Search in sources :

Example 1 with MotechPermission

use of org.motechproject.security.domain.MotechPermission in project motech by motech.

the class MotechPermissionServiceTest method shouldDeletePermissions.

@Test
public void shouldDeletePermissions() {
    MotechPermission permission = mock(MotechPermission.class);
    when(motechPermissionsDataService.findByPermissionName("permName")).thenReturn(permission);
    permissionService.deletePermission("permName");
    verify(motechPermissionsDataService).delete(permission);
}
Also used : MotechPermission(org.motechproject.security.domain.MotechPermission) Test(org.junit.Test)

Example 2 with MotechPermission

use of org.motechproject.security.domain.MotechPermission in project motech by motech.

the class MotechPermissionServiceTest method shouldAddPermissions.

@Test
public void shouldAddPermissions() {
    PermissionDto permissionDto = new PermissionDto("permName", "bundleName");
    permissionService.addPermission(permissionDto);
    ArgumentCaptor<MotechPermission> captor = ArgumentCaptor.forClass(MotechPermission.class);
    verify(motechPermissionsDataService).create(captor.capture());
    assertEquals("permName", captor.getValue().getPermissionName());
    assertEquals("bundleName", captor.getValue().getBundleName());
}
Also used : MotechPermission(org.motechproject.security.domain.MotechPermission) PermissionDto(org.motechproject.security.model.PermissionDto) Test(org.junit.Test)

Example 3 with MotechPermission

use of org.motechproject.security.domain.MotechPermission in project motech by motech.

the class MotechPermissionServiceTest method shouldRefreshUserContextWhenPermissionIsDeleted.

@Test
public void shouldRefreshUserContextWhenPermissionIsDeleted() {
    MotechPermission permission = mock(MotechPermission.class);
    when(motechPermissionsDataService.findByPermissionName("permName")).thenReturn(permission);
    permissionService.deletePermission("permName");
    verify(userContextsService).refreshAllUsersContextIfActive();
}
Also used : MotechPermission(org.motechproject.security.domain.MotechPermission) Test(org.junit.Test)

Example 4 with MotechPermission

use of org.motechproject.security.domain.MotechPermission in project motech by motech.

the class MotechPermissionServiceBundleIT method shouldNotCreateNewPermissionIfPermissionAlreadyExists.

@Test
public void shouldNotCreateNewPermissionIfPermissionAlreadyExists() {
    final String permissionName = "samePersmission";
    permissionService.addPermission(new PermissionDto(new MotechPermission(permissionName, "test1")));
    permissionService.addPermission(new PermissionDto(new MotechPermission(permissionName, "test2")));
    PermissionDto motechPermission = permissionService.findPermissionByName(permissionName);
    List<MotechPermission> allPermission = permissionsDataService.retrieveAll();
    int numberOfPermissionWithSameName = 0;
    for (MotechPermission permission : allPermission) {
        if (permissionName.equalsIgnoreCase(permission.getPermissionName())) {
            ++numberOfPermissionWithSameName;
        }
    }
    assertEquals(1, numberOfPermissionWithSameName);
    assertEquals("test1", motechPermission.getBundleName());
}
Also used : MotechPermission(org.motechproject.security.domain.MotechPermission) PermissionDto(org.motechproject.security.model.PermissionDto) Test(org.junit.Test)

Example 5 with MotechPermission

use of org.motechproject.security.domain.MotechPermission in project motech by motech.

the class MotechPermissionServiceBundleIT method shouldFindByPermissionName.

@Test
public void shouldFindByPermissionName() {
    permissionsDataService.create(new MotechPermission("testPermission", "testBundle"));
    PermissionDto testPermission = permissionService.findPermissionByName("testPermission");
    assertEquals("testPermission", testPermission.getPermissionName());
}
Also used : MotechPermission(org.motechproject.security.domain.MotechPermission) PermissionDto(org.motechproject.security.model.PermissionDto) Test(org.junit.Test)

Aggregations

MotechPermission (org.motechproject.security.domain.MotechPermission)10 Test (org.junit.Test)7 PermissionDto (org.motechproject.security.model.PermissionDto)4 Transactional (org.springframework.transaction.annotation.Transactional)2 LinkedList (java.util.LinkedList)1 PostConstruct (javax.annotation.PostConstruct)1 RoleDto (org.motechproject.security.model.RoleDto)1