generated from hmcts/spring-boot-template
-
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.
DMP-460 Add getCases endpoint (#175)
- Loading branch information
1 parent
83affeb
commit 60098bf
Showing
42 changed files
with
2,079 additions
and
149 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
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
48 changes: 48 additions & 0 deletions
48
src/integrationTest/java/uk/gov/hmcts/darts/cases/controller/CaseControllerTest.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,48 @@ | ||
package uk.gov.hmcts.darts.cases.controller; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.skyscreamer.jsonassert.JSONAssert; | ||
import org.skyscreamer.jsonassert.JSONCompareMode; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.MvcResult; | ||
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; | ||
import uk.gov.hmcts.darts.cases.service.CaseService; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
import static uk.gov.hmcts.darts.cases.CasesConstants.GetCasesParams.COURTHOUSE; | ||
import static uk.gov.hmcts.darts.cases.CasesConstants.GetCasesParams.COURTROOM; | ||
import static uk.gov.hmcts.darts.cases.CasesConstants.GetCasesParams.DATE; | ||
import static uk.gov.hmcts.darts.common.util.TestUtils.getContentsFromFile; | ||
|
||
@SpringBootTest | ||
@ActiveProfiles({"intTest", "h2db"}) | ||
@AutoConfigureMockMvc | ||
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") | ||
class CaseControllerTest { | ||
@Autowired | ||
private transient MockMvc mockMvc; | ||
|
||
@Autowired | ||
private CaseService caseService; | ||
|
||
@Test | ||
void casesGetEndpoint() throws Exception { | ||
MockHttpServletRequestBuilder requestBuilder = get("/cases") | ||
.queryParam(COURTHOUSE, "SWANSEA") | ||
.queryParam(COURTROOM, "1") | ||
.queryParam(DATE, "2023-06-20"); | ||
MvcResult response = mockMvc.perform(requestBuilder).andExpect(status().isOk()).andReturn(); | ||
|
||
String actualResponse = response.getResponse().getContentAsString(); | ||
|
||
String expectedResponse = getContentsFromFile( | ||
"tests/cases/CaseControllerTest/casesGetEndpoint/expectedResponse.json"); | ||
JSONAssert.assertEquals(expectedResponse, actualResponse, JSONCompareMode.NON_EXTENSIBLE); | ||
|
||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
src/integrationTest/java/uk/gov/hmcts/darts/cases/service/CaseServiceTest.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,90 @@ | ||
package uk.gov.hmcts.darts.cases.service; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.skyscreamer.jsonassert.JSONAssert; | ||
import org.skyscreamer.jsonassert.JSONCompareMode; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import uk.gov.hmcts.darts.cases.model.GetCasesRequest; | ||
import uk.gov.hmcts.darts.cases.model.ScheduledCase; | ||
import uk.gov.hmcts.darts.common.entity.Courtroom; | ||
import uk.gov.hmcts.darts.common.repository.CourtroomRepository; | ||
|
||
import java.io.IOException; | ||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static uk.gov.hmcts.darts.common.util.TestUtils.getContentsFromFile; | ||
|
||
@SpringBootTest | ||
@ActiveProfiles({"intTest", "h2db"}) | ||
@ExtendWith(MockitoExtension.class) | ||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
@Transactional | ||
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") | ||
class CaseServiceTest { | ||
|
||
@Autowired | ||
CaseService service; | ||
|
||
@Autowired | ||
CourtroomRepository courtroomRepository; | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@Test | ||
void testGetCasesOk1() throws IOException { | ||
GetCasesRequest request = new GetCasesRequest(); | ||
request.setCourthouse("Swansea"); | ||
request.setCourtroom("1"); | ||
request.setDate(LocalDate.of(2023, 6, 20)); | ||
|
||
List<ScheduledCase> resultList = service.getCases(request); | ||
String actualResponse = objectMapper.writeValueAsString(resultList); | ||
String expectedResponse = getContentsFromFile("tests/cases/CaseServiceTest/getCasesOk1/expectedResponse.json"); | ||
JSONAssert.assertEquals(expectedResponse, actualResponse, JSONCompareMode.NON_EXTENSIBLE); | ||
} | ||
|
||
@Test | ||
void testGetCasesOk2() throws IOException { | ||
GetCasesRequest request = new GetCasesRequest(); | ||
request.setCourthouse("Swansea"); | ||
request.setCourtroom("2"); | ||
request.setDate(LocalDate.of(2023, 6, 20)); | ||
|
||
List<ScheduledCase> resultList = service.getCases(request); | ||
String actualResponse = objectMapper.writeValueAsString(resultList); | ||
String expectedResponse = getContentsFromFile("tests/cases/CaseServiceTest/getCasesOk2/expectedResponse.json"); | ||
JSONAssert.assertEquals(expectedResponse, actualResponse, JSONCompareMode.NON_EXTENSIBLE); | ||
} | ||
|
||
@Test | ||
void testGetCasesCreateCourtroom() throws IOException { | ||
String courthouseName = "Swansea"; | ||
String courtroomName = "99"; | ||
|
||
Courtroom foundCourtroom = courtroomRepository.findByNames(courthouseName, courtroomName); | ||
assertNull(foundCourtroom); | ||
|
||
GetCasesRequest request = new GetCasesRequest(); | ||
request.setCourthouse(courthouseName); | ||
request.setCourtroom(courtroomName); | ||
request.setDate(LocalDate.of(2023, 6, 20)); | ||
|
||
List<ScheduledCase> resultList = service.getCases(request); | ||
assertEquals(0, resultList.size()); | ||
foundCourtroom = courtroomRepository.findByNames(courthouseName, courtroomName); | ||
assertEquals(courtroomName.toUpperCase(Locale.ROOT), foundCourtroom.getName()); | ||
assertEquals(courthouseName.toUpperCase(Locale.ROOT), foundCourtroom.getCourthouse().getCourthouseName()); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/integrationTest/java/uk/gov/hmcts/darts/common/util/CommonTestDataUtil.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,71 @@ | ||
package uk.gov.hmcts.darts.common.util; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import uk.gov.hmcts.darts.common.entity.Case; | ||
import uk.gov.hmcts.darts.common.entity.Courthouse; | ||
import uk.gov.hmcts.darts.common.entity.Courtroom; | ||
import uk.gov.hmcts.darts.common.entity.Hearing; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@UtilityClass | ||
public class CommonTestDataUtil { | ||
|
||
public Courthouse createCourthouse(String name) { | ||
Courthouse courthouse = new Courthouse(); | ||
courthouse.setCourthouseName(name); | ||
return courthouse; | ||
} | ||
|
||
public Courtroom createCourtroom(Courthouse courthouse, String name) { | ||
Courtroom courtroom = new Courtroom(); | ||
courtroom.setCourthouse(courthouse); | ||
courtroom.setName(name); | ||
return courtroom; | ||
} | ||
|
||
public Courtroom createCourtroom(String name) { | ||
createCourthouse("SWANSEA"); | ||
return createCourtroom(createCourthouse("SWANSEA"), name); | ||
} | ||
|
||
public Case createCase(String caseNumber) { | ||
Case courtcase = new Case(); | ||
courtcase.setCaseNumber(caseNumber); | ||
courtcase.setDefenders(List.of("defender_" + caseNumber + "_1", "defender_" + caseNumber + "_2")); | ||
courtcase.setDefendants(List.of("defendant_" + caseNumber + "_1", "defendant_" + caseNumber + "_2")); | ||
courtcase.setProsecutors(List.of("Prosecutor_" + caseNumber + "_1", "Prosecutor_" + caseNumber + "_2")); | ||
return courtcase; | ||
} | ||
|
||
public Hearing createHearing(Case courtcase, Courtroom courtroom, LocalDate date) { | ||
Hearing hearing1 = new Hearing(); | ||
hearing1.setCourtCase(courtcase); | ||
hearing1.setCourtroom(courtroom); | ||
hearing1.setHearingDate(date); | ||
return hearing1; | ||
} | ||
|
||
public Hearing createHearing(String caseNumber, LocalTime time) { | ||
Hearing hearing1 = new Hearing(); | ||
hearing1.setCourtCase(createCase(caseNumber)); | ||
hearing1.setCourtroom(createCourtroom("1")); | ||
hearing1.setHearingDate(LocalDate.of(2023, 6, 20)); | ||
hearing1.setScheduledStartTime(time); | ||
return hearing1; | ||
} | ||
|
||
public List<Hearing> createHearings(int numOfHearings) { | ||
List<Hearing> returnList = new ArrayList<>(); | ||
LocalTime time = LocalTime.of(9, 0, 0); | ||
for (int counter = 1; counter <= numOfHearings; counter++) { | ||
returnList.add(createHearing("caseNum_" + counter, time)); | ||
time = time.plusHours(1); | ||
} | ||
return returnList; | ||
} | ||
|
||
} |
Oops, something went wrong.