Skip to content

Commit b23a503

Browse files
Merge branch 'main' into dependabot/github_actions/actions/setup-java-4
2 parents abd1299 + f17aa7e commit b23a503

File tree

8 files changed

+85
-41
lines changed

8 files changed

+85
-41
lines changed

.env

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
SERVER_PORT=4550
2-
BASE_IMAGE=openjdk:21-jdk-slim
2+
BASE_IMAGE=openjdk:21-jdk-slim
3+
JAR_FILENAME=service-cp-crime-schedulingandlisting-courtschedule-*.jar
4+
JAR_FILE_PATH=build/libs

.github/workflows/ci-build-publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jobs:
105105
- name: Upload JAR Artefact
106106
uses: actions/upload-artifact@v4
107107
with:
108-
name: app-jar
108+
name: app.jar
109109
path: build/libs/${{ steps.repo_vars.outputs.artefact_name }}.jar
110110

111111
Build-Docker:
@@ -119,7 +119,7 @@ jobs:
119119
- name: Download JAR Artefact
120120
uses: actions/download-artifact@v4
121121
with:
122-
name: app-jar
122+
name: app.jar
123123
path: build/libs
124124

125125
- name: Set up Docker Buildx

Dockerfile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,30 @@ ARG BASE_IMAGE
33
FROM ${BASE_IMAGE:-openjdk:21-jdk-slim}
44

55
# ---- Runtime arguments ----
6-
ARG JAR_FILENAME=app.jar
6+
ARG JAR_FILENAME
7+
ARG JAR_FILE_PATH
8+
9+
ENV JAR_FILENAME=${JAR_FILENAME:-app.jar}
10+
ENV JAR_FILE_PATH=${JAR_FILE_PATH:-build/libs}
11+
ENV JAR_FULL_PATH=$JAR_FILE_PATH/$JAR_FILENAME
12+
13+
# ---- Set runtime ENV for Spring Boot to bind port
14+
ARG SERVER_PORT
15+
ENV SERVER_PORT=${SERVER_PORT:-4550}
716

