From 73164087818e7fd74e2857a105d5ebc8ecb22d03 Mon Sep 17 00:00:00 2001 From: Mike Brown Date: Thu, 7 Dec 2023 12:07:09 +0000 Subject: [PATCH] greyed out unused stubs commented out, unused imports removed --- .../controller/utils/WiremockFixtures.java | 330 +++++++++--------- 1 file changed, 158 insertions(+), 172 deletions(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/orgrolemapping/controller/utils/WiremockFixtures.java b/src/integrationTest/java/uk/gov/hmcts/reform/orgrolemapping/controller/utils/WiremockFixtures.java index c54094507..3bde5e12c 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/orgrolemapping/controller/utils/WiremockFixtures.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/orgrolemapping/controller/utils/WiremockFixtures.java @@ -5,23 +5,14 @@ import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.github.tomakehurst.wiremock.client.WireMock; -import com.github.tomakehurst.wiremock.matching.EqualToJsonPattern; import com.nimbusds.jose.JOSEException; -import org.springframework.http.HttpStatus; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; -import uk.gov.hmcts.reform.idam.client.models.TokenResponse; import uk.gov.hmcts.reform.orgrolemapping.domain.model.Appointment; import uk.gov.hmcts.reform.orgrolemapping.domain.model.AssignmentRequest; -import uk.gov.hmcts.reform.orgrolemapping.domain.model.CaseWorkerProfile; -import uk.gov.hmcts.reform.orgrolemapping.domain.model.CaseWorkerProfilesResponse; -import uk.gov.hmcts.reform.orgrolemapping.domain.model.JudicialBooking; -import uk.gov.hmcts.reform.orgrolemapping.domain.model.JudicialBookingResponse; import uk.gov.hmcts.reform.orgrolemapping.domain.model.JudicialProfile; import uk.gov.hmcts.reform.orgrolemapping.domain.model.RoleAssignmentRequestResource; -import uk.gov.hmcts.reform.orgrolemapping.domain.model.UserRequest; import uk.gov.hmcts.reform.orgrolemapping.helper.AssignmentRequestBuilder; -import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -29,18 +20,13 @@ import static com.azure.core.http.ContentType.APPLICATION_JSON; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.badRequest; import static com.github.tomakehurst.wiremock.client.WireMock.configureFor; -import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.resetAllRequests; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching; -import static com.github.tomakehurst.wiremock.stubbing.Scenario.STARTED; import static org.springframework.http.HttpHeaders.CONTENT_TYPE; -import static org.springframework.http.HttpStatus.CREATED; -import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static uk.gov.hmcts.reform.orgrolemapping.controller.BaseTest.WIRE_MOCK_SERVER; @@ -60,13 +46,13 @@ public void resetRequests() { resetAllRequests(); } - public void stubRoleAssignmentServiceWithStatus(HttpStatus status) throws JsonProcessingException { - WIRE_MOCK_SERVER.stubFor(post(urlEqualTo("/am/role-assignments")) - .willReturn(aResponse() - .withStatus(status.value()) - .withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE) - .withBody(OBJECT_MAPPER.writeValueAsString(getRoleAssignmentRequestResource())))); - } +// public void stubRoleAssignmentServiceWithStatus(HttpStatus status) throws JsonProcessingException { +// WIRE_MOCK_SERVER.stubFor(post(urlEqualTo("/am/role-assignments")) +// .willReturn(aResponse() +// .withStatus(status.value()) +// .withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE) +// .withBody(OBJECT_MAPPER.writeValueAsString(getRoleAssignmentRequestResource())))); +// } private RoleAssignmentRequestResource getRoleAssignmentRequestResource() { var roleAssignmentRequestResource = @@ -86,96 +72,96 @@ public void stubRoleAssignmentServiceError() throws JsonProcessingException { .withBody(OBJECT_MAPPER.writeValueAsString(request)))); } - public void stubForGetCaseworkerDetailsById(UserRequest userRequest, - List response) throws JsonProcessingException { - - WIRE_MOCK_SERVER.stubFor(post(urlPathMatching("/refdata/case-worker/users/fetchUsersById")) - .withRequestBody(new EqualToJsonPattern( - OBJECT_MAPPER.writeValueAsString(userRequest), - true, - true) - ).willReturn(aResponse() - .withStatus(CREATED.value()) - .withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE) - .withBody(OBJECT_MAPPER.writeValueAsString(response)))); - } - - public void stubForGetCaseworkerDetailsByServiceName(List response) - throws JsonProcessingException { - - WIRE_MOCK_SERVER.stubFor(get(urlPathMatching("/refdata/internal/staff/usersByServiceName")) - .withQueryParam("ccd_service_names", equalTo("IA")) - .withQueryParam("page_size", equalTo("400")) - .withQueryParam("page_number", equalTo("0")) - .withQueryParam("sort_direction", equalTo("ASC")) - .withQueryParam("sort_column", equalTo("")) - .willReturn(aResponse() - .withStatus(OK.value()) - .withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE) - .withHeader("total_records", "2") - .withBody(OBJECT_MAPPER.writeValueAsString(response)))); - } - - public void stubForFailureGetCaseworkerDetailsByServiceName() throws JsonProcessingException { - - WIRE_MOCK_SERVER.stubFor(get(urlPathMatching("/refdata/internal/staff/usersByServiceName")) - .withQueryParam("ccd_service_names", equalTo("IA")) - .withQueryParam("page_size", equalTo("400")) - .withQueryParam("page_number", equalTo("0")) - .withQueryParam("sort_direction", equalTo("ASC")) - .withQueryParam("sort_column", equalTo("")) - .willReturn(badRequest().withBody("user not found"))); - } - - public void stubForFailureRetryAndSuccessGetCaseworkerDetailsByServiceName( - List response) throws JsonProcessingException { - - WIRE_MOCK_SERVER.stubFor(get(urlPathMatching("/refdata/internal/staff/usersByServiceName")) - .withQueryParam("ccd_service_names", equalTo("IA")) - .withQueryParam("page_size", equalTo("400")) - .withQueryParam("page_number", equalTo("0")) - .withQueryParam("sort_direction", equalTo("ASC")) - .withQueryParam("sort_column", equalTo("")) - .inScenario("multiple retries") - .whenScenarioStateIs(STARTED) - .willSetStateTo("secondRetry") - .willReturn(badRequest().withBody("user not found"))); - - WIRE_MOCK_SERVER.stubFor(get(urlPathMatching("/refdata/internal/staff/usersByServiceName")) - .withQueryParam("ccd_service_names", equalTo("IA")) - .withQueryParam("page_size", equalTo("400")) - .withQueryParam("page_number", equalTo("0")) - .withQueryParam("sort_direction", equalTo("ASC")) - .withQueryParam("sort_column", equalTo("")) - .inScenario("multiple retries") - .whenScenarioStateIs("secondRetry") - .willSetStateTo("success") - .willReturn(badRequest().withBody("user not found"))); - - WIRE_MOCK_SERVER.stubFor(get(urlPathMatching("/refdata/internal/staff/usersByServiceName")) - .withQueryParam("ccd_service_names", equalTo("IA")) - .withQueryParam("page_size", equalTo("400")) - .withQueryParam("page_number", equalTo("0")) - .withQueryParam("sort_direction", equalTo("ASC")) - .withQueryParam("sort_column", equalTo("")) - .inScenario("multiple retries") - .whenScenarioStateIs("success") - .willSetStateTo(STARTED) - .willReturn(aResponse() - .withStatus(OK.value()) - .withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE) - .withHeader("total_records", "2") - .withBody(OBJECT_MAPPER.writeValueAsString(response)))); - } - - public void stubForGetJudicialDetailsById(HttpStatus status, String userId) throws JsonProcessingException { - WIRE_MOCK_SERVER.stubFor(post(urlPathMatching("/refdata/judicial/users")) - .willReturn(aResponse() - .withStatus(status.value()) - .withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE) - .withHeader("total_records", "1") - .withBody(OBJECT_MAPPER.writeValueAsString(buildJudicialProfilesResponse(userId))))); - } +// public void stubForGetCaseworkerDetailsById(UserRequest userRequest, +// List response) throws JsonProcessingException { +// +// WIRE_MOCK_SERVER.stubFor(post(urlPathMatching("/refdata/case-worker/users/fetchUsersById")) +// .withRequestBody(new EqualToJsonPattern( +// OBJECT_MAPPER.writeValueAsString(userRequest), +// true, +// true) +// ).willReturn(aResponse() +// .withStatus(CREATED.value()) +// .withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE) +// .withBody(OBJECT_MAPPER.writeValueAsString(response)))); +// } +// +// public void stubForGetCaseworkerDetailsByServiceName(List response) +// throws JsonProcessingException { +// +// WIRE_MOCK_SERVER.stubFor(get(urlPathMatching("/refdata/internal/staff/usersByServiceName")) +// .withQueryParam("ccd_service_names", equalTo("IA")) +// .withQueryParam("page_size", equalTo("400")) +// .withQueryParam("page_number", equalTo("0")) +// .withQueryParam("sort_direction", equalTo("ASC")) +// .withQueryParam("sort_column", equalTo("")) +// .willReturn(aResponse() +// .withStatus(OK.value()) +// .withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE) +// .withHeader("total_records", "2") +// .withBody(OBJECT_MAPPER.writeValueAsString(response)))); +// } +// +// public void stubForFailureGetCaseworkerDetailsByServiceName() throws JsonProcessingException { +// +// WIRE_MOCK_SERVER.stubFor(get(urlPathMatching("/refdata/internal/staff/usersByServiceName")) +// .withQueryParam("ccd_service_names", equalTo("IA")) +// .withQueryParam("page_size", equalTo("400")) +// .withQueryParam("page_number", equalTo("0")) +// .withQueryParam("sort_direction", equalTo("ASC")) +// .withQueryParam("sort_column", equalTo("")) +// .willReturn(badRequest().withBody("user not found"))); +// } +// +// public void stubForFailureRetryAndSuccessGetCaseworkerDetailsByServiceName( +// List response) throws JsonProcessingException { +// +// WIRE_MOCK_SERVER.stubFor(get(urlPathMatching("/refdata/internal/staff/usersByServiceName")) +// .withQueryParam("ccd_service_names", equalTo("IA")) +// .withQueryParam("page_size", equalTo("400")) +// .withQueryParam("page_number", equalTo("0")) +// .withQueryParam("sort_direction", equalTo("ASC")) +// .withQueryParam("sort_column", equalTo("")) +// .inScenario("multiple retries") +// .whenScenarioStateIs(STARTED) +// .willSetStateTo("secondRetry") +// .willReturn(badRequest().withBody("user not found"))); +// +// WIRE_MOCK_SERVER.stubFor(get(urlPathMatching("/refdata/internal/staff/usersByServiceName")) +// .withQueryParam("ccd_service_names", equalTo("IA")) +// .withQueryParam("page_size", equalTo("400")) +// .withQueryParam("page_number", equalTo("0")) +// .withQueryParam("sort_direction", equalTo("ASC")) +// .withQueryParam("sort_column", equalTo("")) +// .inScenario("multiple retries") +// .whenScenarioStateIs("secondRetry") +// .willSetStateTo("success") +// .willReturn(badRequest().withBody("user not found"))); +// +// WIRE_MOCK_SERVER.stubFor(get(urlPathMatching("/refdata/internal/staff/usersByServiceName")) +// .withQueryParam("ccd_service_names", equalTo("IA")) +// .withQueryParam("page_size", equalTo("400")) +// .withQueryParam("page_number", equalTo("0")) +// .withQueryParam("sort_direction", equalTo("ASC")) +// .withQueryParam("sort_column", equalTo("")) +// .inScenario("multiple retries") +// .whenScenarioStateIs("success") +// .willSetStateTo(STARTED) +// .willReturn(aResponse() +// .withStatus(OK.value()) +// .withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE) +// .withHeader("total_records", "2") +// .withBody(OBJECT_MAPPER.writeValueAsString(response)))); +// } +// +// public void stubForGetJudicialDetailsById(HttpStatus status, String userId) throws JsonProcessingException { +// WIRE_MOCK_SERVER.stubFor(post(urlPathMatching("/refdata/judicial/users")) +// .willReturn(aResponse() +// .withStatus(status.value()) +// .withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE) +// .withHeader("total_records", "1") +// .withBody(OBJECT_MAPPER.writeValueAsString(buildJudicialProfilesResponse(userId))))); +// } private List buildJudicialProfilesResponse(String userId) { List bookings = new ArrayList<>(); @@ -192,45 +178,45 @@ private List buildJudicialProfilesResponse(String userId) { return bookings; } - public void stubForGetJudicialDetailsByIdFailure(HttpStatus status) throws JsonProcessingException { - Map body = Map.of( - "errorDescription", "The User Profile data could not be found", - "status", "Not Found"); - - WIRE_MOCK_SERVER.stubFor(post(urlPathMatching("/refdata/judicial/users")) - .willReturn(aResponse() - .withStatus(status.value()) - .withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE) - .withBody(OBJECT_MAPPER.writeValueAsString(body)))); - - } - - public void stubForGetJudicialBookingByUserIds(String... userIds) throws JsonProcessingException { - WIRE_MOCK_SERVER.stubFor(post(urlPathMatching("/am/bookings/query")) - .willReturn(aResponse() - .withStatus(OK.value()) - .withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE) - .withHeader("total_records", "1") - .withBody(OBJECT_MAPPER.writeValueAsString(buildJudicialBookingResponse(userIds))))); - } - - private JudicialBookingResponse buildJudicialBookingResponse(String... userIds) { - List bookings = new ArrayList<>(); - - for (String userId : userIds) { - bookings.add( - JudicialBooking.builder() - .beginTime(ZonedDateTime.now()) - .endTime(ZonedDateTime.now().plusDays(5)) - .userId(userId) - .locationId("location") - .regionId("region") - .build() - ); - } - - return new JudicialBookingResponse(bookings); - } +// public void stubForGetJudicialDetailsByIdFailure(HttpStatus status) throws JsonProcessingException { +// Map body = Map.of( +// "errorDescription", "The User Profile data could not be found", +// "status", "Not Found"); +// +// WIRE_MOCK_SERVER.stubFor(post(urlPathMatching("/refdata/judicial/users")) +// .willReturn(aResponse() +// .withStatus(status.value()) +// .withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE) +// .withBody(OBJECT_MAPPER.writeValueAsString(body)))); +// +// } + +// public void stubForGetJudicialBookingByUserIds(String... userIds) throws JsonProcessingException { +// WIRE_MOCK_SERVER.stubFor(post(urlPathMatching("/am/bookings/query")) +// .willReturn(aResponse() +// .withStatus(OK.value()) +// .withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE) +// .withHeader("total_records", "1") +// .withBody(OBJECT_MAPPER.writeValueAsString(buildJudicialBookingResponse(userIds))))); +// } + +// private JudicialBookingResponse buildJudicialBookingResponse(String... userIds) { +// List bookings = new ArrayList<>(); +// +// for (String userId : userIds) { +// bookings.add( +// JudicialBooking.builder() +// .beginTime(ZonedDateTime.now()) +// .endTime(ZonedDateTime.now().plusDays(5)) +// .userId(userId) +// .locationId("location") +// .regionId("region") +// .build() +// ); +// } +// +// return new JudicialBookingResponse(bookings); +// } public void stubIdamConfig() throws JsonProcessingException { @@ -250,18 +236,18 @@ public void stubIdamConfig() throws JsonProcessingException { } - private Map getUserInfoResponse() { - LinkedHashMap data1 = new LinkedHashMap<>(); - - data1.put("id","%s"); - data1.put("uid","%s"); - data1.put("forename","Super"); - data1.put("surname","User"); - data1.put("email","dummy@email.com"); - data1.put("roles", List.of("%s")); - - return data1; - } +// private Map getUserInfoResponse() { +// LinkedHashMap data1 = new LinkedHashMap<>(); +// +// data1.put("id","%s"); +// data1.put("uid","%s"); +// data1.put("forename","Super"); +// data1.put("surname","User"); +// data1.put("email","dummy@email.com"); +// data1.put("roles", List.of("%s")); +// +// return data1; +// } private Map getOpenIdResponse() { LinkedHashMap data1 = new LinkedHashMap<>(); @@ -283,16 +269,16 @@ private String getJwksResponse() { } - private TokenResponse getTokenResponse() { - return new TokenResponse( - "user1", - "expiresInValue", - "idTokenValue", - "refreshTokenValue", - "scopeValue", - "tokenTypeValue" - ); - } +// private TokenResponse getTokenResponse() { +// return new TokenResponse( +// "user1", +// "expiresInValue", +// "idTokenValue", +// "refreshTokenValue", +// "scopeValue", +// "tokenTypeValue" +// ); +// } public void stubRoleAssignments(String body, int returnHttpStatus) { WIRE_MOCK_SERVER.stubFor(WireMock.post(urlEqualTo("/am/role-assignments"))