Search in sources :

Example 1 with TestAction

use of org.pentaho.platform.util.bean.TestAction 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 2 with TestAction

use of org.pentaho.platform.util.bean.TestAction in project pentaho-platform by pentaho.

the class ActionRunnerTest method testCallThrowsException.

@Test
public void testCallThrowsException() throws Exception {
    Map<String, Serializable> paramsMap = createMapWithUserLocale();
    IAction actionBeanSpy = Mockito.spy(new TestAction());
    IBackgroundExecutionStreamProvider mockStreamProvider = Mockito.mock(IBackgroundExecutionStreamProvider.class);
    when(mockStreamProvider.getInputStream()).thenThrow(new Exception("something went wrong"));
    ActionRunner actionRunner = new ActionRunner(actionBeanSpy, "actionUser", paramsMap, mockStreamProvider);
    exception.expect(ActionInvocationException.class);
    actionRunner.call();
}
Also used : IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) Serializable(java.io.Serializable) IAction(org.pentaho.platform.api.action.IAction) ExpectedException(org.junit.rules.ExpectedException) ActionInvocationException(org.pentaho.platform.api.action.ActionInvocationException) TestAction(org.pentaho.platform.util.bean.TestAction) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with TestAction

use of org.pentaho.platform.util.bean.TestAction in project pentaho-platform by pentaho.

the class ActionRunnerTest method testCallInvokesExecute.

@Test
public void testCallInvokesExecute() throws Exception {
    Map<String, Serializable> paramsMap = createMapWithUserLocale();
    IAction actionBeanSpy = Mockito.spy(new TestAction());
    ActionRunner actionRunner = new ActionRunner(actionBeanSpy, "actionUser", paramsMap, null);
    actionRunner.call();
    Mockito.verify(actionBeanSpy).execute();
    // Verify that, by default the isExecutionSuccessful returns true
    Assert.assertTrue(actionBeanSpy.isExecutionSuccessful());
}
Also used : Serializable(java.io.Serializable) IAction(org.pentaho.platform.api.action.IAction) TestAction(org.pentaho.platform.util.bean.TestAction) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with TestAction

use of org.pentaho.platform.util.bean.TestAction in project pentaho-platform by pentaho.

the class DefaultActionInvokerTest method testValidate.

@Test
public void testValidate() throws Exception {
    final DefaultActionInvoker ai = new DefaultActionInvoker();
    ai.validate(new TestAction(), "user", new HashMap());
}
Also used : HashMap(java.util.HashMap) TestAction(org.pentaho.platform.util.bean.TestAction) Test(org.junit.Test)

Example 5 with TestAction

use of org.pentaho.platform.util.bean.TestAction in project pentaho-platform by pentaho.

the class DefaultActionInvokerTest method testValidateNullParams.

@Test(expected = ActionInvocationException.class)
public void testValidateNullParams() throws Exception {
    final DefaultActionInvoker ai = new DefaultActionInvoker();
    ai.validate(new TestAction(), "user", null);
}
Also used : TestAction(org.pentaho.platform.util.bean.TestAction) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 TestAction (org.pentaho.platform.util.bean.TestAction)5 Serializable (java.io.Serializable)3 IAction (org.pentaho.platform.api.action.IAction)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 HashMap (java.util.HashMap)2 IBackgroundExecutionStreamProvider (org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ExpectedException (org.junit.rules.ExpectedException)1 ActionInvocationException (org.pentaho.platform.api.action.ActionInvocationException)1 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)1 ISecurityHelper (org.pentaho.platform.api.engine.ISecurityHelper)1 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1