use of org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException in project pentaho-platform by pentaho.
the class SolutionImportHandlerTest method testImportRoles_roleAlreadyExists.
@Test
public void testImportRoles_roleAlreadyExists() throws Exception {
String roleName = "ADMIN";
List<String> permissions = new ArrayList<String>();
RoleExport role = new RoleExport();
role.setRolename(roleName);
role.setPermission(permissions);
List<RoleExport> roles = new ArrayList<>();
roles.add(role);
Map<String, List<String>> roleToUserMap = new HashMap<>();
final List<String> adminUsers = new ArrayList<>();
adminUsers.add("admin");
adminUsers.add("root");
roleToUserMap.put(roleName, adminUsers);
String[] userStrings = adminUsers.toArray(new String[] {});
Mockito.when(userRoleDao.createRole(Mockito.any(ITenant.class), Mockito.anyString(), Mockito.anyString(), Mockito.any(userStrings.getClass()))).thenThrow(new AlreadyExistsException("already there"));
importHandler.setOverwriteFile(true);
importHandler.importRoles(roles, roleToUserMap);
Mockito.verify(userRoleDao).createRole(Mockito.any(ITenant.class), Mockito.anyString(), Mockito.anyString(), Mockito.any(userStrings.getClass()));
// even if the roles exists, make sure we set the permissions on it Mockito.anyway... they might have changed
Mockito.verify(roleAuthorizationPolicyRoleBindingDao).setRoleBindings(Mockito.any(ITenant.class), Mockito.eq(roleName), Mockito.eq(permissions));
}
use of org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException in project pentaho-platform by pentaho.
the class UserRoleDaoResourceTest method testCreateUserDuplicate.
@Test
public void testCreateUserDuplicate() throws Exception {
UserRoleDaoService mockService = mock(UserRoleDaoService.class);
doThrow(new AlreadyExistsException("message")).when(mockService).createUser(any(User.class));
UserRoleDaoResource resource = new UserRoleDaoResource(roleBindingDao, tenantManager, systemRoles, adminRole, mockService);
try {
resource.createUser(new User("user", "duplicate"));
} catch (WebApplicationException e) {
assertEquals(Response.Status.PRECONDITION_FAILED.getStatusCode(), e.getResponse().getStatus());
}
}
use of org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException in project pentaho-platform by pentaho.
the class UserRoleWebServiceBase method testCreateDuplicateRole.
@Test
public void testCreateDuplicateRole() throws UserRoleException {
UserRoleDaoMock userRoleDao = Mockito.mock(UserRoleDaoMock.class);
Mockito.doThrow(new AlreadyExistsException("That role already exists.")).when(userRoleDao).createRole(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
UserRoleWebService userRoleWebService = new UserRoleWebService() {
@Override
protected IUserRoleDao getDao() throws UserRoleException {
return userRoleDao;
}
};
ProxyPentahoRole proxyPentahoRole = new ProxyPentahoRole("testrole");
try {
userRoleWebService.createRole(proxyPentahoRole);
Assert.fail();
} catch (AlreadyExistsException e) {
Assert.assertEquals(0, e.getStackTrace().length);
}
}
use of org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException in project pentaho-platform by pentaho.
the class UserRoleWebServiceBase method testCreateDuplicateUser.
@Test
public void testCreateDuplicateUser() throws UserRoleException {
UserRoleDaoMock userRoleDao = Mockito.mock(UserRoleDaoMock.class);
Mockito.doThrow(new AlreadyExistsException("That user name already exists.")).when(userRoleDao).createUser(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any());
UserRoleWebService userRoleWebService = new UserRoleWebService() {
@Override
protected IUserRoleDao getDao() throws UserRoleException {
return userRoleDao;
}
};
ProxyPentahoUser proxyPentahoUser = new ProxyPentahoUser();
proxyPentahoUser.setName("test");
proxyPentahoUser.setEnabled(true);
proxyPentahoUser.setPassword("test");
proxyPentahoUser.setDescription("testing");
try {
userRoleWebService.createUser(proxyPentahoUser);
Assert.fail();
} catch (AlreadyExistsException e) {
Assert.assertEquals(0, e.getStackTrace().length);
}
}
Aggregations