Search in sources :

Example 1 with AssignedModulesDataBuilder

use of org.motechproject.mots.testbuilder.AssignedModulesDataBuilder in project mots by motech-implementations.

the class ModuleAssignmentServiceTest method setUp.

/**
 * Prepare the test environment.
 */
@Before
public void setUp() {
    user = TestUtils.createNewUserAndAddToSecurityContext();
    existingAssignedModules = new AssignedModulesDataBuilder().withChw(CHW).withModule(MODULE_1).withModule(MODULE_2).build();
    newAssignedModules = new AssignedModulesDataBuilder().withChw(CHW).withModule(MODULE_2).withModule(MODULE_3).build();
    districtAssignmentDto = new DistrictAssignmentDtoDataBuilder().withModule(MODULE_2.getId().toString()).withModule(MODULE_3.getId().toString()).withDistrictId(DISTRICT.getId().toString()).build();
    when(assignedModulesRepository.findByHealthWorkerId(eq(CHW.getId()))).thenReturn(Optional.of(existingAssignedModules));
    when(districtRepository.findOne(eq((DISTRICT.getId())))).thenReturn(DISTRICT);
    mockModuleInModuleRepository(MODULE_2);
    mockModuleInModuleRepository(MODULE_3);
}
Also used : AssignedModulesDataBuilder(org.motechproject.mots.testbuilder.AssignedModulesDataBuilder) DistrictAssignmentDtoDataBuilder(org.motechproject.mots.testbuilder.DistrictAssignmentDtoDataBuilder) Before(org.junit.Before)

Example 2 with AssignedModulesDataBuilder

use of org.motechproject.mots.testbuilder.AssignedModulesDataBuilder in project mots by motech-implementations.

the class ModuleAssignmentServiceTest method assignModulesShouldThrowIfIvrIdIsNotSet.

@Test(expected = ModuleAssignmentException.class)
public void assignModulesShouldThrowIfIvrIdIsNotSet() {
    final CommunityHealthWorker chw = new CommunityHealthWorkerDataBuilder().withIvrId(null).build();
    final AssignedModules assignedModules = new AssignedModulesDataBuilder().withChw(chw).build();
    when(assignedModulesRepository.findByHealthWorkerId(eq(chw.getId()))).thenReturn(Optional.of(assignedModules));
    moduleAssignmentService.assignModules(assignedModules);
}
Also used : AssignedModules(org.motechproject.mots.domain.AssignedModules) AssignedModulesDataBuilder(org.motechproject.mots.testbuilder.AssignedModulesDataBuilder) CommunityHealthWorker(org.motechproject.mots.domain.CommunityHealthWorker) CommunityHealthWorkerDataBuilder(org.motechproject.mots.testbuilder.CommunityHealthWorkerDataBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with AssignedModulesDataBuilder

use of org.motechproject.mots.testbuilder.AssignedModulesDataBuilder in project mots by motech-implementations.

the class ModuleAssignmentServiceTest method assignModulesToDistrictShouldThrowIfIvrIdIsNotSet.

@Test(expected = ModuleAssignmentException.class)
public void assignModulesToDistrictShouldThrowIfIvrIdIsNotSet() {
    CommunityHealthWorker chw = new CommunityHealthWorkerDataBuilder().withIvrId(null).build();
    AssignedModules assignedModules = new AssignedModulesDataBuilder().withChw(chw).build();
    when(communityHealthWorkerRepository.findByCommunityFacilityChiefdomDistrictIdAndSelected(any(), any())).thenReturn(Collections.singletonList(chw));
    when(assignedModulesRepository.findByHealthWorkerId(eq(chw.getId()))).thenReturn(Optional.of(assignedModules));
    moduleAssignmentService.assignModulesToDistrict(districtAssignmentDto);
}
Also used : AssignedModules(org.motechproject.mots.domain.AssignedModules) AssignedModulesDataBuilder(org.motechproject.mots.testbuilder.AssignedModulesDataBuilder) CommunityHealthWorker(org.motechproject.mots.domain.CommunityHealthWorker) CommunityHealthWorkerDataBuilder(org.motechproject.mots.testbuilder.CommunityHealthWorkerDataBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

AssignedModulesDataBuilder (org.motechproject.mots.testbuilder.AssignedModulesDataBuilder)3 Test (org.junit.Test)2 AssignedModules (org.motechproject.mots.domain.AssignedModules)2 CommunityHealthWorker (org.motechproject.mots.domain.CommunityHealthWorker)2 CommunityHealthWorkerDataBuilder (org.motechproject.mots.testbuilder.CommunityHealthWorkerDataBuilder)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Before (org.junit.Before)1 DistrictAssignmentDtoDataBuilder (org.motechproject.mots.testbuilder.DistrictAssignmentDtoDataBuilder)1