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.
* Fetch Staff Profile By Id * Fetch Staff Profile By Id * Fetch Staff Profile By Id * Fetch Staff Profile By Id * checkstyle fixes * unit test * unit test * unit test * unit test * unit test * sonar fix * Integration Test * Dependency check * Dependency check * checkstyle fix * Integration test cases * Integration test cases * swagger change response * checkstyle fix * assert statement in integration * check style fix * Functional Test * Functional Test * Functional Test * Functional Test * Functional Test * LaunchDarkly configuration --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
770a30d
commit cd2ae4b
Showing
14 changed files
with
553 additions
and
52 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
100 changes: 100 additions & 0 deletions
100
src/functionalTest/java/uk/gov/hmcts/reform/cwrdapi/FetchStaffProfileByIdFunctionalTest.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,100 @@ | ||
package uk.gov.hmcts.reform.cwrdapi; | ||
|
||
import io.restassured.response.Response; | ||
import lombok.extern.slf4j.Slf4j; | ||
import net.thucydides.core.annotations.WithTag; | ||
import net.thucydides.core.annotations.WithTags; | ||
import org.junit.jupiter.api.MethodOrderer; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import uk.gov.hmcts.reform.cwrdapi.controllers.request.SkillsRequest; | ||
import uk.gov.hmcts.reform.cwrdapi.controllers.request.StaffProfileCreationRequest; | ||
import uk.gov.hmcts.reform.cwrdapi.controllers.response.SearchStaffUserByIdResponse; | ||
import uk.gov.hmcts.reform.cwrdapi.controllers.response.StaffProfileCreationResponse; | ||
import uk.gov.hmcts.reform.cwrdapi.idam.IdamOpenIdClient; | ||
import uk.gov.hmcts.reform.cwrdapi.util.FeatureToggleConditionExtension; | ||
import uk.gov.hmcts.reform.cwrdapi.util.ToggleEnable; | ||
import uk.gov.hmcts.reform.lib.util.serenity5.SerenityTest; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
@ComponentScan("uk.gov.hmcts.reform.cwrdapi") | ||
@WithTags({@WithTag("testType:Functional")}) | ||
@ActiveProfiles("functional") | ||
@SerenityTest | ||
@SpringBootTest | ||
@Slf4j | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
public class FetchStaffProfileByIdFunctionalTest extends AuthorizationFunctionalTest { | ||
|
||
public static final String FETCH_STAFF_PROFILE_BY_ID = "StaffRefDataController.fetchStaffProfileById"; | ||
public static final String STAFF_PROFILE_URL = "/refdata/case-worker"; | ||
|
||
@Test | ||
@ToggleEnable(mapKey = FETCH_STAFF_PROFILE_BY_ID, withFeature = true) | ||
@ExtendWith(FeatureToggleConditionExtension.class) | ||
void should_fetchStaffProfile_By_ID_200() { | ||
SkillsRequest skillsRequest = SkillsRequest | ||
.skillsRequest() | ||
.skillId(9) | ||
.description("testskill1") | ||
.skillCode("SKILL:AAA7:TEST1") | ||
.build(); | ||
|
||
StaffProfileCreationRequest staffProfileCreationRequest = caseWorkerApiClient | ||
.createStaffProfileCreationRequest(); | ||
staffProfileCreationRequest.setSkills(List.of(skillsRequest)); | ||
|
||
Response response = caseWorkerApiClient.createStaffUserProfile(staffProfileCreationRequest); | ||
|
||
assertNotNull(response); | ||
StaffProfileCreationResponse staffProfileCreationResponse = | ||
response.getBody().as(StaffProfileCreationResponse.class); | ||
assertNotNull(staffProfileCreationResponse); | ||
assertNotNull(staffProfileCreationResponse.getCaseWorkerId()); | ||
|
||
String firstCaseworkerId = staffProfileCreationResponse.getCaseWorkerId(); | ||
|
||
IdamOpenIdClient.cwdStaffAdminUserToken = null; | ||
Response fetchResponse = caseWorkerApiClient.getMultipleAuthHeadersInternal(ROLE_STAFF_ADMIN) | ||
.get(STAFF_PROFILE_URL + "/profile/search-by-id?id=" + firstCaseworkerId) | ||
.andReturn(); | ||
fetchResponse.then() | ||
.assertThat() | ||
.statusCode(200); | ||
|
||
SearchStaffUserByIdResponse caseWorkerProfile = | ||
fetchResponse.getBody().as(SearchStaffUserByIdResponse.class); | ||
|
||
assertThat(caseWorkerProfile).isNotNull(); | ||
|
||
assertEquals(firstCaseworkerId, caseWorkerProfile.getCaseWorkerId()); | ||
assertEquals(staffProfileCreationRequest.getFirstName(), caseWorkerProfile.getFirstName()); | ||
assertEquals(staffProfileCreationRequest.getLastName(), caseWorkerProfile.getLastName()); | ||
assertEquals(staffProfileCreationRequest.getEmailId(), caseWorkerProfile.getEmailId()); | ||
assertEquals(staffProfileCreationRequest.isStaffAdmin(), caseWorkerProfile.isStaffAdmin()); | ||
assertEquals(staffProfileCreationRequest.getBaseLocations().size(), | ||
caseWorkerProfile.getBaseLocations().size()); | ||
assertEquals(staffProfileCreationRequest.getBaseLocations().get(0).getLocation(), | ||
caseWorkerProfile.getBaseLocations().get(0).getLocationName()); | ||
assertEquals(staffProfileCreationRequest.getServices().size(), caseWorkerProfile.getServices().size()); | ||
assertEquals(staffProfileCreationRequest.getServices().get(0).getService(), | ||
caseWorkerProfile.getServices().get(0).getService()); | ||
assertEquals(staffProfileCreationRequest.getRoles().size(), caseWorkerProfile.getRoles().size()); | ||
assertEquals(staffProfileCreationRequest.getRoles().get(0).getRole(), | ||
caseWorkerProfile.getRoles().get(0).getRoleName()); | ||
assertThat(caseWorkerProfile.getSkills().size()).isGreaterThanOrEqualTo(1); | ||
assertEquals(staffProfileCreationRequest.getSkills().get(0).getSkillId(), | ||
caseWorkerProfile.getSkills().get(0).getSkillId()); | ||
assertEquals(staffProfileCreationRequest.getSkills().get(0).getDescription(), | ||
caseWorkerProfile.getSkills().get(0).getDescription()); | ||
} | ||
} |
135 changes: 135 additions & 0 deletions
135
...ntegrationTest/java/uk/gov/hmcts/reform/cwrdapi/FetchStaffProfileByIdIntegrationTest.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,135 @@ | ||
package uk.gov.hmcts.reform.cwrdapi; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.HttpStatus; | ||
import org.testcontainers.shaded.com.google.common.collect.ImmutableList; | ||
import org.testcontainers.shaded.com.google.common.collect.ImmutableSet; | ||
import uk.gov.hmcts.reform.cwrdapi.controllers.advice.ErrorResponse; | ||
import uk.gov.hmcts.reform.cwrdapi.controllers.request.CaseWorkerLocationRequest; | ||
import uk.gov.hmcts.reform.cwrdapi.controllers.request.CaseWorkerRoleRequest; | ||
import uk.gov.hmcts.reform.cwrdapi.controllers.request.CaseWorkerWorkAreaRequest; | ||
import uk.gov.hmcts.reform.cwrdapi.controllers.request.CaseWorkersProfileCreationRequest; | ||
import uk.gov.hmcts.reform.cwrdapi.controllers.response.SearchStaffUserByIdResponse; | ||
import uk.gov.hmcts.reform.cwrdapi.util.AuthorizationEnabledIntegrationTest; | ||
import uk.gov.hmcts.reform.cwrdapi.util.CaseWorkerConstants; | ||
import uk.gov.hmcts.reform.cwrdapi.util.CaseWorkerReferenceDataClient; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import static org.apache.logging.log4j.util.Strings.EMPTY; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static uk.gov.hmcts.reform.cwrdapi.CreateStaffReferenceProfileBasicSearchTest.ROLE_CWD_ADMIN; | ||
import static uk.gov.hmcts.reform.cwrdapi.UpdateStaffReferenceProfileTest.ROLE_STAFF_ADMIN; | ||
|
||
public class FetchStaffProfileByIdIntegrationTest extends AuthorizationEnabledIntegrationTest { | ||
|
||
List<CaseWorkersProfileCreationRequest> caseWorkersProfileCreationRequests; | ||
|
||
|
||
@BeforeEach | ||
public void setUpClient() { | ||
super.setUpClient(); | ||
Set<String> roles = ImmutableSet.of(" tribunal_case_worker "); | ||
List<CaseWorkerRoleRequest> caseWorkerRoleRequests = | ||
ImmutableList.of(CaseWorkerRoleRequest.caseWorkerRoleRequest().role(" role ").isPrimaryFlag(true) | ||
.build()); | ||
|
||
List<CaseWorkerLocationRequest> caseWorkerLocationRequests = ImmutableList.of(CaseWorkerLocationRequest | ||
.caseWorkersLocationRequest() | ||
.isPrimaryFlag(true).locationId(1) | ||
.location(" location ").build()); | ||
|
||
List<CaseWorkerWorkAreaRequest> caseWorkerAreaRequests = ImmutableList.of(CaseWorkerWorkAreaRequest | ||
.caseWorkerWorkAreaRequest() | ||
.areaOfWork(" areaOfWork ").serviceCode(" serviceCode ") | ||
.build()); | ||
|
||
caseWorkersProfileCreationRequests = ImmutableList.of(CaseWorkersProfileCreationRequest | ||
.caseWorkersProfileCreationRequest() | ||
.firstName(" firstName ") | ||
.lastName(" lastName ") | ||
.emailId("[email protected]") | ||
.regionId(1).userType("CTSC") | ||
.region("region") | ||
.suspended(false) | ||
.taskSupervisor(true) | ||
.caseAllocator(false) | ||
.roles(caseWorkerRoleRequests) | ||
.idamRoles(roles) | ||
.baseLocations(caseWorkerLocationRequests) | ||
.workerWorkAreaRequests(caseWorkerAreaRequests) | ||
.build()); | ||
} | ||
|
||
@BeforeAll | ||
public static void setup() { | ||
CaseWorkerReferenceDataClient.setBearerToken(EMPTY); | ||
} | ||
|
||
@AfterAll | ||
public static void tearDown() { | ||
CaseWorkerReferenceDataClient.setBearerToken(EMPTY); | ||
} | ||
|
||
@Test | ||
void should_return_status_code_404_when_profile_not_found_in_cw() throws JsonProcessingException { | ||
String searchString = "?id=123"; | ||
String path = "/profile/search-by-id"; | ||
|
||
Map<String, Object> response = (Map<String, Object>) caseworkerReferenceDataClient | ||
.fetchStaffUserById(SearchStaffUserByIdResponse.class, path + searchString, ROLE_STAFF_ADMIN); | ||
assertThat(response).containsEntry("http_status", HttpStatus.NOT_FOUND); | ||
assertThat(((ErrorResponse)response.get("response_body")).getErrorDescription()) | ||
.contains(CaseWorkerConstants.NO_DATA_FOUND); | ||
} | ||
|
||
|
||
@Test | ||
void should_return_status_code_404_when_profile_not_found_in_up() throws JsonProcessingException { | ||
caseworkerReferenceDataClient.setBearerToken(EMPTY); | ||
Map<String, Object> createResponse = caseworkerReferenceDataClient | ||
.createCaseWorkerProfile(caseWorkersProfileCreationRequests, ROLE_CWD_ADMIN); | ||
assertThat(createResponse).containsEntry("http_status", "201 CREATED"); | ||
String caseWorkerId = ((List)((Map)createResponse.get("body")).get("case_worker_ids")).get(0).toString(); | ||
Assertions.assertNotNull(caseWorkerId); | ||
|
||
String path = "/profile/search-by-id"; | ||
String searchString = "?id=" + caseWorkerId; | ||
caseworkerReferenceDataClient.setBearerToken(null); | ||
userProfileGetUserByIdWireMock(caseWorkerId, 404); | ||
Map<String, Object> getResponse = (Map<String, Object>) caseworkerReferenceDataClient | ||
.fetchStaffUserById(SearchStaffUserByIdResponse.class, path + searchString, ROLE_STAFF_ADMIN); | ||
assertThat(getResponse).containsEntry("http_status", HttpStatus.NOT_FOUND); | ||
assertThat(((ErrorResponse)getResponse.get("response_body")).getErrorDescription()) | ||
.contains(CaseWorkerConstants.NO_DATA_FOUND); | ||
} | ||
|
||
@Test | ||
void should_return_status_code_200_when_profile_found() throws JsonProcessingException { | ||
Map<String, Object> createResponse = caseworkerReferenceDataClient | ||
.createCaseWorkerProfile(caseWorkersProfileCreationRequests, ROLE_CWD_ADMIN); | ||
assertThat(createResponse).containsEntry("http_status", "201 CREATED"); | ||
String caseWorkerId = ((List)((Map)createResponse.get("body")).get("case_worker_ids")).get(0).toString(); | ||
Assertions.assertNotNull(caseWorkerId); | ||
String path = "/profile/search-by-id"; | ||
String searchString = "?id=" + caseWorkerId; | ||
caseworkerReferenceDataClient.setBearerToken(null); | ||
|
||
userProfileGetUserByIdWireMock(caseWorkerId, 200); | ||
SearchStaffUserByIdResponse getResponse = (SearchStaffUserByIdResponse)caseworkerReferenceDataClient | ||
.fetchStaffUserById(SearchStaffUserByIdResponse.class, path + searchString, ROLE_STAFF_ADMIN); | ||
Assertions.assertNotNull(getResponse); | ||
Assertions.assertEquals(caseWorkerId, getResponse.getCaseWorkerId()); | ||
Assertions.assertNotNull(getResponse.getIdamStatus()); | ||
Assertions.assertEquals("pending", getResponse.getIdamStatus()); | ||
|
||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -166,6 +166,25 @@ public void userProfileGetUserWireMock(String idamStatus, String roles) { | |
+ "}"))); | ||
} | ||
|
||
public void userProfileGetUserByIdWireMock(String idamId, Integer status) { | ||
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\"" | ||
+ " ]" | ||
+ "}"))); | ||
} | ||
|
||
|
||
public void userProfileDeleteUserWireMock() { | ||
userProfileService.stubFor(delete(urlPathMatching("/v1/userprofile/users.*")) | ||
.willReturn(aResponse() | ||
|
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
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
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
Oops, something went wrong.