use of org.motechproject.mots.dto.DistrictAssignmentDto in project mots by motech-implementations.
the class DistrictAssignmentDtoDataBuilder method build.
/**
* Builds instance of {@link DistrictAssignmentDto} without id.
*/
public DistrictAssignmentDto build() {
DistrictAssignmentDto districtAssignmentDto = new DistrictAssignmentDto();
districtAssignmentDto.setDistrictId(districtId);
districtAssignmentDto.setModules(modules);
districtAssignmentDto.setStartDate(startDate);
districtAssignmentDto.setEndDate(endDate);
return districtAssignmentDto;
}
use of org.motechproject.mots.dto.DistrictAssignmentDto in project mots by motech-implementations.
the class ModuleAssignmentServiceTest method shouldAssignModulesToDistrict.
@Test
public void shouldAssignModulesToDistrict() throws Exception {
when(userService.getUserByUserName(eq(user.getUsername()))).thenReturn(user);
when(communityHealthWorkerRepository.findByCommunityFacilityChiefdomDistrictIdAndSelected(any(), any())).thenReturn(Collections.singletonList(CHW));
moduleAssignmentService.assignModulesToDistrict(districtAssignmentDto);
ArgumentCaptor<DistrictAssignmentLog> districtAssignmentLogCaptor = ArgumentCaptor.forClass(DistrictAssignmentLog.class);
verify(districtAssignmentLogRepository, times(2)).save(districtAssignmentLogCaptor.capture());
List<DistrictAssignmentLog> districtAssignmentLogs = districtAssignmentLogCaptor.getAllValues();
final Set<Module> passedModules = new HashSet<>(Arrays.asList(MODULE_2, MODULE_3));
assertTrue(districtAssignmentLogs.stream().allMatch(l -> passedModules.contains(l.getModule())));
for (DistrictAssignmentLog log : districtAssignmentLogs) {
assertEquals(DISTRICT, log.getDistrict());
assertEquals(districtAssignmentDto.getStartDate(), log.getStartDate().toString());
assertEquals(districtAssignmentDto.getEndDate(), log.getEndDate().toString());
assertEquals(user, log.getOwner());
}
ArgumentCaptor<AssignedModules> assignedModulesCaptor = ArgumentCaptor.forClass(AssignedModules.class);
verify(assignedModulesRepository).save(assignedModulesCaptor.capture());
final Set<Module> allModules = new HashSet<>(Arrays.asList(MODULE_1, MODULE_2, MODULE_3));
assertEquals(allModules, assignedModulesCaptor.getValue().getModules());
verify(ivrService).addSubscriberToGroups(eq(CHW.getIvrId()), eq(Collections.singletonList(IVR_GROUP)));
verify(moduleProgressService).createModuleProgresses(any(), eq(Collections.singleton(MODULE_3)));
}
use of org.motechproject.mots.dto.DistrictAssignmentDto in project mots by motech-implementations.
the class ModuleAssignmentServiceTest method shouldThrowIfModulesWithDoesNotExists.
@Test(expected = EntityNotFoundException.class)
public void shouldThrowIfModulesWithDoesNotExists() {
UUID moduleId = UUID.randomUUID();
DistrictAssignmentDto customDistrictAssignmentDto = new DistrictAssignmentDtoDataBuilder().withModule(moduleId.toString()).withDistrictId(DISTRICT.getId().toString()).build();
when(moduleRepository.findById(moduleId)).thenReturn(Optional.empty());
moduleAssignmentService.assignModulesToDistrict(customDistrictAssignmentDto);
}
Aggregations