Skip to content

Commit c68843a

Browse files
committed
updated code for pact testing
1 parent d83ebf4 commit c68843a

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

src/integrationTest/java/uk/gov/hmcts/cp/controllers/CourtScheduleControllerIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.springframework.boot.test.context.SpringBootTest;
1313
import org.springframework.context.annotation.Import;
1414
import org.springframework.http.MediaType;
15+
import org.springframework.test.context.ActiveProfiles;
1516
import org.springframework.test.context.junit.jupiter.SpringExtension;
1617
import org.springframework.test.web.servlet.MockMvc;
1718
import uk.gov.hmcts.cp.config.TestConfig;
@@ -29,6 +30,7 @@
2930
@ExtendWith(SpringExtension.class)
3031
@SpringBootTest
3132
@AutoConfigureMockMvc
33+
@ActiveProfiles("pact-test")
3234
@Import(TestConfig.class)
3335
class CourtScheduleControllerIT {
3436
private static final Logger log = LoggerFactory.getLogger(CourtScheduleControllerIT.class);

src/main/java/uk/gov/hmcts/cp/repositories/CourtScheduleClientImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.slf4j.LoggerFactory;
77
import org.springframework.beans.factory.annotation.Value;
88
import org.springframework.context.annotation.Primary;
9+
import org.springframework.context.annotation.Profile;
910
import org.springframework.http.HttpStatus;
1011
import org.springframework.stereotype.Component;
1112
import org.springframework.web.util.UriComponentsBuilder;
@@ -31,6 +32,7 @@
3132
@Component
3233
@Primary
3334
@RequiredArgsConstructor
35+
@Profile("!pact-test")
3436
public class CourtScheduleClientImpl implements CourtScheduleClient {
3537
private static final Logger LOG = LoggerFactory.getLogger(CourtScheduleClientImpl.class);
3638
private final HttpClient httpClient;

src/main/java/uk/gov/hmcts/cp/repositories/InMemoryCourtScheduleClientImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package uk.gov.hmcts.cp.repositories;
22

3+
import org.springframework.context.annotation.Profile;
34
import org.springframework.stereotype.Component;
45
import uk.gov.hmcts.cp.openapi.model.CourtSchedule;
56
import uk.gov.hmcts.cp.openapi.model.CourtScheduleResponse;
@@ -15,6 +16,7 @@
1516
import java.util.concurrent.ConcurrentHashMap;
1617

1718
@Component("inMemoryCourtScheduleClientImpl")
19+
@Profile("pact-test")
1820
public class InMemoryCourtScheduleClientImpl implements CourtScheduleClient {
1921
private final Map<String, CourtScheduleResponse> courtScheduleResponseMap = new ConcurrentHashMap<>();
2022

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,25 @@
1111
import org.junit.jupiter.api.Tag;
1212
import org.junit.jupiter.api.TestTemplate;
1313
import org.junit.jupiter.api.extension.ExtendWith;
14+
import org.mockito.Mockito;
1415
import org.slf4j.Logger;
1516
import org.slf4j.LoggerFactory;
1617
import org.springframework.beans.factory.annotation.Autowired;
1718
import org.springframework.boot.test.context.SpringBootTest;
19+
import org.springframework.boot.test.context.TestConfiguration;
1820
import org.springframework.boot.test.web.server.LocalServerPort;
21+
import org.springframework.context.annotation.Bean;
22+
import org.springframework.test.context.ActiveProfiles;
1923
import org.springframework.test.context.junit.jupiter.SpringExtension;
2024
import uk.gov.hmcts.cp.openapi.model.CourtScheduleResponse;
2125
import uk.gov.hmcts.cp.pact.helper.JsonFileToObject;
2226
import 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})
@@ -28,6 +38,7 @@
2838
url = "${pact.broker.url}",
2939
authentication = @PactBrokerAuth(token = "${pact.broker.token}")
3040
)
41+
@ActiveProfiles("pact-test")
3142
@Tag("pact")
3243
public 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

Comments
 (0)