Skip to content

Commit

Permalink
Increase Mutation coverage for Staff Reference Data (#741)
Browse files Browse the repository at this point in the history
* rd caseworker mutation upgrade
  • Loading branch information
arshinsalim authored Jun 22, 2023
1 parent b07cd94 commit aa4fe8d
Show file tree
Hide file tree
Showing 13 changed files with 391 additions and 9 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ dependencies {
testImplementation 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.7.0'
testImplementation 'org.codehaus.sonar-plugins:sonar-pitest-plugin:0.5'


testImplementation 'io.github.openfeign:feign-jackson:12.1'
testImplementation group: 'com.github.mifmif', name: 'generex', version: '1.0.2'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void addInterceptors(InterceptorRegistry registry) {

//Launch Darkly Feature Toggle
registry.addInterceptor(featureConditionEvaluation)
.addPathPatterns("/refdata/case-worker/users/fetchUsersById",
.addPathPatterns("/refdata/case-worker",
"/refdata/case-worker/idam-roles-mapping",
"/refdata/case-worker/users",
"/refdata/case-worker/users/sync",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -14,19 +17,26 @@ void testLocation() {
AttributeResponse attributeResponse = new AttributeResponse();
attributeResponse.setIdamMessage("OK");
attributeResponse.setIdamStatusCode(200);

RoleDeletionResponse roleDeletionResponse = new RoleDeletionResponse();
roleDeletionResponse.setRoleName("role");
roleDeletionResponse.setIdamMessage("message");
roleDeletionResponse.setIdamStatusCode("OK");
RoleAdditionResponse roleAdditionResponse = new RoleAdditionResponse();
roleAdditionResponse.setIdamMessage("OK");
roleAdditionResponse.setIdamStatusCode("200");

List<RoleDeletionResponse> roleDeletionResponses = new ArrayList<>();
roleDeletionResponses.add(roleDeletionResponse);
UserProfileRolesResponse userProfileRolesResponse = new UserProfileRolesResponse();
userProfileRolesResponse.setAttributeResponse(attributeResponse);
userProfileRolesResponse.setRoleAdditionResponse(roleAdditionResponse);
userProfileRolesResponse.setRoleDeletionResponse(roleDeletionResponses);

assertNotNull(userProfileRolesResponse);
assertFalse(attributeResponse.getIdamMessage().isEmpty());
assertThat(userProfileRolesResponse.getAttributeResponse(), is(attributeResponse));
assertThat(userProfileRolesResponse.getRoleAdditionResponse(), is(roleAdditionResponse));
assertThat(userProfileRolesResponse.getRoleDeletionResponse(), is(roleDeletionResponses));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ void testCaseWorkerSkill() {
caseWorkerSkill.setCreatedDate(LocalDateTime.now());
caseWorkerSkill.setLastUpdate(LocalDateTime.now());
caseWorkerSkill.setCaseWorkerProfile(new CaseWorkerProfile());
caseWorkerSkill.setCaseWorkerSkill(new CaseWorkerSkill());


assertNotNull(caseWorkerSkill);
assertNotNull(caseWorkerSkill.getSkill());
assertNotNull(caseWorkerSkill.getCaseWorkerProfile());
assertNotNull(caseWorkerSkill.getCreatedDate());
assertNotNull(caseWorkerSkill.getLastUpdate());
assertNotNull(caseWorkerSkill.getCaseWorkerSkill());

assertThat(caseWorkerSkill.getCaseWorkerId(), is("case_worker_id"));
assertThat(caseWorkerSkill.getSkillId(), is(1L));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package uk.gov.hmcts.reform.cwrdapi.domain;

import org.junit.jupiter.api.Test;
import uk.gov.hmcts.reform.cwrdapi.client.domain.RoleDeletionResponse;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.junit.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class RoleDeletionResponseTest {

@Test
void testSkillResposne_for_valid_data() {

RoleDeletionResponse roleDeletionResponse = new RoleDeletionResponse();

roleDeletionResponse.setRoleName("role");
roleDeletionResponse.setIdamStatusCode("active");
roleDeletionResponse.setIdamMessage("message");

assertNotNull(roleDeletionResponse);
assertThat(roleDeletionResponse.getRoleName(),is("role"));
assertThat(roleDeletionResponse.getIdamMessage(), is("message"));
assertThat(roleDeletionResponse.getIdamStatusCode(), is("active"));

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package uk.gov.hmcts.reform.cwrdapi.domain;

import org.junit.jupiter.api.Test;
import uk.gov.hmcts.reform.cwrdapi.client.domain.ServiceResponse;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class ServiceResponseTest {

@Test
void testSkillResposne_for_tostring_builder() {

ServiceResponse serviceResponse = ServiceResponse.builder()
.service("testservice")
.serviceCode("testServiceCode")
.build();

assertNotNull(serviceResponse);
assertEquals("testservice",serviceResponse.getService());
assertEquals("testServiceCode",serviceResponse.getServiceCode());


String description = ServiceResponse.builder()
.serviceCode("testServiceCode").toString();


assertTrue(description
.contains("ServiceResponse.ServiceResponseBuilder(service=null, serviceCode=testServiceCode)"));

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package uk.gov.hmcts.reform.cwrdapi.domain;

import org.junit.jupiter.api.Test;
import uk.gov.hmcts.reform.cwrdapi.client.domain.SkillResponse;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.junit.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class SkillResponseTest {


@Test
void testSkillResposne_for_valid_data() {

SkillResponse skillResponse = new SkillResponse();
skillResponse.setSkillId(123L);
skillResponse.setDescription("testresponsedescription");

assertNotNull(skillResponse);
assertThat(skillResponse.getSkillId(),is(123L));
assertThat(skillResponse.getDescription(), is("testresponsedescription"));

}

@Test
void testSkillResposne_for_empty_data() {

SkillResponse skillResponse = new SkillResponse();
skillResponse.setSkillId(123L);
skillResponse.setDescription(" ");

assertNotNull(skillResponse);
assertThat(skillResponse.getSkillId(),is(123L));
assertThat(skillResponse.getDescription(), is(" "));

}


@Test
void testSkillResposne_for_tostring_builder() {

SkillResponse skillResponse = SkillResponse.builder()
.skillId(123L)
.description("testresponsedescription")
.build();

assertNotNull(skillResponse);
assertEquals(123L, skillResponse.getSkillId());
assertEquals("testresponsedescription", skillResponse.getDescription());


String description = SkillResponse.builder().description("test").toString();

assertTrue(description.contains("SkillResponse.SkillResponseBuilder(skillId=null, description=test)"));

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,22 @@ void test_should_add_roles_add_when_modified() {
void testUserProfileUpdatedDataBuilder() {
Set<RoleName> rolesAdd = new HashSet<>();
rolesAdd.add(new RoleName("Role Name"));
Set<RoleName> rolesDel = new HashSet<>();
rolesDel.add(new RoleName("Role Name"));

UserProfileUpdatedData userProfileUpdatedData = UserProfileUpdatedData.builder()
.idamStatus("ACTIVE")
.firstName("firstName")
.lastName("lastName")
.rolesAdd(rolesAdd)
.rolesDelete(rolesDel)
.build();

assertThat(userProfileUpdatedData.getIdamStatus()).isEqualTo("ACTIVE");
assertThat(userProfileUpdatedData.getFirstName()).isEqualTo("firstName");
assertThat(userProfileUpdatedData.getLastName()).isEqualTo("lastName");
assertThat(userProfileUpdatedData.getRolesAdd()).isNotEmpty();
assertThat(userProfileUpdatedData.getRolesDelete()).isNotEmpty();

String userProfileUpdatedDataString = UserProfileUpdatedData.builder().idamStatus("ACTIVE").toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.util.ResourceUtils.getFile;
Expand Down Expand Up @@ -98,6 +99,7 @@ void shouldProcessCaseWorkerFileWithPartialSuccess() throws IOException {
ImmutableList.of(ExceptionCaseWorker.builder().errorDescription("Up Failed").excelRowId("1").build());
when(exceptionCaseWorkerRepository.findByJobId(anyLong())).thenReturn(exceptionCaseWorkers);
ResponseEntity<Object> responseEntity = caseWorkerServiceFacade.processFile(multipartFile);
verify(validationServiceFacadeImpl,times(1)).saveJsrExceptionsForCaseworkerJob(anyLong());
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
}

Expand Down Expand Up @@ -233,12 +235,49 @@ void shouldProcessCaseWorkerFileWithSuspendedRowFailed() throws IOException {
when(validationServiceFacadeImpl.getInvalidRecords(anyList())).thenReturn(Collections.emptyList());
when(caseWorkerProfileConverter.getSuspendedRowIds()).thenReturn(List.of(1L));
ResponseEntity<Object> responseEntity = caseWorkerServiceFacade.processFile(multipartFile);
verify(caseWorkerInternalApiClient,times(1)).postRequest(any(),anyString());
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
ObjectMapper mapper = new ObjectMapper();
String responseString = mapper.writeValueAsString(responseEntity.getBody());
assertTrue(responseString.contains("1 record(s) failed validation and 1 record(s) uploaded"));
}

@Test
void shouldProcessCaseWorkerFileWithDuplicateEmail() throws IOException {
CaseWorkerProfile caseWorkerProfile1 = CaseWorkerProfile.builder()
.firstName("test").lastName("test")
.officialEmail("[email protected]")
.regionId(1)
.regionName("test")
.userType("testUser")
.build();

CaseWorkerProfile caseWorkerProfile2 = CaseWorkerProfile.builder()
.firstName("test1").lastName("test1")
.officialEmail("[email protected]")
.regionId(1)
.regionName("test1")
.userType("testUser")
.build();
List<CaseWorkerProfile> caseWorkerProfiles = new ArrayList<>();

caseWorkerProfiles.add(caseWorkerProfile1);
caseWorkerProfiles.add(caseWorkerProfile2);
MultipartFile multipartFile = createCaseWorkerMultiPartFile("Staff Data Upload.xls");

List<ExceptionCaseWorker> exceptionCaseWorkers =
ImmutableList.of(ExceptionCaseWorker.builder().errorDescription("Up Failed").excelRowId("1").build());
when(exceptionCaseWorkerRepository.findByJobId(anyLong())).thenReturn(exceptionCaseWorkers);
when(excelAdaptorService
.parseExcel(workbook, CaseWorkerProfile.class))
.thenReturn(caseWorkerProfiles);
when(validationServiceFacadeImpl.getInvalidRecords(anyList())).thenReturn(Collections.emptyList());
when(caseWorkerProfileConverter.getSuspendedRowIds()).thenReturn(List.of(1L));
ResponseEntity<Object> responseEntity = caseWorkerServiceFacade.processFile(multipartFile);
verify(validationServiceFacadeImpl,times(2)).logFailures(anyString(),anyLong());
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
}

@Test
void shouldProcessCaseWorkerFileWithUploadedAndSuspendedMessage() throws IOException {
CaseWorkerProfile caseWorkerProfile1 = CaseWorkerProfile.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ void testValidateStaffProfileMissingServices() {
InvalidRequestException lastNameException = Assertions.assertThrows(InvalidRequestException.class, () ->
jsrValidatorStaffProfile.validateStaffProfile(profile, STAFF_PROFILE_CREATE));
Assertions.assertNotNull(lastNameException.getLocalizedMessage());
verify(staffProfileAuditService,times(1)).saveStaffAudit(any(),any(),any(),any(),any());
assertThat(lastNameException.getMessage()).contains(MISSING_REGION_PROFILE);
}

Expand Down
Loading

0 comments on commit aa4fe8d

Please sign in to comment.