use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class SchedulerServiceTest method testGetJobInfo.
@Test
public void testGetJobInfo() throws Exception {
String jobId = "jobId";
Job mockJob = mock(Job.class);
doReturn(mockJob).when(schedulerService).getJob(jobId);
ISecurityHelper mockSecurityHelper = mock(ISecurityHelper.class);
doReturn(mockSecurityHelper).when(schedulerService).getSecurityHelper();
IPentahoSession mockPentahoSession = mock(IPentahoSession.class);
doReturn(mockPentahoSession).when(schedulerService).getSession();
String sessionName = "sessionName";
doReturn(sessionName).when(mockPentahoSession).getName();
doReturn(sessionName).when(mockJob).getUserName();
Map<String, Serializable> mockJobParams = mock(Map.class);
doReturn(mockJobParams).when(mockJob).getJobParams();
Set<String> jobParamsKeyset = new HashSet<>();
doReturn(jobParamsKeyset).when(mockJobParams).keySet();
String jobParamKey = "key";
jobParamsKeyset.add(jobParamKey);
String value = "value";
String[] testArray = new String[] { value };
doReturn(testArray).when(mockJobParams).get(jobParamKey);
// Test 1
doReturn(true).when(schedulerService).canAdminister(mockPentahoSession);
Job testJob = schedulerService.getJobInfo(jobId);
assertEquals(mockJob, testJob);
// Test 2
doReturn(false).when(schedulerService).canAdminister(mockPentahoSession);
testJob = schedulerService.getJobInfo(jobId);
assertEquals(mockJob, testJob);
verify(mockJobParams, times(2)).put(eq(jobParamKey), any(Serializable.class));
verify(schedulerService, times(2)).getJob(jobId);
verify(schedulerService, times(2)).getSession();
verify(mockPentahoSession, times(2)).getName();
verify(mockJob, times(2)).getUserName();
verify(mockJob, times(6)).getJobParams();
verify(mockJobParams, times(2)).keySet();
verify(mockJobParams, times(2)).get(jobParamKey);
verify(schedulerService, times(2)).canAdminister(null);
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testAssignRoleToUserNotFoundException.
@Test(expected = NotFoundException.class)
public void testAssignRoleToUserNotFoundException() throws UserRoleListService.UnauthorizedException {
String userName = "testUser";
String roleNames = "Power User\tBusiness User\t";
setupMockSessionUser(SESSION_USER_NAME, true);
// Create session that will generate tenant
IPentahoSession session = mock(IPentahoSession.class);
when(session.getAttribute(IPentahoSession.TENANT_ID_KEY)).thenReturn("testTenantPath");
PentahoSessionHolder.setSession(session);
IUserRoleDao roleDao = mock(IUserRoleDao.class);
when(roleDao.getUserRoles(any(ITenant.class), anyString())).thenThrow(new NotFoundException("expectedTestException"));
PentahoSystem.registerObject(roleDao);
userRoleService.assignRolesToUser(userName, roleNames);
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testAssignRoleToUserUncategorizedUserRoleDaoException.
@Test(expected = UncategorizedUserRoleDaoException.class)
public void testAssignRoleToUserUncategorizedUserRoleDaoException() throws UserRoleListService.UnauthorizedException {
String userName = "testUser";
String roleNames = "Power User\tBusiness User\t";
setupMockSessionUser(SESSION_USER_NAME, true);
// Create session that will generate tenant
IPentahoSession session = mock(IPentahoSession.class);
when(session.getAttribute(IPentahoSession.TENANT_ID_KEY)).thenReturn("testTenantPath");
PentahoSessionHolder.setSession(session);
IUserRoleDao roleDao = mock(IUserRoleDao.class);
when(roleDao.getUserRoles(any(ITenant.class), anyString())).thenThrow(new UncategorizedUserRoleDaoException("expectedTestException"));
PentahoSystem.registerObject(roleDao);
userRoleService.assignRolesToUser(userName, roleNames);
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testRemoveRoleFromUser.
@Test
public void testRemoveRoleFromUser() {
String userName = "testUser";
String roleNames = "Power User\tBusiness User\t";
setupMockSessionUser(SESSION_USER_NAME, true);
// Create session that will generate tenant
IPentahoSession session = mock(IPentahoSession.class);
when(session.getAttribute(IPentahoSession.TENANT_ID_KEY)).thenReturn("testTenantPath");
PentahoSessionHolder.setSession(session);
IPentahoRole ceoRole = mock(IPentahoRole.class);
when(ceoRole.getName()).thenReturn("ceo");
IPentahoRole ctoRole = mock(IPentahoRole.class);
when(ctoRole.getName()).thenReturn("cto");
IPentahoRole powerUserRole = mock(IPentahoRole.class);
when(powerUserRole.getName()).thenReturn("Power User");
IPentahoRole businessUserRole = mock(IPentahoRole.class);
when(businessUserRole.getName()).thenReturn("Business User");
List<IPentahoRole> roleList = new ArrayList<>();
roleList.add(ceoRole);
roleList.add(ctoRole);
roleList.add(powerUserRole);
roleList.add(businessUserRole);
IUserRoleDao roleDao = mock(IUserRoleDao.class);
when(roleDao.getUserRoles(any(ITenant.class), anyString())).thenReturn(roleList);
PentahoSystem.registerObject(roleDao);
userRoleService.removeRolesFromUser(userName, roleNames);
verify(roleDao).setUserRoles(any(ITenant.class), anyString(), argThat(new UnorderedArrayMatcher(new String[] { "ceo", "cto" })));
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method registerMockSession.
private IPentahoSession registerMockSession(String username) {
final IPentahoSession pentahoSession = mock(IPentahoSession.class);
when(pentahoSession.getName()).thenReturn(username);
PentahoSessionHolder.setSession(pentahoSession);
return pentahoSession;
}
Aggregations