Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ ext {
lombokVersion = "1.18.38"
}

tasks.named('processPactVerificationTestResources') {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

dependencies {
implementation "uk.gov.hmcts.cp:api-cp-crime-schedulingandlisting-courtschedule:$apiCourtScheduleVersion"
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.9'
Expand All @@ -272,6 +276,9 @@ dependencies {
implementation 'org.hibernate.validator:hibernate-validator:9.0.1.Final'
implementation 'org.apache.commons:commons-text:1.13.1'

implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.2'

compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package uk.gov.hmcts.cp.pact.helper;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import java.io.File;

public class JsonFileToObject {

private static final ObjectMapper mapper = new ObjectMapper()
.registerModule(new JavaTimeModule());

public static <T> T readJsonFromResources(String fileName, Class<T> clazz) throws Exception {
File file = new File(JsonFileToObject.class.getClassLoader().getResource(fileName).toURI());
return mapper.readValue(file, clazz);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import uk.gov.hmcts.cp.openapi.model.CourtScheduleResponse;
import uk.gov.hmcts.cp.openapi.model.CourtSchedule;
import uk.gov.hmcts.cp.openapi.model.Hearing;
import uk.gov.hmcts.cp.openapi.model.CourtSitting;
import uk.gov.hmcts.cp.pact.helper.JsonFileToObject;
import uk.gov.hmcts.cp.repositories.CourtScheduleRepository;

import java.time.OffsetDateTime;
import java.util.List;
import java.util.UUID;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ExtendWith({SpringExtension.class, PactVerificationInvocationContextProvider.class})
@Provider("CPCourtScheduleProvider")
Expand All @@ -50,31 +44,10 @@ void setupTarget(PactVerificationContext context) {
}

@State("court schedule for case 456789 exists")
public void setupCourtSchedule() {
public void setupCourtSchedule() throws Exception{
courtScheduleRepository.clearAll();
var courtSitting = CourtSitting.builder()
.courtHouse("Central Criminal Court")
.sittingStart(OffsetDateTime.now())
.sittingEnd(OffsetDateTime.now().plusMinutes(60))
.judiciaryId(UUID.randomUUID().toString())
.build();
var hearing = Hearing.builder()
.hearingId(UUID.randomUUID().toString())
.listNote("Requires interpreter")
.hearingDescription("Sentencing for theft case")
.hearingType("Trial")
.courtSittings(List.of(courtSitting))
.build();

var schedule = CourtSchedule.builder()
.hearings(List.of(hearing))
.build();

var response = CourtScheduleResponse.builder()
.courtSchedule(List.of(schedule))
.build();

courtScheduleRepository.saveCourtSchedule("456789", response);
CourtScheduleResponse courtScheduleResponse = JsonFileToObject.readJsonFromResources("courtSchedule.json", CourtScheduleResponse.class);
courtScheduleRepository.saveCourtSchedule("456789", courtScheduleResponse);
}

@TestTemplate
Expand Down
22 changes: 22 additions & 0 deletions src/pactVerificationTest/resources/courtSchedule.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"courtSchedule": [
{
"hearings": [
{
"hearingId": "HRG-123456",
"hearingType": "Preliminary",
"hearingDescription": "Initial appearance for case 456789",
"listNote": "Judge prefers afternoon start",
"courtSittings": [
{
"sittingStart": "2025-03-25T09:00:00Z",
"sittingEnd": "2025-03-25T12:00:00Z",
"judiciaryId": "123e4567-e89b-12d3-a456-426614174000",
"courtHouse": "223e4567-e89b-12d3-a456-426614174111"
}
]
}
]
}
]
}
Loading