Search in sources :

Example 6 with IBackgroundExecutionStreamProvider

use of org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider 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();
}
Also used : IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) Serializable(java.io.Serializable) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) IAction(org.pentaho.platform.api.action.IAction) HashMap(java.util.HashMap) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) TestAction(org.pentaho.platform.util.bean.TestAction) ISecurityHelper(org.pentaho.platform.api.engine.ISecurityHelper) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with IBackgroundExecutionStreamProvider

use of org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider 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));
}
Also used : IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) Serializable(java.io.Serializable) IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) HashMap(java.util.HashMap) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ISecurityHelper(org.pentaho.platform.api.engine.ISecurityHelper) TestVarArgsAction(org.pentaho.platform.engine.services.actions.TestVarArgsAction) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with IBackgroundExecutionStreamProvider

use of org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider in project pentaho-platform by pentaho.

the class LocalActionInvokerTest method getStreamProviderNullWithInputFileTest.

@Test
public void getStreamProviderNullWithInputFileTest() throws IOException {
    Map<String, Serializable> paramMap = new HashMap<>();
    File inputFile = new File("example.txt");
    BufferedWriter output = new BufferedWriter(new FileWriter(inputFile));
    output.write("TEST TEXT");
    paramMap.put(ActionUtil.INVOKER_STREAMPROVIDER, null);
    paramMap.put(ActionUtil.INVOKER_STREAMPROVIDER_INPUT_FILE, inputFile);
    IBackgroundExecutionStreamProvider iBackgroundExecutionStreamProvider = defaultActionInvoker.getStreamProvider(paramMap);
    Assert.assertNull(iBackgroundExecutionStreamProvider);
}
Also used : IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) Serializable(java.io.Serializable) HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) File(java.io.File) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 9 with IBackgroundExecutionStreamProvider

use of org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider in project pentaho-platform by pentaho.

the class LocalActionInvokerTest method getStreamProviderNullTest.

@Test
public void getStreamProviderNullTest() {
    Map<String, Serializable> paramMap = new HashMap<>();
    paramMap.put(ActionUtil.INVOKER_STREAMPROVIDER, null);
    IBackgroundExecutionStreamProvider iBackgroundExecutionStreamProvider = defaultActionInvoker.getStreamProvider(paramMap);
    Assert.assertNull(iBackgroundExecutionStreamProvider);
}
Also used : IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 10 with IBackgroundExecutionStreamProvider

use of org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider in project pentaho-platform by pentaho.

the class LocalActionInvokerTest method getStreamProviderTest.

@Test
public void getStreamProviderTest() {
    Map<String, Serializable> paramMap = new HashMap<>();
    RepositoryFileStreamProvider repositoryFileStreamProvider = new RepositoryFileStreamProvider();
    paramMap.put(ActionUtil.INVOKER_STREAMPROVIDER, repositoryFileStreamProvider);
    IBackgroundExecutionStreamProvider iBackgroundExecutionStreamProvider = defaultActionInvoker.getStreamProvider(paramMap);
    Assert.assertEquals(repositoryFileStreamProvider, iBackgroundExecutionStreamProvider);
}
Also used : IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) Serializable(java.io.Serializable) HashMap(java.util.HashMap) RepositoryFileStreamProvider(org.pentaho.platform.web.http.api.resources.RepositoryFileStreamProvider) Test(org.junit.Test)

Aggregations

IBackgroundExecutionStreamProvider (org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider)13 Serializable (java.io.Serializable)12 Test (org.junit.Test)10 HashMap (java.util.HashMap)9 IAction (org.pentaho.platform.api.action.IAction)4 Job (org.pentaho.platform.api.scheduler2.Job)4 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)3 RepositoryFileStreamProvider (org.pentaho.platform.web.http.api.resources.RepositoryFileStreamProvider)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 BufferedWriter (java.io.BufferedWriter)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 ActionInvocationException (org.pentaho.platform.api.action.ActionInvocationException)2 IActionInvokeStatus (org.pentaho.platform.api.action.IActionInvokeStatus)2 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)2 ISecurityHelper (org.pentaho.platform.api.engine.ISecurityHelper)2 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2