Skip to content

Commit

Permalink
DTSCCI-1005 fix fee register pact (#5854)
Browse files Browse the repository at this point in the history
* DTSCCI-1005: Fix fee range pact test
  • Loading branch information
ruban72 authored Dec 3, 2024
1 parent 99051d2 commit afbe2e7
Show file tree
Hide file tree
Showing 16 changed files with 1,161 additions and 1,168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import au.com.dius.pact.consumer.junit5.PactConsumerTestExt;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.json.JSONException;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import java.io.IOException;

@ExtendWith(PactConsumerTestExt.class)
@ActiveProfiles("integration-test")
@SpringBootTest
Expand All @@ -19,4 +22,8 @@ public class BaseContractTest {

@Autowired
protected ObjectMapper objectMapper;

protected String createJsonObject(Object obj) throws JSONException, IOException {
return objectMapper.writeValueAsString(obj);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public class CaseAssignmentApiConsumerTest extends BaseContractTest {
@Autowired
private CaseAssignmentApi caseAssignmentApi;

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getUserRoles(PactDslWithProvider builder)
throws JSONException, IOException {
return buildGetUserRolesResponsePact(builder);
}

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact removeCaseUserRoles(PactDslWithProvider builder)
throws JSONException, IOException {
return buildRemoveUserRolesResponsePact(builder);
Expand Down Expand Up @@ -95,7 +95,7 @@ private RequestResponsePact buildRemoveUserRolesResponsePact(PactDslWithProvider
.path(ENDPOINT)
.headers(SERVICE_AUTHORIZATION_HEADER, SERVICE_AUTH_TOKEN, AUTHORIZATION_HEADER, AUTHORIZATION_TOKEN)
.method(HttpMethod.DELETE.toString())
.body(objectMapper.writeValueAsString(getRequestEntity()))
.body(createJsonObject(getRequestEntity()))
.willRespondWith()
.matchHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.body(buildRemoveUserRolesResponseBody())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class CmcClaimsForClaimantApiConsumerTest extends BaseContractTest {
@Autowired
private ClaimStoreApi claimStoreApi;

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getClaimsForClaimant(PactDslWithProvider builder)
throws JSONException, IOException {
return buildClaimsForClaimantPact(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class CmcClaimsForDefendantApiConsumerTest extends BaseContractTest {
@Autowired
private ClaimStoreApi claimStoreApi;

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getClaimsForDefendant(PactDslWithProvider builder)
throws JSONException, IOException {
return buildClaimsForDefendantPact(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class CmcDefendantLinkedApiConsumerTest extends BaseContractTest {
@Autowired
private ClaimStoreApi claimStoreApi;

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getClaimsForDefendant(PactDslWithProvider builder)
throws JSONException, IOException {
return buildClaimsForDefendantPact(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class DocmosisApiConsumerTest extends BaseContractTest {
@Autowired
private DocmosisApiClient docmosisApiClient;

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact postCreateDocumentRequest(PactDslWithProvider builder)
throws JSONException, IOException {
return buildCreateDocumentResponsePact(builder);
Expand Down Expand Up @@ -73,7 +73,4 @@ private DocmosisRequest getDocmosisRequest() {
.build();
}

private String createJsonObject(Object obj) throws JSONException, IOException {
return objectMapper.writeValueAsString(obj);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class FeesLookupApiConsumerTest extends BaseContractTest {
@MockBean
private FeatureToggleService featureToggleService;

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getFeeForHearingSmallClaims(PactDslWithProvider builder) throws JSONException {
return buildLookupFeeWithAmountPact(
builder,
Expand All @@ -84,7 +84,7 @@ public RequestResponsePact getFeeForHearingSmallClaims(PactDslWithProvider build
);
}

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getFeeForHearingFastTrackClaims(PactDslWithProvider builder) throws JSONException {
return buildLookupFeeWithAmountPact(
builder,
Expand All @@ -101,7 +101,7 @@ public RequestResponsePact getFeeForHearingFastTrackClaims(PactDslWithProvider b
);
}

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getFeeForHearingMultiClaims(PactDslWithProvider builder) throws JSONException {
return buildLookupFeeWithAmountPact(
builder,
Expand All @@ -118,7 +118,7 @@ public RequestResponsePact getFeeForHearingMultiClaims(PactDslWithProvider build
);
}

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getFeeForMoneyClaim(PactDslWithProvider builder) throws JSONException {
return buildLookupFeeWithAmountPact(
builder,
Expand All @@ -135,7 +135,7 @@ public RequestResponsePact getFeeForMoneyClaim(PactDslWithProvider builder) thro
);
}

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getFeeForMoneyClaimWithoutKeyword(PactDslWithProvider builder) throws JSONException {
return buildLookupFeeWithoutKeywordPact(
builder,
Expand All @@ -151,7 +151,7 @@ public RequestResponsePact getFeeForMoneyClaimWithoutKeyword(PactDslWithProvider
);
}

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getFeeForGAWithNotice(PactDslWithProvider builder) throws JSONException {
return buildLookupFeePact(
builder,
Expand All @@ -167,7 +167,7 @@ public RequestResponsePact getFeeForGAWithNotice(PactDslWithProvider builder) th
);
}

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getFeeForConsentWithOrWithout(PactDslWithProvider builder) throws JSONException {
return buildLookupFeePact(
builder,
Expand All @@ -183,7 +183,7 @@ public RequestResponsePact getFeeForConsentWithOrWithout(PactDslWithProvider bui
);
}

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getFeeForAppToVaryOrSuspend(PactDslWithProvider builder) throws JSONException {
return buildLookupFeePact(
builder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import uk.gov.hmcts.reform.civil.model.Fee2Dto;
import uk.gov.hmcts.reform.civil.service.FeesClientService;

import java.math.BigDecimal;

import static au.com.dius.pact.consumer.dsl.LambdaDsl.newJsonArray;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
Expand All @@ -41,7 +43,7 @@ public class FeesRangeGroupApiConsumerTest extends BaseContractTest {
@Autowired
private FeesConfiguration feesConfiguration;

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getRangeGroupFees(PactDslWithProvider builder) throws JSONException {
return buildLookupRangeGroupFeesResponsePact(
builder,
Expand All @@ -55,7 +57,27 @@ public RequestResponsePact getRangeGroupFees(PactDslWithProvider builder) throws
public void verifyRangeGroupFees() {
Fee2Dto[] fee = feesClientService.findRangeGroup(feesConfiguration.getChannel(), feesConfiguration.getEvent()
);
assertThat(fee[0].getCode(), is(equalTo("code")));
assertThat(fee[0].getCode(), is(equalTo("FEE0209")));
assertThat(fee[0].getFeeType(), is(equalTo("FEETYPE")));
assertThat(fee[0].getKeyword(), is(equalTo("MoneyClaim")));
assertThat(fee[0].getMinRange(), is(equalTo(BigDecimal.valueOf(100))));
assertThat(fee[0].getMaxRange(), is(equalTo(BigDecimal.valueOf(100))));
assertThat(fee[0].getRangeUnit(), is(equalTo("GBP")));
assertThat(fee[0].getUnspecifiedClaimAmount(), is(equalTo(true)));
assertThat(fee[0].getFeeVersions().get(0).getVersion(), is(equalTo(2)));
assertThat(fee[0].getFeeVersions().get(0).getAuthor(), is(equalTo("124756")));
assertThat(fee[0].getFeeVersions().get(0).getApprovedBy(), is(equalTo("39907")));
assertThat(fee[0].getFeeVersions().get(0).getDescription(), is(equalTo("Counter Claim - 5000.01 up to 10000 GBP")));
assertThat(fee[0].getFeeVersions().get(0).getStatus(), is(equalTo("approved")));
assertThat(fee[0].getFeeVersions().get(0).getValidFrom().toString(), is(equalTo("2015-03-09T00:00Z")));
assertThat(fee[0].getFeeVersions().get(0).getValidTo().toString(), is(equalTo("2022-03-09T00:00Z")));
assertThat(fee[0].getFeeVersions().get(0).getFlatAmount().getAmount(), is(equalTo(BigDecimal.valueOf(455))));
assertThat(fee[0].getFeeVersions().get(0).getMemoLine(), is(equalTo("RECEIPT OF FEES - Civil issue money")));
assertThat(fee[0].getFeeVersions().get(0).getStatutoryInstrument(), is(equalTo("2014 No 874")));
assertThat(fee[0].getFeeVersions().get(0).getSiRefId(), is(equalTo("1.1h")));
assertThat(fee[0].getFeeVersions().get(0).getNaturalAccountCode(), is(equalTo("4481102133")));
assertThat(fee[0].getFeeVersions().get(0).getPercentageAmount().getPercentage(), is(equalTo(BigDecimal.valueOf(5))));
assertThat(fee[0].getFeeVersions().get(0).getDirection(), is(equalTo("enhanced")));
}

private RequestResponsePact buildLookupRangeGroupFeesResponsePact(PactDslWithProvider builder,
Expand All @@ -82,85 +104,60 @@ private RequestResponsePact buildLookupRangeGroupFeesResponsePact(PactDslWithPro
private DslPart buildRangeGroupFeesResponseBody() {
return newJsonArray(response -> response
.object(feeDto -> feeDto
.object("applicantType", applicantType ->
.object("applicant_type", applicantType ->
applicantType
.stringMatcher("creationTime",
"^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{1,6})$",
"2020-10-06T18:54:48.785000")
.stringMatcher("lastUpdated",
"^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{1,6})$",
"2020-10-06T18:54:48.785000")
.stringType("name", "name"))
.object("channelType", channelTypeDto ->
.stringValue("name", "all"))
.object("channel_type", channelTypeDto ->
channelTypeDto
.stringMatcher("creationTime",
"^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{1,6})$",
"2020-10-06T18:54:48.785000")
.stringMatcher("lastUpdated",
"^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{1,6})$",
"2020-10-06T18:54:48.785000")
.stringType("name", "name"))
.stringType("code", "code")
.object("currentVersion", feeVersionDto ->
.stringValue("name", "default"))
.stringValue("code", "FEE0209")
.object("current_version", feeVersionDto ->
getFeeVersionDto(feeVersionDto))
.object("eventType", eventType -> eventType
.stringMatcher("creationTime",
"^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{1,6})$",
"2020-10-06T18:54:48.785000")
.stringMatcher("lastUpdated",
"^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{1,6})$",
"2020-10-06T18:54:48.785000")
.stringType("name", "name"))
.stringType("feeType", "FEETYPE")
.minArrayLike("feeVersions", 1, feeVersions -> getFeeVersionDto(feeVersions))
.object("event_type", eventType -> eventType
.stringValue("name", "issue"))
.stringValue("fee_type", "FEETYPE")
.minArrayLike("fee_versions", 1, feeVersions -> getFeeVersionDto(feeVersions))
.object("jurisdiction1", jurisdiction1 ->
jurisdiction1
.stringType("name", "name"))
.stringValue("name", "civil"))
.object("jurisdiction2", jurisdiction2 ->
jurisdiction2
.stringType("name", "name"))
.stringType("keyword", "keyword")
.object("matchingVersion", feeVersionDto ->
.stringValue("name", "county court"))
.stringValue("keyword", "MoneyClaim")
.object("matching_version", feeVersionDto ->
getFeeVersionDto(feeVersionDto))
.numberType("maxRange", "maxRange")
.numberType("minRange", "minRange")
.stringType("rangeUnit", "rangeUnit")
.object("serviceType", serviceType -> serviceType
.stringMatcher("creationTime",
"^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{1,6})$",
"2020-10-06T18:54:48.785000")
.stringMatcher("lastUpdated",
"^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{1,6})$",
"2020-10-06T18:54:48.785000")
.stringType("name", "name"))
.booleanType("unspecifiedClaimAmount")
.numberType("max_range", 100)
.numberType("min_range", 100)
.stringValue("range_unit", "GBP")
.object("service_type", serviceType -> serviceType
.stringValue("name", "civil money claims"))
.booleanType("unspecified_claim_amount")
)).build();
}

private static LambdaDslObject getFeeVersionDto(LambdaDslObject feeVersionDto) {

return feeVersionDto
.stringType("approvedBy", "approvedBy")
.stringType("author", "author")
.stringType("description", "description")
.stringType("direction", "direction")
.object("flatAmount", flatAmount ->
.stringType("approvedBy", "39907")
.stringType("author", "124756")
.stringType("description", "Counter Claim - 5000.01 up to 10000 GBP")
.stringType("direction", "enhanced")
.object("flat_amount", flatAmount ->
flatAmount
.numberType("amount"))
.stringType("memoLine", "memoLine")
.stringType("naturalAccountCode", "naturalAccountCode")
.object("percentageAmount", percentageAmount -> percentageAmount
.numberType("percentage"))
.stringType("siRefId", "siRefId")
.stringType("status", "status")
.stringType("statutoryInstrument", "statutoryInstrument")
.stringMatcher("validFrom",
"^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{1,6})$",
"2020-10-06T18:54:48.785000")
.stringMatcher("validTo",
"^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{1,6})$",
"2020-10-06T18:54:48.785000")
.numberType("version")
.object("volumeAmount", volumeAmount -> volumeAmount
.numberType("amount"));
.numberType("amount", 455))
.stringType("memo_line", "RECEIPT OF FEES - Civil issue money")
.stringType("natural_account_code", "4481102133")
.object("percentage_amount", percentageAmount -> percentageAmount
.numberType("percentage", 5))
.stringType("si_ref_id", "1.1h")
.stringType("status", "approved")
.stringType("statutory_instrument", "2014 No 874")
.stringMatcher("valid_from",
"^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{1,6}\\+\\d{2}:\\d{2})$",
"2015-03-09T00:00:00.000+00:00")
.stringMatcher("valid_to",
"^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{1,6}\\+\\d{2}:\\d{2})$",
"2022-03-09T00:00:00.000+00:00")
.numberType("version", 2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,37 @@ public class LocationReferenceDataApiConsumerTest extends BaseContractTest {
@Autowired
private LocationReferenceDataApiClient locationReferenceDataApiClient;

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getCourtVenueByName(PactDslWithProvider builder)
throws JSONException, IOException {
return buildCourtVenueByNameResponsePact(builder);
}

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getCourtVenueByEpimmsId(PactDslWithProvider builder)
throws JSONException, IOException {
return buildCourtVenueByEpimmsIdResponsePact(builder);
}

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getCourtVenueByEpimmsIdAndType(PactDslWithProvider builder)
throws JSONException, IOException {
return buildCourtVenueByEpimmsIdAndTypeResponsePact(builder);
}

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getCourtVenueByLocationCode(PactDslWithProvider builder)
throws JSONException, IOException {
return buildCourtVenueByLocationCodeResponsePact(builder);
}

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getHearingVenue(PactDslWithProvider builder)
throws JSONException, IOException {
return buildHearingVenueResponsePact(builder);
}

@Pact(consumer = "civil-service")
@Pact(consumer = "civil_service")
public RequestResponsePact getCourtVenue(PactDslWithProvider builder)
throws JSONException, IOException {
return buildCourtVenueResponsePact(builder);
Expand Down Expand Up @@ -284,7 +284,4 @@ static DslPart buildLocationRefDataResponseBody() {
).build();
}

private String createJsonObject(Object obj) throws JSONException, IOException {
return objectMapper.writeValueAsString(obj);
}
}
Loading

0 comments on commit afbe2e7

Please sign in to comment.