Skip to content

Commit

Permalink
RDCC-6706 SRD:WireMock response enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
vilasshelke-hmcts committed Apr 21, 2023
1 parent 00ce324 commit 2296e87
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
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;
Expand Down Expand Up @@ -130,7 +131,7 @@ public void setupIdamStubs() throws Exception {
.withBody("rd_caseworker_ref_api")));


UserInfo userDetails = UserInfo.builder()
UserIdentifier userDetails = UserIdentifier.builder()
.id("%s")
.uid("%s")
.forename("Super")
Expand All @@ -145,8 +146,7 @@ public void setupIdamStubs() throws Exception {
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withHeader("Connection", "close")
.withBody(WireMockUtil.getObjectMapper()
.writeValueAsString(userDetails))
.withBody(WireMockUtil.getObjectMapper().writeValueAsString(userDetails))
.withTransformers("user-token-response")));

mockHttpServerForOidc.stubFor(get(urlPathMatching("/jwks"))
Expand All @@ -157,40 +157,38 @@ public void setupIdamStubs() throws Exception {
.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
+ "}")));
.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.*"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@
@EqualsAndHashCode
@ToString
@JsonIgnoreProperties(ignoreUnknown = true)
public class UserInfo {
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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ private WireMockUtil() {
}

public static ObjectMapper getObjectMapper() {

ObjectMapper mapper = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return mapper;
Expand Down

0 comments on commit 2296e87

Please sign in to comment.