Search in sources :

Example 1 with AssignedModules

use of org.motechproject.mots.domain.AssignedModules 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 2 with AssignedModules

use of org.motechproject.mots.domain.AssignedModules in project mots by motech-implementations.

the class AssignedModulesDataBuilder method buildAsNew.

/**
 * Builds instance of {@link AssignedModules} without id.
 */
public AssignedModules buildAsNew() {
    AssignedModules assignedModules = new AssignedModules();
    assignedModules.setHealthWorker(chw);
    assignedModules.setModules(modules);
    return assignedModules;
}
Also used : AssignedModules(org.motechproject.mots.domain.AssignedModules)

Example 3 with AssignedModules

use of org.motechproject.mots.domain.AssignedModules in project mots by motech-implementations.

the class AssignedModulesDataBuilder method build.

/**
 * Builds instance of {@link AssignedModules}.
 */
public AssignedModules build() {
    AssignedModules assignedModules = buildAsNew();
    assignedModules.setId(id);
    return assignedModules;
}
Also used : AssignedModules(org.motechproject.mots.domain.AssignedModules)

Example 4 with AssignedModules

use of org.motechproject.mots.domain.AssignedModules in project mots by motech-implementations.

the class ModuleAssignmentController method assignModules.

/**
 * Assign modules for CHW.
 * @param moduleAssignmentDto dto with chw id and list of modules assigned to it
 */
@RequestMapping(value = "/module/assign", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
public void assignModules(@RequestBody ModuleAssignmentDto moduleAssignmentDto) {
    AssignedModules assignedModules = moduleAssignmentMapper.fromDto(moduleAssignmentDto);
    moduleAssignmentService.assignModules(assignedModules);
}
Also used : AssignedModules(org.motechproject.mots.domain.AssignedModules) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with AssignedModules

use of org.motechproject.mots.domain.AssignedModules in project mots by motech-implementations.

the class ModuleAssignmentServiceTest method shouldReturnAssignedModules.

@Test
public void shouldReturnAssignedModules() {
    AssignedModules actual = moduleAssignmentService.getAssignedModules(CHW.getId());
    assertEquals(existingAssignedModules, actual);
}
Also used : AssignedModules(org.motechproject.mots.domain.AssignedModules) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

AssignedModules (org.motechproject.mots.domain.AssignedModules)11 CommunityHealthWorker (org.motechproject.mots.domain.CommunityHealthWorker)5 IvrException (org.motechproject.mots.exception.IvrException)5 Test (org.junit.Test)4 ModuleAssignmentException (org.motechproject.mots.exception.ModuleAssignmentException)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 HashSet (java.util.HashSet)3 Module (org.motechproject.mots.domain.Module)3 AssignedModulesDataBuilder (org.motechproject.mots.testbuilder.AssignedModulesDataBuilder)3 CommunityHealthWorkerDataBuilder (org.motechproject.mots.testbuilder.CommunityHealthWorkerDataBuilder)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 CourseModule (org.motechproject.mots.domain.CourseModule)2 DistrictAssignmentLog (org.motechproject.mots.domain.DistrictAssignmentLog)2 User (org.motechproject.mots.domain.security.User)2 EntityNotFoundException (org.motechproject.mots.exception.EntityNotFoundException)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1