use of org.motechproject.security.model.RoleDto in project motech by motech.
the class RolesBundleIT method testThatRoleThatAllowsRoleManagementIsPresent.
@Test
public void testThatRoleThatAllowsRoleManagementIsPresent() throws InterruptedException {
RoleDto role = roleService.getRole(MOTECH_ADMIN);
assertNotNull(role);
assertTrue(role.getPermissionNames().contains(PermissionNames.MANAGE_ROLE_AND_PERMISSION_PERMISSION));
}
use of org.motechproject.security.model.RoleDto in project motech by motech.
the class AuthoritiesServiceImplTest method shouldRetrieveAuthorities.
@Test
public void shouldRetrieveAuthorities() {
MotechUser user = mock(MotechUser.class);
RoleDto role = mock(RoleDto.class);
List<String> roles = Arrays.asList("role1");
when(user.getRoles()).thenReturn(roles);
when(motechRoleService.getRole("role1")).thenReturn(role);
List<String> permissions = Arrays.asList("permission1");
when(role.getPermissionNames()).thenReturn(permissions);
List<GrantedAuthority> authorities = authoritiesService.authoritiesFor(user);
assertThat(authorities.size(), Is.is(1));
assertThat(authorities.get(0).getAuthority(), Is.is("permission1"));
}
use of org.motechproject.security.model.RoleDto in project motech by motech.
the class MotechRoleServiceTest method shouldRefreshUserContextWhenRoleIsDeleted.
@Test
public void shouldRefreshUserContextWhenRoleIsDeleted() {
RoleDto role = new RoleDto("role1", asList("permission1"));
MotechRole motechRole = mock(MotechRole.class);
when(motechRole.isDeletable()).thenReturn(true);
when(rolesDataService.findByRoleName("role1")).thenReturn(motechRole);
motechRoleService.deleteRole(role);
verify(userContextsService).refreshAllUsersContextIfActive();
}
use of org.motechproject.security.model.RoleDto in project motech by motech.
the class MotechRoleServiceTest method shouldRefreshUserContextWhenRoleIsUpdated.
@Test
public void shouldRefreshUserContextWhenRoleIsUpdated() {
RoleDto role = new RoleDto("role1", asList("permission1"));
MotechRole motechRole = mock(MotechRole.class);
when(rolesDataService.findByRoleName("role1")).thenReturn(motechRole);
motechRoleService.updateRole(role);
verify(userContextsService).refreshAllUsersContextIfActive();
}
use of org.motechproject.security.model.RoleDto in project motech by motech.
the class MotechRoleServiceBundleIT method shouldNotCreateNewRoleIfRoleOfTheSameNameAlreadyExists.
@Test
public void shouldNotCreateNewRoleIfRoleOfTheSameNameAlreadyExists() {
String roleName = "sameRole";
motechRoleService.createRole(new RoleDto(roleName, asList("per1", "per2"), false));
motechRoleService.createRole(new RoleDto(roleName, asList("per3", "per4"), false));
MotechRole motechRole = rolesDataService.findByRoleName(roleName);
List<MotechRole> allRoles = rolesDataService.retrieveAll();
int numberOfRoles = 0;
for (MotechRole role : allRoles) {
if (roleName.equalsIgnoreCase(role.getRoleName())) {
++numberOfRoles;
}
}
assertEquals(1, numberOfRoles);
assertEquals("per1", motechRole.getPermissionNames().get(0));
assertEquals("per2", motechRole.getPermissionNames().get(1));
}
Aggregations