-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from nhkhai/SIS-24
SIS-24: Added dirties context for integration test cases.
- Loading branch information
Showing
5 changed files
with
26 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,9 @@ | |
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.annotation.DirtiesContext.ClassMode; | ||
|
||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.RequestBuilder; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
|
@@ -31,6 +34,7 @@ | |
|
||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) | ||
public class CustomerControllerTest { | ||
@Autowired | ||
private MockMvc mockMvc; | ||
|
@@ -75,7 +79,7 @@ public void createCustomerTest() throws Exception { | |
.address("123 HK St").postalCode(654321).phoneNumber(87654321) | ||
.email("[email protected]").build(); | ||
|
||
// Step 2: Convert the Java object to JSON using ObjectMapper. | ||
// Step 2: Convert the Java objects to JSON using ObjectMapper. | ||
String newCustomerAsJSON = objectMapper.writeValueAsString(newCustomer); | ||
|
||
// Step 3: Build the request. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ | |
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.annotation.DirtiesContext.ClassMode; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.RequestBuilder; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
|
@@ -40,6 +42,7 @@ | |
|
||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) | ||
public class IntegrationTest { | ||
@Mock | ||
private CustomerRepository customerRepository; | ||
|
@@ -114,9 +117,10 @@ public void runIntegratedTest() throws Exception { | |
Customer testObject1 = Customer.builder().firstName("Jackie").lastName("Chan").country("Hong Kong") | ||
.address("123 HK St").postalCode(654321).phoneNumber(87654321) | ||
.email("[email protected]").build(); | ||
Customer testObject2 = Customer.builder().firstName("Jackie").lastName("Chang").country("Hong Kong") | ||
.address("123 HK St").postalCode(654321).phoneNumber(87654321) | ||
.email("[email protected]").build(); | ||
|
||
Customer testObject2 = Customer.builder().firstName("Jack").lastName("Chang").country("China") | ||
.address("321 HK St").postalCode(123456).phoneNumber(12345678) | ||
.email("[email protected]").build(); | ||
|
||
// Step 2: Convert the Java objects to JSON using ObjectMapper. | ||
String testObject1AsJSON = objectMapper.writeValueAsString(testObject1); | ||
|
@@ -142,7 +146,7 @@ public void runIntegratedTest() throws Exception { | |
.andDo(print()) | ||
.andExpect(status().isCreated()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$.firstName").value("Jackie")) | ||
.andExpect(jsonPath("$.firstName").value("Jack")) | ||
.andExpect(jsonPath("$.lastName").value("Chang")); | ||
|
||
test_logger.info("Ending test: " + getCurrentMethodName() + ". "); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ | |
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.annotation.DirtiesContext.ClassMode; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.RequestBuilder; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
|
@@ -40,6 +42,7 @@ | |
|
||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) | ||
public class UseCaseTest { | ||
@Mock | ||
private CustomerRepository customerRepository; | ||
|
@@ -115,9 +118,9 @@ public void runIntegratedTest() throws Exception { | |
.address("123 HK St").postalCode(654321).phoneNumber(87654321) | ||
.email("[email protected]").build(); | ||
|
||
Customer testObject2 = Customer.builder().firstName("Jackie").lastName("Chang").country("Hong Kong") | ||
.address("123 HK St").postalCode(654321).phoneNumber(87654321) | ||
.email("jackie[email protected]").build(); | ||
Customer testObject2 = Customer.builder().firstName("Jack").lastName("Chang").country("China") | ||
.address("321 HK St").postalCode(123456).phoneNumber(12345678) | ||
.email("jack[email protected]").build(); | ||
|
||
// Step 2: Convert the Java objects to JSON using ObjectMapper. | ||
String testObject1AsJSON = objectMapper.writeValueAsString(testObject1); | ||
|
@@ -144,7 +147,7 @@ public void runIntegratedTest() throws Exception { | |
.andDo(print()) | ||
.andExpect(status().isCreated()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$.firstName").value("Jackie")) | ||
.andExpect(jsonPath("$.firstName").value("Jack")) | ||
.andExpect(jsonPath("$.lastName").value("Chang")); | ||
|
||
test_logger.info("Ending test: " + getCurrentMethodName() + ". "); | ||
|