generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #714 from hmcts/RDCC-6706-SRD_WireMock_response_en…
…hancement RDCC-6706 SRD:WireMock response enhancement
- Loading branch information
Showing
4 changed files
with
136 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package uk.gov.hmcts.reform.cwrdapi.util; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.github.tomakehurst.wiremock.common.FileSource; | ||
import com.github.tomakehurst.wiremock.extension.Parameters; | ||
|
@@ -34,6 +35,7 @@ | |
import uk.gov.hmcts.reform.lib.util.serenity5.SerenityTest; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
|
@@ -57,7 +59,7 @@ | |
@SerenityTest | ||
@WithTags({@WithTag("testType:Integration")}) | ||
@TestPropertySource(properties = {"S2S_URL=http://127.0.0.1:8990", "IDAM_URL:http://127.0.0.1:5000", | ||
"USER_PROFILE_URL:http://127.0.0.1:8091", "spring.config.location=classpath:application-test.yml"}) | ||
"USER_PROFILE_URL:http://127.0.0.1:8091", "spring.config.location=classpath:application-test.yml"}) | ||
@ContextConfiguration(classes = {TestConfig.class, RestTemplateConfiguration.class}) | ||
public abstract class AuthorizationEnabledIntegrationTest extends SpringBootIntegrationTest { | ||
|
||
|
@@ -122,72 +124,71 @@ public void setUpClient() { | |
public void setupIdamStubs() throws Exception { | ||
|
||
s2sService.stubFor(get(urlEqualTo("/details")) | ||
.willReturn(aResponse() | ||
.withStatus(200) | ||
.withHeader("Content-Type", "application/json") | ||
.withHeader("Connection", "close") | ||
.withBody("rd_caseworker_ref_api"))); | ||
.willReturn(aResponse() | ||
.withStatus(200) | ||
.withHeader("Content-Type", "application/json") | ||
.withHeader("Connection", "close") | ||
.withBody("rd_caseworker_ref_api"))); | ||
|
||
|
||
UserIdentifier userDetails = UserIdentifier.builder() | ||
.id("%s") | ||
.uid("%s") | ||
.forename("Super") | ||
.surname("User") | ||
.email("[email protected]") | ||
.accountStatus("active") | ||
.roles(List.of("%s")) | ||
.build(); | ||
|
||
sidamService.stubFor(get(urlPathMatching("/o/userinfo")) | ||
.willReturn(aResponse() | ||
.withStatus(200) | ||
.withHeader("Content-Type", "application/json") | ||
.withHeader("Connection", "close") | ||
.withBody("{" | ||
+ " \"id\": \"%s\"," | ||
+ " \"uid\": \"%s\"," | ||
+ " \"forename\": \"Super\"," | ||
+ " \"surname\": \"User\"," | ||
+ " \"email\": \"[email protected]\"," | ||
+ " \"accountStatus\": \"active\"," | ||
+ " \"roles\": [" | ||
+ " \"%s\"" | ||
+ " ]" | ||
+ "}") | ||
.withTransformers("user-token-response"))); | ||
.willReturn(aResponse() | ||
.withStatus(200) | ||
.withHeader("Content-Type", "application/json") | ||
.withHeader("Connection", "close") | ||
.withBody(WireMockUtil.getObjectMapper().writeValueAsString(userDetails)) | ||
.withTransformers("user-token-response"))); | ||
|
||
mockHttpServerForOidc.stubFor(get(urlPathMatching("/jwks")) | ||
.willReturn(aResponse() | ||
.withStatus(200) | ||
.withHeader("Content-Type", "application/json") | ||
.withHeader("Connection", "close") | ||
.withBody(getDynamicJwksResponse()))); | ||
.willReturn(aResponse() | ||
.withStatus(200) | ||
.withHeader("Content-Type", "application/json") | ||
.withHeader("Connection", "close") | ||
.withBody(getDynamicJwksResponse()))); | ||
} | ||
|
||
public void userProfileGetUserWireMock(String idamStatus, String roles) { | ||
public void userProfileGetUserWireMock(String idamStatus, String roles) throws JsonProcessingException { | ||
userProfileService.stubFor(get(urlPathMatching("/v1/userprofile.*")) | ||
.willReturn(aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withHeader("Connection", "close") | ||
.withStatus(200) | ||
.withBody("{" | ||
+ " \"userIdentifier\":\"" + UUID.randomUUID().toString() + "\"," | ||
+ " \"firstName\": \"prashanth\"," | ||
+ " \"lastName\": \"rao\"," | ||
+ " \"email\": \"[email protected]\"," | ||
+ " \"idamStatus\": \"" + idamStatus + "\"," | ||
+ " \"roles\": " + roles | ||
+ "}"))); | ||
.willReturn(aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withHeader("Connection", "close") | ||
.withStatus(200) | ||
.withBody(WireMockUtil.getObjectMapper().writeValueAsString( | ||
getUserIdentifierData(idamStatus, roles)))) | ||
); | ||
} | ||
|
||
public void userProfileGetUserByIdWireMock(String idamId, Integer status) { | ||
public void userProfileGetUserByIdWireMock(String idamId, Integer status) throws JsonProcessingException { | ||
userProfileService.stubFor(get(urlPathMatching("/v1/userprofile.*")) | ||
.willReturn(aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withHeader("Connection", "close") | ||
.withStatus(status) | ||
.withBody("{" | ||
+ " \"userIdentifier\":\"" + UUID.randomUUID().toString() + "\"," | ||
+ " \"firstName\": \"prashanth\"," | ||
+ " \"lastName\": \"rao\"," | ||
+ " \"email\": \"[email protected]\"," | ||
+ " \"idamStatus\": \"pending\"," | ||
+ " \"roles\": [" | ||
+ " \"%s\"" | ||
+ " ]" | ||
+ "}"))); | ||
.withBody(WireMockUtil.getObjectMapper().writeValueAsString( | ||
getUserIdentifierData("pending", "%s")))) | ||
); | ||
} | ||
|
||
private UserIdentifier getUserIdentifierData(String idamStatus, String roles) { | ||
return UserIdentifier.builder() | ||
.userIdentifier(UUID.randomUUID().toString()) | ||
.firstName("prashanth") | ||
.lastName("rao") | ||
.email("[email protected]") | ||
.idamStatus(idamStatus) | ||
.roles(List.of(roles)) | ||
.build(); | ||
} | ||
|
||
public void userProfileDeleteUserWireMock() { | ||
userProfileService.stubFor(delete(urlPathMatching("/v1/userprofile/users.*")) | ||
|
@@ -209,11 +210,11 @@ public void modifyUserRoles() throws Exception { | |
userProfileRolesResponse.setRoleAdditionResponse(roleAdditionRes); | ||
|
||
userProfileService.stubFor(put(urlPathMatching("/v1/userprofile.*")) | ||
.willReturn(aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withHeader("Connection", "close") | ||
.withStatus(201) | ||
.withBody(objectMapper.writeValueAsString(userProfileRolesResponse)))); | ||
.willReturn(aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withHeader("Connection", "close") | ||
.withStatus(201) | ||
.withBody(objectMapper.writeValueAsString(userProfileRolesResponse)))); | ||
} | ||
|
||
public void modifyUserStatus(int idamStatus) throws Exception { | ||
|
@@ -225,26 +226,26 @@ public void modifyUserStatus(int idamStatus) throws Exception { | |
userProfileRolesResponse.setAttributeResponse(attributeResponse); | ||
|
||
userProfileService.stubFor(put(urlPathMatching("/v1/userprofile.*")) | ||
.willReturn(aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withHeader("Connection", "close") | ||
.withStatus(201) | ||
.withBody(objectMapper.writeValueAsString(userProfileRolesResponse)))); | ||
.willReturn(aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withHeader("Connection", "close") | ||
.withStatus(201) | ||
.withBody(objectMapper.writeValueAsString(userProfileRolesResponse)))); | ||
} | ||
|
||
//removed UUID mock here and put in Test config,hence use this only for insert integration testing | ||
//for update use insert response UUID in test or other mock methods | ||
@BeforeEach | ||
public void userProfilePostUserWireMock() { | ||
userProfileService.stubFor(post(urlPathMatching("/v1/userprofile")) | ||
.inScenario("") | ||
.willReturn(aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withHeader("Connection", "close") | ||
.withStatus(201) | ||
.withBody("{" | ||
+ " \"idamRegistrationResponse\":\"201\"" | ||
+ "}"))); | ||
.inScenario("") | ||
.willReturn(aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withHeader("Connection", "close") | ||
.withStatus(201) | ||
.withBody("{" | ||
+ " \"idamRegistrationResponse\":\"201\"" | ||
+ "}"))); | ||
} | ||
|
||
@AfterEach | ||
|
@@ -258,13 +259,13 @@ public void cleanupTestData() { | |
public void userProfileCreateUserWireMock(HttpStatus status) { | ||
|
||
userProfileService.stubFor(post(urlPathMatching("/v1/userprofile")) | ||
.willReturn(aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withHeader("Connection", "close") | ||
.withStatus(status.value()) | ||
.withBody("{" | ||
+ " \"idamRegistrationResponse\":\"" + status.value() + "\"" | ||
+ "}"))); | ||
.willReturn(aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withHeader("Connection", "close") | ||
.withStatus(status.value()) | ||
.withBody("{" | ||
+ " \"idamRegistrationResponse\":\"" + status.value() + "\"" | ||
+ "}"))); | ||
} | ||
|
||
public void userProfilePostUserWireMockForStaffProfile(HttpStatus status) { | ||
|
@@ -303,8 +304,8 @@ public Response transform(Request request, Response response, FileSource files, | |
formatResponse = format(formatResponse, tokenInfo.get(1), tokenInfo.get(1), tokenInfo.get(0)); | ||
|
||
return Response.Builder.like(response) | ||
.but().body(formatResponse) | ||
.build(); | ||
.but().body(formatResponse) | ||
.build(); | ||
} | ||
|
||
@Override | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/util/UserIdentifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package uk.gov.hmcts.reform.cwrdapi.util; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@EqualsAndHashCode | ||
@ToString | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class UserIdentifier { | ||
private String id; | ||
private String uid; | ||
private String forename; | ||
private String surname; | ||
private String email; | ||
private String accountStatus; | ||
private List<String> roles; | ||
private String userIdentifier; | ||
private String firstName; | ||
private String lastName; | ||
private String idamStatus; | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/integrationTest/java/uk/gov/hmcts/reform/cwrdapi/util/WireMockUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package uk.gov.hmcts.reform.cwrdapi.util; | ||
|
||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public class WireMockUtil { | ||
|
||
private WireMockUtil() { | ||
|
||
} | ||
|
||
public static ObjectMapper getObjectMapper() { | ||
ObjectMapper mapper = new ObjectMapper() | ||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
return mapper; | ||
|
||
} | ||
} |