817
# ---- Dependencies ----
918
RUN apt-get update \
1019
&& apt-get install -y curl \
1120
&& rm -rf /var/lib/apt/lists/*
1221

1322
# ---- Application files ----
14-
COPY build/libs/${JAR_FILENAME} /opt/app/${JAR_FILENAME}
23+
COPY $JAR_FULL_PATH /opt/app/app.jar
1524
COPY lib/applicationinsights.json /opt/app/
1625

1726
# ---- Permissions ----
18-
RUN chmod 755 /opt/app/$JAR_FILENAME
27+
RUN chmod 755 /opt/app/app.jar
1928

2029
# ---- Runtime ----
2130
EXPOSE 4550
22-
CMD ["java", "-jar", "/opt/app/$JAR_FILENAME"]
31+
32+
CMD ["java", "-jar", "/opt/app/app.jar"]

build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ ext {
247247
lombokVersion = "1.18.38"
248248
}
249249

250+
tasks.named('processPactVerificationTestResources') {
251+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
252+
}
253+
250254
dependencies {
251255
implementation "uk.gov.hmcts.cp:api-cp-crime-schedulingandlisting-courtschedule:$apiCourtScheduleVersion"
252256
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.9'
@@ -272,6 +276,9 @@ dependencies {
272276
implementation 'org.hibernate.validator:hibernate-validator:9.0.1.Final'
273277
implementation 'org.apache.commons:commons-text:1.13.1'
274278

279+
implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2'
280+
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.2'
281+
275282
compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
276283
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
277284

docker-compose.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
version: '2.1'
1+
version: '3.8'
22

33
services:
4-
service-cp-refdata-courthearing-judges:
4+
service-cp-crime-schedulingandlisting-courtschedule:
5+
env_file:
6+
- .env
57
build:
68
context: .
79
dockerfile: Dockerfile
@@ -10,11 +12,22 @@ services:
1012
https_proxy: ${https_proxy}
1113
no_proxy: ${no_proxy}
1214
BASE_IMAGE: ${BASE_IMAGE}
15+
SERVER_PORT: ${SERVER_PORT}
16+
JAR_FILENAME: ${JAR_FILENAME}
17+
JAR_FILE_PATH: ${JAR_FILE_PATH}
18+
environment:
19+
- SERVER_PORT=${SERVER_PORT:-4550}
1320
ports:
14-
- $SERVER_PORT:$SERVER_PORT
21+
- "${SERVER_PORT:-4550}:${SERVER_PORT:-4550}"
22+
networks:
23+
- service-network
1524
healthcheck:
1625
test: [ "CMD", "curl", "-f", "http://localhost:${SERVER_PORT}/health" ]
1726
interval: 30s
1827
timeout: 10s
1928
retries: 3
2029
start_period: 5s
30+
31+
networks:
32+
service-network:
33+
name: service-cp-crime-schedulingandlisting-courtschedule-network
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package uk.gov.hmcts.cp.pact.helper;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
5+
6+
import java.io.File;
7+
8+
public class JsonFileToObject {
9+
10+
private static final ObjectMapper mapper = new ObjectMapper()
11+
.registerModule(new JavaTimeModule());
12+
13+
public static <T> T readJsonFromResources(String fileName, Class<T> clazz) throws Exception {
14+
File file = new File(JsonFileToObject.class.getClassLoader().getResource(fileName).toURI());
15+
return mapper.readValue(file, clazz);
16+
}
17+
}

src/pactVerificationTest/java/pact.provider/CourtScheduleProviderPactTest.java renamed to src/pactVerificationTest/java/uk/gov/hmcts/cp/pact/provider/CourtScheduleProviderPactTest.java

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,9 @@
1616
import org.springframework.boot.test.web.server.LocalServerPort;
1717
import org.springframework.test.context.junit.jupiter.SpringExtension;
1818
import uk.gov.hmcts.cp.openapi.model.CourtScheduleResponse;
19-
import uk.gov.hmcts.cp.openapi.model.CourtSchedule;
20-
import uk.gov.hmcts.cp.openapi.model.Hearing;
21-
import uk.gov.hmcts.cp.openapi.model.CourtSitting;
19+
import uk.gov.hmcts.cp.pact.helper.JsonFileToObject;
2220
import uk.gov.hmcts.cp.repositories.CourtScheduleRepository;
2321

24-
import java.time.OffsetDateTime;
25-
import java.util.List;
26-
import java.util.UUID;
27-
2822
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
2923
@ExtendWith({SpringExtension.class, PactVerificationInvocationContextProvider.class})
3024
@Provider("CPCourtScheduleProvider")
@@ -50,31 +44,10 @@ void setupTarget(PactVerificationContext context) {
5044
}
5145

5246
@State("court schedule for case 456789 exists")
53-
public void setupCourtSchedule() {
47+
public void setupCourtSchedule() throws Exception{
5448
courtScheduleRepository.clearAll();
55-
var courtSitting = CourtSitting.builder()
56-
.courtHouse("Central Criminal Court")
57-
.sittingStart(OffsetDateTime.now())
58-
.sittingEnd(OffsetDateTime.now().plusMinutes(60))
59-
.judiciaryId(UUID.randomUUID().toString())
60-
.build();
61-
var hearing = Hearing.builder()
62-
.hearingId(UUID.randomUUID().toString())
63-
.listNote("Requires interpreter")
64-
.hearingDescription("Sentencing for theft case")
65-
.hearingType("Trial")
66-
.courtSittings(List.of(courtSitting))
67-
.build();
68-
69-
var schedule = CourtSchedule.builder()
70-
.hearings(List.of(hearing))
71-
.build();
72-
73-
var response = CourtScheduleResponse.builder()
74-
.courtSchedule(List.of(schedule))
75-
.build();
76-
77-
courtScheduleRepository.saveCourtSchedule("456789", response);
49+
CourtScheduleResponse courtScheduleResponse = JsonFileToObject.readJsonFromResources("courtSchedule.json", CourtScheduleResponse.class);
50+
courtScheduleRepository.saveCourtSchedule("456789", courtScheduleResponse);
7851
}
7952

8053
@TestTemplate
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"courtSchedule": [
3+
{
4+
"hearings": [
5+
{
6+
"hearingId": "HRG-123456",
7+
"hearingType": "Preliminary",
8+
"hearingDescription": "Initial appearance for case 456789",
9+
"listNote": "Judge prefers afternoon start",
10+
"courtSittings": [
11+
{
12+
"sittingStart": "2025-03-25T09:00:00Z",
13+
"sittingEnd": "2025-03-25T12:00:00Z",
14+
"judiciaryId": "123e4567-e89b-12d3-a456-426614174000",
15+
"courtHouse": "223e4567-e89b-12d3-a456-426614174111"
16+
}
17+
]
18+
}
19+
]
20+
}
21+
]
22+
}

0 commit comments

Comments
 (0)