1616import org .springframework .boot .test .web .server .LocalServerPort ;
1717import org .springframework .test .context .junit .jupiter .SpringExtension ;
1818import 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 ;
2220import 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
0 commit comments