generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New integration tests for reference data controllers
- Loading branch information
1 parent
59f30db
commit 9e35978
Showing
22 changed files
with
834 additions
and
31 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
101 changes: 101 additions & 0 deletions
101
...est/java/uk/gov/hmcts/opal/controllers/develop/BusinessUnitControllerIntegrationTest.java
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 |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package uk.gov.hmcts.opal.controllers.develop; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import uk.gov.hmcts.opal.dto.search.BusinessUnitSearchDto; | ||
import uk.gov.hmcts.opal.entity.BusinessUnitEntity; | ||
import uk.gov.hmcts.opal.service.opal.BusinessUnitService; | ||
|
||
import static java.util.Collections.singletonList; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@WebMvcTest | ||
@ContextConfiguration(classes = BusinessUnitController.class) | ||
@ActiveProfiles({"integration"}) | ||
class BusinessUnitControllerIntegrationTest { | ||
|
||
@Autowired | ||
MockMvc mockMvc; | ||
|
||
@MockBean | ||
@Qualifier("businessUnitService") | ||
BusinessUnitService businessUnitService; | ||
|
||
@Test | ||
void testGetBusinessUnitById() throws Exception { | ||
BusinessUnitEntity businessUnitEntity = createBusinessUnitEntity(); | ||
|
||
when(businessUnitService.getBusinessUnit((short)1)).thenReturn(businessUnitEntity); | ||
|
||
mockMvc.perform(get("/api/business-unit/1")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$.businessUnitId").value(1)) | ||
.andExpect(jsonPath("$.businessUnitName").value("Business Unit 001")) | ||
.andExpect(jsonPath("$.businessUnitCode").value("AAAA")) | ||
.andExpect(jsonPath("$.businessUnitType").value("LARGE UNIT")) | ||
.andExpect(jsonPath("$.accountNumberPrefix").value("XX")) | ||
.andExpect(jsonPath("$.parentBusinessUnitId").value(99)); | ||
} | ||
|
||
|
||
@Test | ||
void testGetBusinessUnitById_WhenBusinessUnitDoesNotExist() throws Exception { | ||
when(businessUnitService.getBusinessUnit((short)2)).thenReturn(null); | ||
|
||
mockMvc.perform(get("/api/business-unit/2")) | ||
.andExpect(status().isNoContent()); | ||
} | ||
|
||
@Test | ||
void testPostBusinessUnitsSearch() throws Exception { | ||
BusinessUnitEntity businessUnitEntity = createBusinessUnitEntity(); | ||
|
||
when(businessUnitService.searchBusinessUnits(any(BusinessUnitSearchDto.class))) | ||
.thenReturn(singletonList(businessUnitEntity)); | ||
|
||
mockMvc.perform(post("/api/business-unit/search") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content("{\"criteria\":\"value\"}")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$[0].businessUnitId").value(1)) | ||
.andExpect(jsonPath("$[0].businessUnitName").value("Business Unit 001")) | ||
.andExpect(jsonPath("$[0].businessUnitCode").value("AAAA")) | ||
.andExpect(jsonPath("$[0].businessUnitType").value("LARGE UNIT")) | ||
.andExpect(jsonPath("$[0].accountNumberPrefix").value("XX")) | ||
.andExpect(jsonPath("$[0].parentBusinessUnitId").value(99)); | ||
} | ||
|
||
@Test | ||
void testPostBusinessUnitsSearch_WhenBusinessUnitDoesNotExist() throws Exception { | ||
mockMvc.perform(post("/api/business-unit/search") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content("{\"criteria\":\"2\"}")) | ||
.andExpect(status().isNoContent()); | ||
} | ||
|
||
private BusinessUnitEntity createBusinessUnitEntity() { | ||
return BusinessUnitEntity.builder() | ||
.businessUnitId((short)1) | ||
.businessUnitName("Business Unit 001") | ||
.businessUnitCode("AAAA") | ||
.businessUnitType("LARGE UNIT") | ||
.accountNumberPrefix("XX") | ||
.parentBusinessUnitId((short)99) | ||
.build(); | ||
} | ||
} |
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
124 changes: 124 additions & 0 deletions
124
...ionTest/java/uk/gov/hmcts/opal/controllers/develop/EnforcerControllerIntegrationTest.java
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 |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package uk.gov.hmcts.opal.controllers.develop; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import uk.gov.hmcts.opal.dto.search.EnforcerSearchDto; | ||
import uk.gov.hmcts.opal.entity.EnforcerEntity; | ||
import uk.gov.hmcts.opal.service.opal.EnforcerService; | ||
|
||
import static java.util.Collections.singletonList; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@WebMvcTest | ||
@ContextConfiguration(classes = EnforcerController.class) | ||
@ActiveProfiles({"integration"}) | ||
class EnforcerControllerIntegrationTest { | ||
|
||
@Autowired | ||
MockMvc mockMvc; | ||
|
||
@MockBean | ||
@Qualifier("enforcerService") | ||
EnforcerService enforcerService; | ||
|
||
@Test | ||
void testGetEnforcerById() throws Exception { | ||
EnforcerEntity enforcerEntity = createEnforcerEntity(); | ||
|
||
when(enforcerService.getEnforcer(1L)).thenReturn(enforcerEntity); | ||
|
||
mockMvc.perform(get("/api/enforcer/1")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$.enforcerId").value(1)) | ||
.andExpect(jsonPath("$.enforcerCode").value(7)) | ||
.andExpect(jsonPath("$.warrantReferenceSequence").value("WARR-REF-SEQ-666")) | ||
.andExpect(jsonPath("$.warrantRegisterSequence").value(666)) | ||
.andExpect(jsonPath("$.businessUnitId").value(3)) | ||
.andExpect(jsonPath("$.name").value("Herbert the Enforcer")) | ||
.andExpect(jsonPath("$.addressLine1").value("Enforcer Road")) | ||
.andExpect(jsonPath("$.addressLine2").value("Enforcer Town")) | ||
.andExpect(jsonPath("$.addressLine3").value("Enforcer County")) | ||
.andExpect(jsonPath("$.postcode").value("EN99 9EN")) | ||
.andExpect(jsonPath("$.nameCy").value("Herbert the Enforcer CY")) | ||
.andExpect(jsonPath("$.addressLine1Cy").value("Enforcer Road CY")) | ||
.andExpect(jsonPath("$.addressLine2Cy").value("Enforcer Town CY")) | ||
.andExpect(jsonPath("$.addressLine3Cy").value("Enforcer County CY")); | ||
} | ||
|
||
|
||
@Test | ||
void testGetEnforcerById_WhenEnforcerDoesNotExist() throws Exception { | ||
when(enforcerService.getEnforcer(2L)).thenReturn(null); | ||
|
||
mockMvc.perform(get("/api/enforcer/2")) | ||
.andExpect(status().isNoContent()); | ||
} | ||
|
||
@Test | ||
void testPostEnforcersSearch() throws Exception { | ||
EnforcerEntity enforcerEntity = createEnforcerEntity(); | ||
|
||
when(enforcerService.searchEnforcers(any(EnforcerSearchDto.class))).thenReturn(singletonList(enforcerEntity)); | ||
|
||
mockMvc.perform(post("/api/enforcer/search") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content("{\"criteria\":\"value\"}")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$[0].enforcerId").value(1)) | ||
.andExpect(jsonPath("$[0].enforcerCode").value(7)) | ||
.andExpect(jsonPath("$[0].warrantReferenceSequence").value("WARR-REF-SEQ-666")) | ||
.andExpect(jsonPath("$[0].warrantRegisterSequence").value(666)) | ||
.andExpect(jsonPath("$[0].businessUnitId").value(3)) | ||
.andExpect(jsonPath("$[0].name").value("Herbert the Enforcer")) | ||
.andExpect(jsonPath("$[0].addressLine1").value("Enforcer Road")) | ||
.andExpect(jsonPath("$[0].addressLine2").value("Enforcer Town")) | ||
.andExpect(jsonPath("$[0].addressLine3").value("Enforcer County")) | ||
.andExpect(jsonPath("$[0].postcode").value("EN99 9EN")) | ||
.andExpect(jsonPath("$[0].nameCy").value("Herbert the Enforcer CY")) | ||
.andExpect(jsonPath("$[0].addressLine1Cy").value("Enforcer Road CY")) | ||
.andExpect(jsonPath("$[0].addressLine2Cy").value("Enforcer Town CY")) | ||
.andExpect(jsonPath("$[0].addressLine3Cy").value("Enforcer County CY")); | ||
} | ||
|
||
@Test | ||
void testPostEnforcersSearch_WhenEnforcerDoesNotExist() throws Exception { | ||
mockMvc.perform(post("/api/enforcer/search") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content("{\"criteria\":\"2\"}")) | ||
.andExpect(status().isNoContent()); | ||
} | ||
|
||
private EnforcerEntity createEnforcerEntity() { | ||
return EnforcerEntity.builder() | ||
.enforcerId(1L) | ||
.enforcerCode((short)7) | ||
.warrantReferenceSequence("WARR-REF-SEQ-666") | ||
.warrantRegisterSequence(666) | ||
.businessUnitId((short)3) | ||
.name("Herbert the Enforcer") | ||
.addressLine1("Enforcer Road") | ||
.addressLine2("Enforcer Town") | ||
.addressLine3("Enforcer County") | ||
.postcode("EN99 9EN") | ||
.nameCy("Herbert the Enforcer CY") | ||
.addressLine1Cy("Enforcer Road CY") | ||
.addressLine2Cy("Enforcer Town CY") | ||
.addressLine3Cy("Enforcer County CY") | ||
.build(); | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
...nTest/java/uk/gov/hmcts/opal/controllers/develop/ImpositionControllerIntegrationTest.java
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 |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package uk.gov.hmcts.opal.controllers.develop; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import uk.gov.hmcts.opal.dto.search.ImpositionSearchDto; | ||
import uk.gov.hmcts.opal.entity.CourtEntity; | ||
import uk.gov.hmcts.opal.entity.CreditorAccountEntity; | ||
import uk.gov.hmcts.opal.entity.DefendantAccountEntity; | ||
import uk.gov.hmcts.opal.entity.ImpositionEntity; | ||
import uk.gov.hmcts.opal.entity.UserEntity; | ||
import uk.gov.hmcts.opal.service.opal.ImpositionService; | ||
|
||
import java.math.BigDecimal; | ||
import java.time.LocalDateTime; | ||
|
||
import static java.util.Collections.singletonList; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@WebMvcTest | ||
@ContextConfiguration(classes = ImpositionController.class) | ||
@ActiveProfiles({"integration"}) | ||
class ImpositionControllerIntegrationTest { | ||
|
||
@Autowired | ||
MockMvc mockMvc; | ||
|
||
@MockBean | ||
@Qualifier("impositionService") | ||
ImpositionService impositionService; | ||
|
||
@Test | ||
void testGetImpositionById() throws Exception { | ||
ImpositionEntity impositionEntity = createImpositionEntity(); | ||
|
||
when(impositionService.getImposition(1L)).thenReturn(impositionEntity); | ||
|
||
mockMvc.perform(get("/api/imposition/1")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$.impositionId").value(1)) | ||
.andExpect(jsonPath("$.postedBy").value("ADMIN")) | ||
.andExpect(jsonPath("$.resultId").value("AAABBB")) | ||
.andExpect(jsonPath("$.offenceId").value(8)) | ||
.andExpect(jsonPath("$.unitFineAdjusted").value(false)) | ||
.andExpect(jsonPath("$.unitFineUnits").value(0)) | ||
.andExpect(jsonPath("$.completed").value(false)); | ||
} | ||
|
||
|
||
@Test | ||
void testGetImpositionById_WhenImpositionDoesNotExist() throws Exception { | ||
when(impositionService.getImposition(2L)).thenReturn(null); | ||
|
||
mockMvc.perform(get("/api/imposition/2")) | ||
.andExpect(status().isNoContent()); | ||
} | ||
|
||
@Test | ||
void testPostImpositionsSearch() throws Exception { | ||
ImpositionEntity impositionEntity = createImpositionEntity(); | ||
|
||
when(impositionService.searchImpositions(any(ImpositionSearchDto.class))) | ||
.thenReturn(singletonList(impositionEntity)); | ||
|
||
mockMvc.perform(post("/api/imposition/search") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content("{\"criteria\":\"value\"}")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(jsonPath("$[0].impositionId").value(1)) | ||
.andExpect(jsonPath("$[0].postedBy").value("ADMIN")) | ||
.andExpect(jsonPath("$[0].resultId").value("AAABBB")) | ||
.andExpect(jsonPath("$[0].offenceId").value(8)) | ||
.andExpect(jsonPath("$[0].unitFineAdjusted").value(false)) | ||
.andExpect(jsonPath("$[0].unitFineUnits").value(0)) | ||
.andExpect(jsonPath("$[0].completed").value(false)); | ||
} | ||
|
||
@Test | ||
void testPostImpositionsSearch_WhenImpositionDoesNotExist() throws Exception { | ||
mockMvc.perform(post("/api/imposition/search") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content("{\"criteria\":\"2\"}")) | ||
.andExpect(status().isNoContent()); | ||
} | ||
|
||
private ImpositionEntity createImpositionEntity() { | ||
return ImpositionEntity.builder() | ||
.impositionId(1L) | ||
.defendantAccount(DefendantAccountEntity.builder().build()) | ||
.postedDate(LocalDateTime.now()) | ||
.postedBy("ADMIN") | ||
.postedByUser(UserEntity.builder().build()) | ||
.originalPostedDate(LocalDateTime.now()) | ||
.resultId("AAABBB") | ||
.imposingCourt(CourtEntity.builder().build()) | ||
.imposedDate(LocalDateTime.now()) | ||
.imposedAmount(BigDecimal.TEN) | ||
.paidAmount(BigDecimal.ONE) | ||
.offenceId((short)8) | ||
.creditorAccount(CreditorAccountEntity.builder().build()) | ||
.unitFineAdjusted(false) | ||
.unitFineUnits((short)0) | ||
.completed(false) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.