use of org.motechproject.security.model.RoleDto in project motech by motech.
the class RoleControllerSecurityContextIT method shouldAllowRoleUpdateWithoutException.
@Test
public void shouldAllowRoleUpdateWithoutException() {
login(USER_WITH_PERMISSION_TO_MANAGE_ROLE_AND_PERMISSION);
roleController.updateRole(new RoleDto());
}
use of org.motechproject.security.model.RoleDto in project motech by motech.
the class RoleControllerSecurityContextIT method shouldNotAllowRoleUpdate.
@Test(expected = AccessDeniedException.class)
public void shouldNotAllowRoleUpdate() {
login(USER_WITHOUT_PERMISSION_TO_MANAGE_ROLE_AND_PERMISSION);
roleController.updateRole(new RoleDto("someRole", Collections.<String>emptyList()));
}
use of org.motechproject.security.model.RoleDto in project motech by motech.
the class RoleControllerSecurityContextIT method shouldDenyRoleCreation.
@Test(expected = AccessDeniedException.class)
public void shouldDenyRoleCreation() {
login(USER_WITHOUT_PERMISSION_TO_MANAGE_ROLE_AND_PERMISSION);
roleController.saveRole(new RoleDto());
}
use of org.motechproject.security.model.RoleDto in project motech by motech.
the class SecurityRoleLoaderTest method shouldUpdateExistingRoles.
@Test
public void shouldUpdateExistingRoles() throws IOException {
when(roleService.getRole("Test Role")).thenReturn(new RoleDto("Test Role", Collections.<String>emptyList(), false));
when(applicationContext.getResource("roles.json")).thenReturn(resource);
when(applicationContext.getBean(BundleContext.class)).thenReturn(bundleContext);
when(resource.exists()).thenReturn(true);
try (InputStream in = getClass().getClassLoader().getResourceAsStream("roles.json")) {
when(resource.getInputStream()).thenReturn(new ByteArrayInputStream(IOUtils.toByteArray(in)));
}
securityRoleLoader.loadRoles(applicationContext);
verify(roleService).getRole("Test Role");
ArgumentCaptor<RoleDto> roleCaptor = ArgumentCaptor.forClass(RoleDto.class);
verify(roleService).updateRole(roleCaptor.capture());
assertEquals("Test Role", roleCaptor.getValue().getRoleName());
assertEquals(asList("perm1", "perm2"), roleCaptor.getValue().getPermissionNames());
ArgumentCaptor<PermissionDto> permissionCaptor = ArgumentCaptor.forClass(PermissionDto.class);
verify(permissionService, times(2)).addPermission(permissionCaptor.capture());
verifyPermission("perm1", SYMBOLIC_NAME, permissionCaptor.getAllValues().get(0));
verifyPermission("perm2", SYMBOLIC_NAME, permissionCaptor.getAllValues().get(1));
}
use of org.motechproject.security.model.RoleDto in project motech by motech.
the class RoleControllerTest method shouldGetRoleDetailsGivenItsName.
@Test
public void shouldGetRoleDetailsGivenItsName() throws Exception {
String roleName = "foo";
RoleDto role = new RoleDto(roleName, Arrays.asList("permission1"));
when(roleService.getRole(roleName)).thenReturn(role);
mockMvc.perform(get(String.format("/web-api/roles/role/%s", roleName))).andExpect(status().isOk()).andExpect(content().string("{\"roleName\":\"foo\",\"originalRoleName\":\"foo\",\"permissionNames\":[\"permission1\"],\"deletable\":false}"));
}
Aggregations