use of org.pentaho.platform.api.engine.IUserRoleListService in project pentaho-platform by pentaho.
the class CachingUserRoleListServiceDecoratorTest method testGetAllRoles.
@Test
public void testGetAllRoles() throws Exception {
IUserRoleListService mockService = mock(IUserRoleListService.class);
when(mockService.getAllRoles()).thenReturn(Arrays.asList("foo", "bar"));
CachingUserRoleListServiceDecorator decorator = new CachingUserRoleListServiceDecorator(mockService);
List<String> allRoles = decorator.getAllRoles();
assertArrayEquals("does not match", new String[] { "foo", "bar" }, allRoles.toArray());
// second call should be from cache
allRoles = decorator.getAllRoles();
assertArrayEquals("does not match", new String[] { "foo", "bar" }, allRoles.toArray());
verify(mockService, times(1)).getAllRoles();
}
use of org.pentaho.platform.api.engine.IUserRoleListService in project pentaho-platform by pentaho.
the class CachingUserRoleListServiceDecoratorTest method testGetRolesForUser.
@Test
public void testGetRolesForUser() throws Exception {
IUserRoleListService mockService = mock(IUserRoleListService.class);
when(mockService.getRolesForUser(tenant, "joe")).thenReturn(Arrays.asList("foo", "bar"));
when(mockService.getRolesForUser(tenant, "admin")).thenReturn(Arrays.asList("foo", "bar"));
CachingUserRoleListServiceDecorator decorator = new CachingUserRoleListServiceDecorator(mockService);
List<String> allRoles = decorator.getRolesForUser(tenant, "joe");
assertArrayEquals("does not match", new String[] { "foo", "bar" }, allRoles.toArray());
// second call should be from cache
allRoles = decorator.getRolesForUser(tenant, "joe");
assertArrayEquals("does not match", new String[] { "foo", "bar" }, allRoles.toArray());
allRoles = decorator.getRolesForUser(tenant, "admin");
assertArrayEquals("does not match", new String[] { "foo", "bar" }, allRoles.toArray());
verify(mockService, times(1)).getRolesForUser(tenant, "joe");
verify(mockService, times(1)).getRolesForUser(tenant, "admin");
}
use of org.pentaho.platform.api.engine.IUserRoleListService in project pentaho-platform by pentaho.
the class CachingUserRoleListServiceDecoratorTest method testGetUsersInRole.
@Test
public void testGetUsersInRole() throws Exception {
IUserRoleListService mockService = mock(IUserRoleListService.class);
when(mockService.getUsersInRole(tenant, "ceo")).thenReturn(Arrays.asList("foo", "bar"));
CachingUserRoleListServiceDecorator decorator = new CachingUserRoleListServiceDecorator(mockService);
List<String> allRoles = decorator.getUsersInRole(tenant, "ceo");
assertArrayEquals("does not match", new String[] { "foo", "bar" }, allRoles.toArray());
// second call should be from cache
allRoles = decorator.getUsersInRole(tenant, "ceo");
assertArrayEquals("does not match", new String[] { "foo", "bar" }, allRoles.toArray());
verify(mockService, times(1)).getUsersInRole(tenant, "ceo");
}
use of org.pentaho.platform.api.engine.IUserRoleListService in project pentaho-platform by pentaho.
the class SystemServiceTest method testGetUsersNoPermission.
@Test
public void testGetUsersNoPermission() throws Exception {
IUserRoleListService service = mock(IUserRoleListService.class);
PentahoSystem.registerObject(service);
doReturn(false).when(systemService).canAdminister();
try {
systemService.getUsers();
fail();
} catch (IllegalAccessException e) {
// expected exception
}
PentahoSystem.clearObjectFactory();
}
use of org.pentaho.platform.api.engine.IUserRoleListService in project pentaho-platform by pentaho.
the class UserRoleListServiceTest method testDoGetAllRoles.
@Test
public void testDoGetAllRoles() {
List<String> roles = new ArrayList<String>();
roles.add("ROLE1");
roles.add("ROLE2");
List<String> extraRoles = new ArrayList<String>();
extraRoles.add("ROLE3");
extraRoles.add("ROLE4");
IUserRoleListService userRoleListService1 = mock(IUserRoleListService.class);
doReturn(userRoleListService1).when(userRoleListService).getUserRoleListService();
doReturn(roles).when(userRoleListService1).getAllRoles();
doReturn(extraRoles).when(userRoleListService).getExtraRoles();
RoleListWrapper roleListWrapper = userRoleListService.getAllRoles();
verify(userRoleListService).getUserRoleListService();
verify(userRoleListService1).getAllRoles();
verify(userRoleListService).getExtraRoles();
assertEquals(4, roleListWrapper.getRoles().size());
}
Aggregations