use of org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService in project pentaho-platform by pentaho.
the class UserRoleDaoResourceTest method testCreateUserUnauthorizedException.
@Test
public void testCreateUserUnauthorizedException() throws Exception {
UserRoleDaoService mockService = mock(UserRoleDaoService.class);
doThrow(new SecurityException()).when(mockService).createUser(any(User.class));
UserRoleDaoResource resource = new UserRoleDaoResource(roleBindingDao, tenantManager, systemRoles, adminRole, mockService);
try {
resource.createUser(new User("not", "admin"));
} catch (WebApplicationException e) {
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), e.getResponse().getStatus());
}
}
use of org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService in project pentaho-platform by pentaho.
the class UserRoleDaoResourceTest method testCreateRoleEmptyName.
@Test
public void testCreateRoleEmptyName() throws Exception {
UserRoleDaoService mockService = mock(UserRoleDaoService.class);
doThrow(new UserRoleDaoService.ValidationFailedException()).when(mockService).createRole(anyString());
UserRoleDaoResource resource = new UserRoleDaoResource(roleBindingDao, tenantManager, systemRoles, adminRole, mockService);
try {
resource.createRole("");
} catch (WebApplicationException e) {
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), e.getResponse().getStatus());
}
}
use of org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService in project pentaho-platform by pentaho.
the class UserRoleDaoResourceTest method testCreateUserValidationFailed.
@Test
public void testCreateUserValidationFailed() throws Exception {
UserRoleDaoService mockService = mock(UserRoleDaoService.class);
doThrow(new UserRoleDaoService.ValidationFailedException()).when(mockService).createUser(any(User.class));
UserRoleDaoResource resource = new UserRoleDaoResource(roleBindingDao, tenantManager, systemRoles, adminRole, mockService);
try {
resource.createUser(new User("\\/validation", "failed"));
} catch (WebApplicationException e) {
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), e.getResponse().getStatus());
}
}
use of org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService in project pentaho-platform by pentaho.
the class UserRoleDaoResource_RolesUpdatedTest method setUp.
@Before
public void setUp() {
UserRoleDaoService service = mock(UserRoleDaoService.class);
doReturn(new RoleListWrapper(allRoles)).when(service).getRolesForUser(eq(SESSION_USER_NAME));
resource = new UserRoleDaoResource(mock(IRoleAuthorizationPolicyRoleBindingDao.class), mock(ITenantManager.class), new ArrayList<String>(), ROLE_NAME_ADMINISTRATOR, service);
session = new StandaloneSession(SESSION_USER_NAME);
resource = spy(resource);
doReturn(session).when(resource).getSession();
userRoleDao = mock(IUserRoleDao.class);
doReturn(new ArrayList<IPentahoRole>()).when(userRoleDao).getRoles(any(ITenant.class));
doReturn(mock(ITenant.class)).when(resource).getTenant(anyString());
doReturn(userRoleDao).when(resource).getUserRoleDao();
doReturn(true).when(resource).canAdminister();
}
use of org.pentaho.platform.web.http.api.resources.services.UserRoleDaoService in project pentaho-platform by pentaho.
the class UserRoleDaoResourceTest method changePassException.
private void changePassException(Exception ex, int expectedStatus, String name, String newPass, String oldPass) throws Exception {
UserRoleDaoService mockService = mock(UserRoleDaoService.class);
doThrow(ex).when(mockService).changeUserPassword(anyString(), anyString(), anyString());
UserRoleDaoResource resource = new UserRoleDaoResource(roleBindingDao, tenantManager, systemRoles, adminRole, mockService);
try {
resource.changeUserPassword(new ChangePasswordUser(name, newPass, oldPass));
} catch (WebApplicationException exception) {
assertEquals(expectedStatus, exception.getResponse().getStatus());
}
}
Aggregations