use of org.pentaho.platform.api.engine.ISecurityHelper in project pentaho-platform by pentaho.
the class ActionRunnerTest method testCallWithStreamProvider.
@Test
public void testCallWithStreamProvider() throws Exception {
Map<String, Serializable> paramsMap = createMapWithUserLocale();
IAction actionBeanSpy = Mockito.spy(new TestAction());
IBackgroundExecutionStreamProvider mockStreamProvider = Mockito.mock(IBackgroundExecutionStreamProvider.class);
InputStream mockInputStream = Mockito.mock(InputStream.class);
OutputStream mockOutputStream = Mockito.mock(OutputStream.class);
when(mockStreamProvider.getInputStream()).thenReturn(mockInputStream);
String mockOutputPath = "/someUser/someOutput";
when(mockStreamProvider.getOutputPath()).thenReturn(mockOutputPath);
when(mockStreamProvider.getOutputStream()).thenReturn(mockOutputStream);
ISecurityHelper mockSecurityHelper = Mockito.mock(ISecurityHelper.class);
SecurityHelper.setMockInstance(mockSecurityHelper);
when(mockSecurityHelper.runAsUser(Mockito.anyString(), Mockito.any())).thenReturn(mockOutputPath);
PowerMockito.mockStatic(PentahoSystem.class);
IUnifiedRepository mockRepository = Mockito.mock(IUnifiedRepository.class);
when(PentahoSystem.get(isA(IUnifiedRepository.class.getClass()), Mockito.any())).thenReturn(mockRepository);
IAuthorizationPolicy mockAuthorizationPolicy = Mockito.mock(IAuthorizationPolicy.class);
when(PentahoSystem.get(isA(IAuthorizationPolicy.class.getClass()), Mockito.any())).thenReturn(mockAuthorizationPolicy);
when(mockAuthorizationPolicy.isAllowed(SchedulerOutputPathResolver.SCHEDULER_ACTION_NAME)).thenReturn(true);
String repoId = "SOME_REPO_ID";
Map<String, Serializable> dummyMetaData = new HashMap<>();
dummyMetaData.put(RepositoryFile.SCHEDULABLE_KEY, true);
when(mockRepository.getFileMetadata(repoId)).thenReturn(dummyMetaData);
RepositoryFile mockRepoFile = Mockito.mock(RepositoryFile.class);
when(mockRepoFile.isFolder()).thenReturn(true);
when(mockRepoFile.getId()).thenReturn(repoId);
ActionRunner actionRunner = new ActionRunner(actionBeanSpy, "actionUser", paramsMap, mockStreamProvider);
actionRunner.call();
Mockito.verify(actionBeanSpy).execute();
}
use of org.pentaho.platform.api.engine.ISecurityHelper in project pentaho-platform by pentaho.
the class ActionRunnerTest method testCallWithStreamProviderAndVarargsAction.
@Test
public void testCallWithStreamProviderAndVarargsAction() throws Exception {
Map<String, Serializable> paramsMap = createMapWithUserLocale();
TestVarArgsAction testVarArgsAction = new TestVarArgsAction();
IBackgroundExecutionStreamProvider mockStreamProvider = Mockito.mock(IBackgroundExecutionStreamProvider.class);
InputStream mockInputStream = Mockito.mock(InputStream.class);
OutputStream mockOutputStream = Mockito.mock(OutputStream.class);
when(mockStreamProvider.getInputStream()).thenReturn(mockInputStream);
String mockOutputPath = "/someUser/someOutput";
when(mockStreamProvider.getOutputPath()).thenReturn(mockOutputPath);
when(mockStreamProvider.getOutputStream()).thenReturn(mockOutputStream);
ISecurityHelper mockSecurityHelper = Mockito.mock(ISecurityHelper.class);
SecurityHelper.setMockInstance(mockSecurityHelper);
when(mockSecurityHelper.runAsUser(Mockito.anyString(), Mockito.any())).thenReturn(mockOutputPath);
PowerMockito.mockStatic(PentahoSystem.class);
IUnifiedRepository mockRepository = Mockito.mock(IUnifiedRepository.class);
when(PentahoSystem.get(isA(IUnifiedRepository.class.getClass()), Mockito.any())).thenReturn(mockRepository);
IAuthorizationPolicy mockAuthorizationPolicy = Mockito.mock(IAuthorizationPolicy.class);
when(PentahoSystem.get(isA(IAuthorizationPolicy.class.getClass()), Mockito.any())).thenReturn(mockAuthorizationPolicy);
when(mockAuthorizationPolicy.isAllowed(SchedulerOutputPathResolver.SCHEDULER_ACTION_NAME)).thenReturn(true);
String repoId = "SOME_REPO_ID";
Map<String, Serializable> dummyMetaData = new HashMap<>();
dummyMetaData.put(RepositoryFile.SCHEDULABLE_KEY, true);
when(mockRepository.getFileMetadata(repoId)).thenReturn(dummyMetaData);
RepositoryFile mockRepoFile = Mockito.mock(RepositoryFile.class);
when(mockRepoFile.isFolder()).thenReturn(true);
when(mockRepoFile.getId()).thenReturn(repoId);
ActionRunner actionRunner = new ActionRunner(testVarArgsAction, "actionUser", paramsMap, mockStreamProvider);
actionRunner.call();
assertThat(testVarArgsAction.isExecuteWasCalled(), is(true));
}
use of org.pentaho.platform.api.engine.ISecurityHelper 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.ISecurityHelper in project pentaho-platform by pentaho.
the class PentahoXmlaServletTest method testMakeContentFinderHandlesXmlaEnablement.
@Test
public void testMakeContentFinderHandlesXmlaEnablement() throws Exception {
ISecurityHelper securityHelper = mock(ISecurityHelper.class);
SecurityHelper.setMockInstance(securityHelper);
when(securityHelper.runAsSystem(any((Callable.class)))).thenReturn(DATASOURCE_XML);
Document content = XmlDom4JHelper.getDocFromString(new PentahoXmlaServlet().makeContentFinder("fakeurl").getContent(), new PentahoEntityResolver());
assertEquals(2, content.selectNodes("/DataSources/DataSource/Catalogs/Catalog").size());
assertNotNull(content.selectNodes("/DataSources/DataSource/Catalogs/Catalog[@name='EnabledCatalog']"));
assertNotNull(content.selectNodes("/DataSources/DataSource/Catalogs/Catalog[@name='FoodMart']"));
}
use of org.pentaho.platform.api.engine.ISecurityHelper in project pentaho-platform by pentaho.
the class PentahoXmlaServletTest method createConnectionFactory.
@Test
public void createConnectionFactory() throws Exception {
ISecurityHelper securityHelper = mock(ISecurityHelper.class);
SecurityHelper.setMockInstance(securityHelper);
when(securityHelper.runAsSystem(any((Callable.class)))).thenReturn(DATASOURCE_XML);
IMondrianCatalogService catalogService = mock(MondrianCatalogHelper.class);
MondrianCatalog mondrianCatalog = mock(MondrianCatalog.class);
when(mondrianCatalog.getDataSourceInfo()).thenReturn("DataSource=foo");
doReturn(mondrianCatalog).when(catalogService).getCatalog(anyString(), anyObject());
PowerMockito.mockStatic(DriverManager.class);
when(DriverManager.getConnection(anyString(), anyObject())).thenReturn(mock(RolapConnection.class));
PentahoSystem.registerObject(catalogService);
PentahoXmlaServlet xmlaServlet = spy(new PentahoXmlaServlet());
XmlaHandler.ConnectionFactory connectionFactory = xmlaServlet.createConnectionFactory(mock(ServletConfig.class));
Properties properties = new Properties();
properties.put("DataSource", "bogus");
try {
connectionFactory.getConnection("SampleData", "SampleData", "baz", properties);
} catch (MondrianException exception) {
// ignored
}
try {
connectionFactory.getConnection("SampleData", "SampleData", "baz", properties);
} catch (MondrianException exception) {
// ignored
}
// We verify that only one Catalog Locator is created for multiple requests
verify(xmlaServlet, times(1)).makeCatalogLocator(anyObject());
}
Aggregations