1111import org .junit .jupiter .api .Tag ;
1212import org .junit .jupiter .api .TestTemplate ;
1313import org .junit .jupiter .api .extension .ExtendWith ;
14+ import org .mockito .Mockito ;
1415import org .slf4j .Logger ;
1516import org .slf4j .LoggerFactory ;
1617import org .springframework .beans .factory .annotation .Autowired ;
1718import org .springframework .boot .test .context .SpringBootTest ;
19+ import org .springframework .boot .test .context .TestConfiguration ;
1820import org .springframework .boot .test .web .server .LocalServerPort ;
21+ import org .springframework .context .annotation .Bean ;
22+ import org .springframework .test .context .ActiveProfiles ;
1923import org .springframework .test .context .junit .jupiter .SpringExtension ;
2024import uk .gov .hmcts .cp .openapi .model .CourtScheduleResponse ;
2125import uk .gov .hmcts .cp .pact .helper .JsonFileToObject ;
2226import uk .gov .hmcts .cp .repositories .InMemoryCourtScheduleClientImpl ;
27+ import uk .gov .hmcts .cp .services .CaseUrnMapperService ;
28+
29+ import java .util .UUID ;
30+
31+ import static java .util .UUID .randomUUID ;
32+ import static org .mockito .Mockito .when ;
2333
2434@ SpringBootTest (webEnvironment = SpringBootTest .WebEnvironment .RANDOM_PORT )
2535@ ExtendWith ({SpringExtension .class , PactVerificationInvocationContextProvider .class })
2838 url = "${pact.broker.url}" ,
2939 authentication = @ PactBrokerAuth (token = "${pact.broker.token}" )
3040)
41+ @ ActiveProfiles ("pact-test" )
3142@ Tag ("pact" )
3243public class CourtScheduleProviderPactTest {
3344
@@ -39,6 +50,17 @@ public class CourtScheduleProviderPactTest {
3950 @ LocalServerPort
4051 private int port ;
4152
53+ @ Autowired
54+ private CaseUrnMapperService caseUrnMapperService ;
55+
56+ @ TestConfiguration
57+ static class PactTestConfig {
58+ @ Bean
59+ public CaseUrnMapperService caseUrnMapperService () {
60+ return Mockito .mock (CaseUrnMapperService .class );
61+ }
62+ }
63+
4264 @ BeforeEach
4365 void setupTarget (PactVerificationContext context ) {
4466 LOG .atDebug ().log ("Running test on port: " + port );
@@ -50,7 +72,12 @@ void setupTarget(PactVerificationContext context) {
5072 public void setupCourtSchedule () throws Exception {
5173 inMemoryCourtScheduleClient .clearAll ();
5274 CourtScheduleResponse courtScheduleResponse = JsonFileToObject .readJsonFromResources ("courtSchedule.json" , CourtScheduleResponse .class );
53- inMemoryCourtScheduleClient .saveCourtSchedule ("456789" , courtScheduleResponse );
75+
76+ final UUID caseId = randomUUID ();
77+ when (caseUrnMapperService .getCaseId ("456789" ))
78+ .thenReturn (caseId .toString ());
79+
80+ inMemoryCourtScheduleClient .saveCourtSchedule (caseId .toString (), courtScheduleResponse );
5481 }
5582
5683 @ TestTemplate
0 commit comments