Search in sources :

Example 21 with IUserRoleListService

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();
}
Also used : IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) Test(org.junit.Test)

Example 22 with IUserRoleListService

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");
}
Also used : IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) Test(org.junit.Test)

Example 23 with IUserRoleListService

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");
}
Also used : IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) Test(org.junit.Test)

Example 24 with IUserRoleListService

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();
}
Also used : IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) Test(org.junit.Test)

Example 25 with IUserRoleListService

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());
}
Also used : RoleListWrapper(org.pentaho.platform.web.http.api.resources.RoleListWrapper) ArrayList(java.util.ArrayList) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) Test(org.junit.Test)

Aggregations

IUserRoleListService (org.pentaho.platform.api.engine.IUserRoleListService)34 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)8 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)5 List (java.util.List)4 Document (org.dom4j.Document)4 Element (org.dom4j.Element)4 DefaultElement (org.dom4j.tree.DefaultElement)4 RoleListWrapper (org.pentaho.platform.web.http.api.resources.RoleListWrapper)4 MicroPlatform (org.pentaho.test.platform.engine.core.MicroPlatform)4 File (java.io.File)3 Callable (java.util.concurrent.Callable)3 IPluginResourceLoader (org.pentaho.platform.api.engine.IPluginResourceLoader)3 ITenant (org.pentaho.platform.api.mt.ITenant)3 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 SystemSettings (org.pentaho.platform.engine.core.system.SystemSettings)3 PluginClassLoader (org.pentaho.platform.plugin.services.pluginmgr.PluginClassLoader)3 PluginResourceLoader (org.pentaho.platform.plugin.services.pluginmgr.PluginResourceLoader)3 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2