Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contract test fixes #258

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableFeignClients(basePackages = {"uk.gov.hmcts.reform.hmc.api.clients"})
@EnableFeignClients(basePackages = {"uk.gov.hmcts.reform.hmc.api.services"})
public class HearingCftApiConsumerApplication {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import uk.gov.hmcts.reform.hmc.api.clients.HearingCftApi;
import uk.gov.hmcts.reform.hmc.api.idam.IdamApiConsumerApplication;
import uk.gov.hmcts.reform.hmc.api.services.HearingApiClient;

@ExtendWith(PactConsumerTestExt.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
Expand All @@ -22,7 +22,8 @@
@SuppressWarnings("unchecked")
public class HearingCftConsumerTestBase {

@Autowired HearingCftApi hearingCftApi;
@Autowired
HearingApiClient hearingApiClient;

static final String AUTHORIZATION_HEADER = "Authorization";
static final String AUTHORIZATION_TOKEN = "Bearer some-access-token";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

@PactTestFor(providerName = "hearingData_cftInternal", port = "8894")
@TestPropertySource(
properties = {"hearing_component.api.url=localhost:8894", "idam.api.url=localhost:5000"})
properties = {"hearing_component.api.feign-url=localhost:8894", "idam.api.url=localhost:5000"})
public class HearingCftInternalConsumerTest extends HearingCftConsumerTestBase {

@Pact(provider = "hearingData_cftInternal", consumer = "fpl_hearingDataCftConfiguration")
public RequestResponsePact generatePactFragmentForGetHearingsByCaseRefNo(
PactDslWithProvider builder) {
PactDslWithProvider builder) throws Exception {
// @formatter:off
return builder.given("Hearings exists for given caseRefNo")
.uponReceiving("A Request to get hearings by caseRefNo")
Expand All @@ -30,7 +30,7 @@ public RequestResponsePact generatePactFragmentForGetHearingsByCaseRefNo(
SERVICE_AUTH_TOKEN,
AUTHORIZATION_HEADER,
AUTHORIZATION_TOKEN)
.path("/hearings")
.path("/hearings/caseReference")
.willRespondWith()
.body(buildHearingsResponseDsl())
.status(HttpStatus.SC_OK)
Expand All @@ -41,7 +41,7 @@ public RequestResponsePact generatePactFragmentForGetHearingsByCaseRefNo(
@PactTestFor(pactMethod = "generatePactFragmentForGetHearingsByCaseRefNo")
public void verifyGetHearingsByCaseRefNo() {
Hearings hearings =
hearingCftApi.getHearings(AUTHORIZATION_TOKEN, SERVICE_AUTH_TOKEN, "caseRefNo");
hearingApiClient.getHearingDetails(AUTHORIZATION_TOKEN, SERVICE_AUTH_TOKEN, "caseReference");

assertThat(hearings, is(notNullValue()));
assertThat(hearings.getCaseHearings().get(0).getHmcStatus(), is("someHMCStatus"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableFeignClients(basePackages = {"uk.gov.hmcts.reform.hmc.api.clients"})
@EnableFeignClients(basePackages = {"uk.gov.hmcts.reform.hmc.api.services"})
public class RefDataJudgeApiConsumerApplication {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import uk.gov.hmcts.reform.hmc.api.clients.RefDataJudgeApi;
import uk.gov.hmcts.reform.hmc.api.idam.IdamApiConsumerApplication;
import uk.gov.hmcts.reform.hmc.api.services.RefDataJudicialApi;

@ExtendWith(PactConsumerTestExt.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
Expand All @@ -22,7 +22,7 @@
@SuppressWarnings("unchecked")
public class RefDataJudgeConsumerTestBase {

@Autowired RefDataJudgeApi refDataJudgeApi;
@Autowired RefDataJudicialApi refDataJudgeApi;

static final String AUTHORIZATION_HEADER = "Authorization";
static final String AUTHORIZATION_TOKEN = "Bearer some-access-token";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpStatus;
import org.json.simple.JSONObject;
import org.junit.jupiter.api.Test;
import org.springframework.test.context.TestPropertySource;
import uk.gov.hmcts.reform.hmc.api.model.request.JudgeRequestDTO;
import uk.gov.hmcts.reform.hmc.api.model.response.JudgeDetail;
import uk.gov.hmcts.reform.hmc.api.utils.ResourceLoader;

@PactTestFor(providerName = "referenceData_judgeInternal", port = "8894")
@TestPropertySource(
properties = {"ref_data_judicial.api.url=localhost:8894", "idam.api.url=localhost:5000"})
public class RefDataJudgeInternalConsumerTest extends RefDataJudgeConsumerTestBase {

private final String validResponseBody = "JudgeDetailsRespBody.json";

@Pact(provider = "referenceData_judgeInternal", consumer = "fpl_judgeConfiguration")
public RequestResponsePact generatePactFragmentForGetJudgeDetailsId(PactDslWithProvider builder)
throws JsonProcessingException {
throws Exception {
// @formatter:off
return builder.given("Judge exists for given personal_code or Id ")
.uponReceiving("A Request to get judge details by id")
Expand All @@ -40,7 +43,7 @@ public RequestResponsePact generatePactFragmentForGetJudgeDetailsId(PactDslWithP
new ObjectMapper().writeValueAsString(buildJudgeRequestContent()),
"application/json")
.willRespondWith()
.body(buildJudicialResponseDsl())
.body(ResourceLoader.loadJson(validResponseBody), "application/json")
.status(HttpStatus.SC_OK)
.toPact();
}
Expand All @@ -54,7 +57,7 @@ private JudgeRequestDTO buildJudgeRequestContent() {
@Test
@PactTestFor(pactMethod = "generatePactFragmentForGetJudgeDetailsId")
public void verifyGetJudgeDetailsById() throws JsonProcessingException {
JSONObject judgeDetailList =
List<JudgeDetail> judgeDetailList =
refDataJudgeApi.getJudgeDetails(
AUTHORIZATION_TOKEN, SERVICE_AUTH_TOKEN, buildJudgeRequestContent());
assertThat(judgeDetailList, is(notNullValue()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableFeignClients(basePackages = {"uk.gov.hmcts.reform.hmc.api.clients"})
@EnableFeignClients(basePackages = {"uk.gov.hmcts.reform.hmc.api.services"})
public class RefDataVenueApiConsumerApplication {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import uk.gov.hmcts.reform.hmc.api.clients.RefDataVenueApi;
import uk.gov.hmcts.reform.hmc.api.idam.IdamApiConsumerApplication;
import uk.gov.hmcts.reform.hmc.api.services.RefDataApi;

@ExtendWith(PactConsumerTestExt.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
Expand All @@ -22,7 +22,8 @@
@SuppressWarnings("unchecked")
public class RefDataVenueConsumerTestBase {

@Autowired RefDataVenueApi refDataVenueApi;
@Autowired
RefDataApi refDataApi;

static final String AUTHORIZATION_HEADER = "Authorization";
static final String AUTHORIZATION_TOKEN = "Bearer some-access-token";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@
import au.com.dius.pact.core.model.RequestResponsePact;
import au.com.dius.pact.core.model.annotations.Pact;
import org.apache.http.HttpStatus;
import org.json.simple.JSONObject;
import org.junit.jupiter.api.Test;
import org.springframework.test.context.TestPropertySource;
import uk.gov.hmcts.reform.hmc.api.model.response.CourtDetail;
import uk.gov.hmcts.reform.hmc.api.utils.ResourceLoader;

import java.util.List;

@PactTestFor(providerName = "referenceData_venueInternal", port = "8894")
@TestPropertySource(
properties = {"ref_data_venue.api.url=localhost:8894", "idam.api.url=localhost:5000"})
public class RefDataVenueInternalConsumerTest extends RefDataVenueConsumerTestBase {

private final String validResponseBody = "CourtDetailsRespBody.json";

@Pact(provider = "referenceData_venueInternal", consumer = "fpl_venueConfiguration")
public RequestResponsePact generatePactFragmentForGetCourtDetailsByEpimmsId(
PactDslWithProvider builder) {
PactDslWithProvider builder) throws Exception {
// @formatter:off
return builder.given("Courts exists for given epimmsId")
.uponReceiving("A Request to get court details by epimmsId")
Expand All @@ -33,16 +38,16 @@ public RequestResponsePact generatePactFragmentForGetCourtDetailsByEpimmsId(
.path("/refdata/location/court-venues")
.query("epimms_id=epimms_id")
.willRespondWith()
.body(buildCourtsResponseDsl())
.body(ResourceLoader.loadJson(validResponseBody), "application/json")
.status(HttpStatus.SC_OK)
.toPact();
}

@Test
@PactTestFor(pactMethod = "generatePactFragmentForGetCourtDetailsByEpimmsId")
public void verifyGetCourtByEpimmsId() {
JSONObject courtDetailList =
refDataVenueApi.getCourtDetails(
List<CourtDetail> courtDetailList =
refDataApi.getCourtDetails(
AUTHORIZATION_TOKEN, SERVICE_AUTH_TOKEN, "epimms_id");
assertThat(courtDetailList, is(notNullValue()));
}
Expand Down
3 changes: 3 additions & 0 deletions src/contractTest/resources/CourtDetailsRespBody.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{"users":[{"courtVenueId":"10047","epimmsId":"231596"}]}
]
3 changes: 3 additions & 0 deletions src/contractTest/resources/JudgeDetailsRespBody.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{"users":[{"personalCode":"4925644","hearingJudgeName":"Henry Taylor"}]}
]
Loading