Skip to content

Commit

Permalink
Change party url to business url (#258)
Browse files Browse the repository at this point in the history
* Change party url to business url

* Fix test url mocking

* auto patch increment

Co-authored-by: ras-rm-pr-bot <[email protected]>
  • Loading branch information
insacuri and ras-rm-pr-bot authored Jul 15, 2021
1 parent 8a0c42a commit 604edd5
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 26 deletions.
2 changes: 1 addition & 1 deletion _infra/helm/collection-exercise/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ version: 1.4.0
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.

appVersion: 11.1.6
appVersion: 11.1.7
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import uk.gov.ons.ctp.response.collection.exercise.lib.party.definition.SampleLinkCreationRequestDTO;
import uk.gov.ons.ctp.response.collection.exercise.lib.party.representation.PartyDTO;
import uk.gov.ons.ctp.response.collection.exercise.lib.party.representation.SampleLinkDTO;
import uk.gov.ons.ctp.response.collection.exercise.lib.sample.representation.SampleUnitDTO;

/** HTTP RestClient implementation for calls to the Party service */
@Component
Expand All @@ -40,21 +39,18 @@ public PartySvcClient(
/**
* Request party from the Party Service
*
* @param sampleUnitType the sample unit type for which to request party
* @param sampleUnitRef the sample unit ref for which to request party
* @return the party object
*/
@Retryable(
value = {RestClientException.class},
maxAttemptsExpression = "#{${retries.maxAttempts}}",
backoff = @Backoff(delayExpression = "#{${retries.backoff}}"))
public PartyDTO requestParty(SampleUnitDTO.SampleUnitType sampleUnitType, String sampleUnitRef) {
log.with("sample_unit_type", sampleUnitType)
.with("sample_unit_ref", sampleUnitRef)
.debug("Retrieving party");
public PartyDTO requestParty(String sampleUnitRef) {
log.with("sample_unit_ref", sampleUnitRef).debug("Retrieving party");
UriComponents uriComponents =
restUtility.createUriComponents(
appConfig.getPartySvc().getRequestPartyPath(), null, sampleUnitType, sampleUnitRef);
appConfig.getPartySvc().getRequestPartyPath(), null, sampleUnitRef);
HttpEntity<PartyDTO> httpEntity = restUtility.createHttpEntityWithAuthHeader();
ResponseEntity<PartyDTO> responseEntity =
restTemplate.exchange(uriComponents.toUri(), HttpMethod.GET, httpEntity, PartyDTO.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ private void distributeSampleUnitGroup(
* @return True if a respondent is enrolled, false otherwise
*/
private boolean hasActiveEnrolment(ExerciseSampleUnit sampleUnit, CollectionExercise exercise) {
PartyDTO businessParty =
partySvcClient.requestParty(sampleUnit.getSampleUnitType(), sampleUnit.getSampleUnitRef());
PartyDTO businessParty = partySvcClient.requestParty(sampleUnit.getSampleUnitRef());
return surveyHasEnrolledRespondent(businessParty, exercise.getSurveyId().toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ public void validateSampleUnits() {

if (sampleUnit.getSampleUnitType() == SampleUnitDTO.SampleUnitType.B) {
try {
PartyDTO party =
partySvcClient.requestParty(
sampleUnit.getSampleUnitType(), sampleUnit.getSampleUnitRef());
PartyDTO party = partySvcClient.requestParty(sampleUnit.getSampleUnitRef());
sampleUnit.setPartyId(UUID.fromString(party.getId()));
} catch (HttpClientErrorException e) {
if (e.getStatusCode() != HttpStatus.NOT_FOUND) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ collection-instrument-svc:
read-timeout-milli-seconds: 5000

party-svc:
request-party-path: /party-api/v1/parties/type/{sampleUnitType}/ref/{sampleUnitRef}
request-party-path: /party-api/v1/businesses/ref/{sampleUnitRef}
sample-link-path: /party-api/v1/businesses/sample/link/{sampleSummaryId}
connection-config:
scheme: http
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import uk.gov.ons.ctp.response.collection.exercise.lib.common.rest.RestUtilityConfig;
import uk.gov.ons.ctp.response.collection.exercise.lib.party.representation.PartyDTO;
import uk.gov.ons.ctp.response.collection.exercise.lib.party.representation.SampleLinkDTO;
import uk.gov.ons.ctp.response.collection.exercise.lib.sample.representation.SampleUnitDTO;

@RunWith(MockitoJUnitRunner.class)
public class PartySvcClientTest {
Expand Down Expand Up @@ -59,7 +58,7 @@ public void getParty_200Response() {
.thenReturn(new ResponseEntity<>(HttpStatus.CREATED));

// When
partySvcClient.requestParty(SampleUnitDTO.SampleUnitType.B, SAMPLE_UNIT_REF);
partySvcClient.requestParty(SAMPLE_UNIT_REF);

// Then
verify(restTemplate, times(1))
Expand All @@ -74,7 +73,7 @@ public void getParty_500Response() {
.thenThrow(new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR));

// When
partySvcClient.requestParty(SampleUnitDTO.SampleUnitType.B, SAMPLE_UNIT_REF);
partySvcClient.requestParty(SAMPLE_UNIT_REF);

// Then
verify(restTemplate, times(1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void setUp() throws Exception {

when(sampleUnitRepo.findBySampleUnitGroup(any())).thenReturn(sampleUnitParentOnly);

when(partySvcClient.requestParty(any(), any())).thenReturn(parties.get(0));
when(partySvcClient.requestParty(any())).thenReturn(parties.get(0));

when(sampleUnitGroupRepo.countByStateFKAndCollectionExercise(
eq(SampleUnitGroupDTO.SampleUnitGroupState.PUBLISHED), any()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ private void stubGetPartyBySampleUnitRef() throws IOException {
CollectionExerciseEndpointIT.class,
"CollectionExerciseEndpointIT.PartyDTO.with-associations.json");
this.wireMockRule.stubFor(
get(urlPathMatching("/party-api/v1/parties/type/(.*)/ref/(.*)"))
get(urlPathMatching("/party-api/v1/businesses/ref/(.*)"))
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(json)));
}

Expand All @@ -422,7 +422,7 @@ private void stubGetPartyNoAssociations() throws IOException {
CollectionExerciseEndpointIT.class,
"CollectionExerciseEndpointIT.PartyDTO.no-associations.json");
this.wireMockRule.stubFor(
get(urlPathMatching("/party-api/v1/parties/type/B/ref/(.*)"))
get(urlPathMatching("/party-api/v1/businesses/ref/(.*)"))
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(json)));
}

Expand All @@ -432,7 +432,7 @@ private void stubGetPartyWithAssociations() throws IOException {
CollectionExerciseEndpointIT.class,
"CollectionExerciseEndpointIT.PartyDTO.with-associations.json");
this.wireMockRule.stubFor(
get(urlPathMatching("/party-api/v1/parties/type/B/ref/(.*)"))
get(urlPathMatching("/party-api/v1/businesses/ref/(.*)"))
.willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(json)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void testValidateSampleUnits() throws CTPException {
when(collectionInstrumentSvcClient.requestCollectionInstruments(any()))
.thenReturn(collectionInstruments);

when(partySvcClient.requestParty(any(), any())).thenReturn(party);
when(partySvcClient.requestParty(any())).thenReturn(party);

when(sampleUnitGroupState.transition(any(), any())).thenReturn(SampleUnitGroupState.VALIDATED);

Expand Down Expand Up @@ -207,7 +207,7 @@ public void testValidateSampleUnitsMultipleCollectionInstruments() throws CTPExc
eq("{\"SURVEY_ID\":\"d943344b-1ef4-4c24-b59b-23e3a0350158\",\"FORM_TYPE\":\"0666\"}")))
.thenReturn(collectionInstrumentsTwo);

when(partySvcClient.requestParty(any(), any())).thenReturn(party);
when(partySvcClient.requestParty(any())).thenReturn(party);

when(sampleUnitGroupState.transition(any(), any())).thenReturn(SampleUnitGroupState.VALIDATED);

Expand Down Expand Up @@ -292,7 +292,7 @@ public void testValidateSampleUnitsRequestPartyFail() {
when(collectionInstrumentSvcClient.requestCollectionInstruments(any()))
.thenReturn(collectionInstruments);

when(partySvcClient.requestParty(any(), any()))
when(partySvcClient.requestParty(any()))
.thenThrow(new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "Error"));

// When
Expand Down Expand Up @@ -335,7 +335,7 @@ public void testValidateSampleUnitsCollectionInstrumentNotFound() throws CTPExce
when(collectionInstrumentSvcClient.requestCollectionInstruments(any()))
.thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND, "Bad stuff happened"));

when(partySvcClient.requestParty(any(), any())).thenReturn(party);
when(partySvcClient.requestParty(any())).thenReturn(party);

when(sampleUnitGroupState.transition(any(), any()))
.thenReturn(SampleUnitGroupState.FAILEDVALIDATION);
Expand Down Expand Up @@ -445,7 +445,7 @@ public void testValidateSampleUnitsPartyNotFound() throws CTPException {
when(collectionInstrumentSvcClient.requestCollectionInstruments(any()))
.thenReturn(collectionInstruments);

when(partySvcClient.requestParty(any(), any()))
when(partySvcClient.requestParty(any()))
.thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND, "Bad stuff happened"));

when(sampleUnitGroupState.transition(any(), any()))
Expand Down

0 comments on commit 604edd5

Please sign in to comment.