Search in sources :

Example 6 with Params

use of org.pentaho.di.base.Params in project pentaho-kettle by pentaho.

the class PanCommandExecutorTest method testExecuteWithInvalidRepository.

@Test
public void testExecuteWithInvalidRepository() {
    // Create Mock Objects
    Params params = mock(Params.class);
    PanCommandExecutor panCommandExecutor = new PanCommandExecutor(Kitchen.class);
    PowerMockito.mockStatic(BaseMessages.class);
    // Mock returns
    when(params.getRepoName()).thenReturn("NoExistingRepository");
    when(BaseMessages.getString(any(Class.class), anyString(), anyVararg())).thenReturn("");
    try {
        Result result = panCommandExecutor.execute(params, null);
        Assert.assertEquals(CommandExecutorCodes.Pan.COULD_NOT_LOAD_TRANS.getCode(), result.getExitStatus());
    } catch (Throwable throwable) {
        Assert.fail();
    }
}
Also used : Params(org.pentaho.di.base.Params) Result(org.pentaho.di.core.Result) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with Params

use of org.pentaho.di.base.Params in project pentaho-kettle by pentaho.

the class PanCommandExecutorTest method testTransformationFinishExtensionPointCalled.

/**
 * This method test a ktr that fails in preparation step and and checks to make sure the callExtensionPoint is
 * called once.
 * @throws Throwable
 */
@Test
public void testTransformationFinishExtensionPointCalled() throws Throwable {
    PluginMockInterface pluginInterface = mock(PluginMockInterface.class);
    when(pluginInterface.getName()).thenReturn(KettleExtensionPoint.TransformationFinish.id);
    when(pluginInterface.getMainType()).thenReturn((Class) ExtensionPointInterface.class);
    when(pluginInterface.getIds()).thenReturn(new String[] { "extensionpointId" });
    ExtensionPointInterface extensionPoint = mock(ExtensionPointInterface.class);
    when(pluginInterface.loadClass(ExtensionPointInterface.class)).thenReturn(extensionPoint);
    PluginRegistry.addPluginType(ExtensionPointPluginType.getInstance());
    PluginRegistry.getInstance().registerPlugin(ExtensionPointPluginType.class, pluginInterface);
    // Execute a sample KTR
    String fullPath = getClass().getResource("fail_on_prep_hello_world.ktr").getPath();
    Params params = mock(Params.class);
    when(params.getRepoName()).thenReturn("");
    when(params.getLocalInitialDir()).thenReturn("");
    when(params.getLocalFile()).thenReturn(fullPath);
    when(params.getLocalJarFile()).thenReturn("");
    when(params.getBase64Zip()).thenReturn("");
    Trans trans = mockedPanCommandExecutor.loadTransFromFilesystem("", fullPath, "", "");
    PanCommandExecutor panCommandExecutor = new PanCommandExecutor(PanCommandExecutor.class);
    Result result = panCommandExecutor.execute(params);
    verify(extensionPoint, times(1)).callExtensionPoint(any(LogChannelInterface.class), any(Trans.class));
}
Also used : Params(org.pentaho.di.base.Params) Matchers.anyString(org.mockito.Matchers.anyString) Trans(org.pentaho.di.trans.Trans) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) ExtensionPointInterface(org.pentaho.di.core.extension.ExtensionPointInterface) Result(org.pentaho.di.core.Result) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with Params

use of org.pentaho.di.base.Params in project pentaho-kettle by pentaho.

the class PanCommandExecutorTest method testNoTransformationFinishExtensionPointCalled.

/**
 * This method test a valid ktr and make sure the callExtensionPoint is never called, as this method is called
 * if the ktr fails in preparation step
 * @throws Throwable
 */
@Test
public void testNoTransformationFinishExtensionPointCalled() throws Throwable {
    PluginMockInterface pluginInterface = mock(PluginMockInterface.class);
    when(pluginInterface.getName()).thenReturn(KettleExtensionPoint.TransformationFinish.id);
    when(pluginInterface.getMainType()).thenReturn((Class) ExtensionPointInterface.class);
    when(pluginInterface.getIds()).thenReturn(new String[] { "extensionpointId" });
    ExtensionPointInterface extensionPoint = mock(ExtensionPointInterface.class);
    when(pluginInterface.loadClass(ExtensionPointInterface.class)).thenReturn(extensionPoint);
    PluginRegistry.addPluginType(ExtensionPointPluginType.getInstance());
    PluginRegistry.getInstance().registerPlugin(ExtensionPointPluginType.class, pluginInterface);
    // Execute a sample KTR
    String fullPath = getClass().getResource(SAMPLE_KTR).getPath();
    Params params = mock(Params.class);
    when(params.getRepoName()).thenReturn("");
    when(params.getLocalInitialDir()).thenReturn("");
    when(params.getLocalFile()).thenReturn(fullPath);
    when(params.getLocalJarFile()).thenReturn("");
    when(params.getBase64Zip()).thenReturn("");
    Trans trans = mockedPanCommandExecutor.loadTransFromFilesystem("", fullPath, "", "");
    PanCommandExecutor panCommandExecutor = new PanCommandExecutor(PanCommandExecutor.class);
    Result result = panCommandExecutor.execute(params);
    verify(extensionPoint, times(0)).callExtensionPoint(any(LogChannelInterface.class), same(trans));
}
Also used : Params(org.pentaho.di.base.Params) Matchers.anyString(org.mockito.Matchers.anyString) Trans(org.pentaho.di.trans.Trans) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) ExtensionPointInterface(org.pentaho.di.core.extension.ExtensionPointInterface) Result(org.pentaho.di.core.Result) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Params (org.pentaho.di.base.Params)8 Result (org.pentaho.di.core.Result)7 Test (org.junit.Test)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)5 ExtensionPointInterface (org.pentaho.di.core.extension.ExtensionPointInterface)4 Matchers.anyString (org.mockito.Matchers.anyString)3 Trans (org.pentaho.di.trans.Trans)3 ArrayList (java.util.ArrayList)2 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)2 FileLoggingEventListener (org.pentaho.di.core.logging.FileLoggingEventListener)2 NamedParams (org.pentaho.di.core.parameters.NamedParams)2 NamedParamsDefault (org.pentaho.di.core.parameters.NamedParamsDefault)2 AbstractMap (java.util.AbstractMap)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 KettleException (org.pentaho.di.core.exception.KettleException)1