Search in sources :

Example 16 with StepDataInterface

use of org.pentaho.di.trans.step.StepDataInterface in project pentaho-kettle by pentaho.

the class TransTest method testCleanup_WithSteps.

@Test
public void testCleanup_WithSteps() throws Exception {
    StepInterface stepMock1 = mock(StepInterface.class);
    StepInterface stepMock2 = mock(StepInterface.class);
    StepDataInterface stepDataMock1 = mock(StepDataInterface.class);
    StepDataInterface stepDataMock2 = mock(StepDataInterface.class);
    StepMeta stepMetaMock1 = mock(StepMeta.class);
    StepMeta stepMetaMock2 = mock(StepMeta.class);
    // A step that is already disposed
    when(stepDataMock1.isDisposed()).thenReturn(true);
    // A step not yet disposed
    when(stepDataMock2.isDisposed()).thenReturn(false);
    trans.setSteps(of(combi(stepMock1, stepDataMock1, stepMetaMock1), combi(stepMock2, stepDataMock2, stepMetaMock2)));
    // this should work (no exception thrown)
    trans.cleanup();
    // The isDisposed method is always invoked
    verify(stepDataMock1).isDisposed();
    verify(stepDataMock2).isDisposed();
    // Only 'stepDataMock2' is to be disposed
    verify(stepMock1, times(0)).dispose(any(StepMetaInterface.class), any(StepDataInterface.class));
    verify(stepMock2, times(1)).dispose(any(StepMetaInterface.class), any(StepDataInterface.class));
    // The cleanup method is always invoked
    verify(stepMock1).cleanup();
    verify(stepMock2).cleanup();
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StepDataInterface(org.pentaho.di.trans.step.StepDataInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with StepDataInterface

use of org.pentaho.di.trans.step.StepDataInterface in project pentaho-kettle by pentaho.

the class TransTest method safeStopLetsNonInputStepsKeepRunning.

@Test
public void safeStopLetsNonInputStepsKeepRunning() throws Exception {
    StepInterface stepMock1 = mock(StepInterface.class);
    StepInterface stepMock2 = mock(StepInterface.class);
    StepDataInterface stepDataMock1 = mock(StepDataInterface.class);
    StepDataInterface stepDataMock2 = mock(StepDataInterface.class);
    StepMeta stepMetaMock1 = mock(StepMeta.class);
    StepMeta stepMetaMock2 = mock(StepMeta.class);
    trans.setSteps(of(combi(stepMock1, stepDataMock1, stepMetaMock1), combi(stepMock2, stepDataMock2, stepMetaMock2)));
    doReturn(emptyList()).when(meta).findPreviousSteps(stepMetaMock1, true);
    // stepMeta2 will have stepMeta as previous, so is not an input step
    doReturn(of(stepMetaMock1)).when(meta).findPreviousSteps(stepMetaMock2, true);
    trans.safeStop();
    verifyStopped(stepMock1, 1);
    // non input step shouldn't have stop called
    verifyStopped(stepMock2, 0);
    verify(trans).notifyStoppedListeners();
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) StepDataInterface(org.pentaho.di.trans.step.StepDataInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 18 with StepDataInterface

use of org.pentaho.di.trans.step.StepDataInterface in project pentaho-kettle by pentaho.

the class StepWithMappingMetaTest method testExportResources.

@SuppressWarnings("unchecked")
@Test
@PrepareForTest(StepWithMappingMeta.class)
public void testExportResources() throws Exception {
    StepWithMappingMeta stepWithMappingMeta = spy(new StepWithMappingMeta() {

        @Override
        public void setDefault() {
        }

        @Override
        public StepDataInterface getStepData() {
            return null;
        }

        @Override
        public StepInterface getStep(StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans) {
            return null;
        }
    });
    String testName = "test";
    PowerMockito.mockStatic(StepWithMappingMeta.class);
    when(StepWithMappingMeta.loadMappingMeta(any(), any(), any(), any())).thenReturn(transMeta);
    when(transMeta.exportResources(any(), anyMap(), any(), any(), any())).thenReturn(testName);
    stepWithMappingMeta.exportResources(null, null, null, null, null);
    verify(transMeta).setFilename("${" + Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY + "}/" + testName);
    verify(stepWithMappingMeta).setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) Mockito.anyString(org.mockito.Mockito.anyString) StepDataInterface(org.pentaho.di.trans.step.StepDataInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 19 with StepDataInterface

use of org.pentaho.di.trans.step.StepDataInterface in project pentaho-kettle by pentaho.

the class TransTest method testGetEnded_withSteps.

@Test
public void testGetEnded_withSteps() {
    List<StepMetaDataCombi> steps = new ArrayList<>();
    int ended = 0;
    // Steps with all possible status (and still running).
    // Finished, Halted, or Stopped (three in total) should be counted.
    ended += 3;
    for (BaseStepData.StepExecutionStatus status : BaseStepData.StepExecutionStatus.values()) {
        StepInterface stepMock = mock(StepInterface.class);
        StepDataInterface stepDataMock = mock(StepDataInterface.class);
        StepMeta stepMetaMock = mock(StepMeta.class);
        doReturn(true).when(stepMock).isRunning();
        doReturn(status).when(stepDataMock).getStatus();
        steps.add(combi(stepMock, stepDataMock, stepMetaMock));
    }
    // Step not running (also to be counted)
    ++ended;
    StepInterface stepMock = mock(StepInterface.class);
    doReturn(false).when(stepMock).isRunning();
    steps.add(combi(stepMock, mock(StepDataInterface.class), mock(StepMeta.class)));
    // Add created steps
    trans.setSteps(steps);
    // A total of four (4) steps should be counted as ended.
    assertEquals(ended, trans.getEnded());
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) ArrayList(java.util.ArrayList) BaseStepData(org.pentaho.di.trans.step.BaseStepData) StepDataInterface(org.pentaho.di.trans.step.StepDataInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with StepDataInterface

use of org.pentaho.di.trans.step.StepDataInterface in project pentaho-kettle by pentaho.

the class UnivariateStatsMetaTest method testGetStep.

@Test
public void testGetStep() {
    StepMeta mockStepMeta = mock(StepMeta.class);
    when(mockStepMeta.getName()).thenReturn("testName");
    StepDataInterface mockStepDataInterface = mock(StepDataInterface.class);
    int cnr = 10;
    TransMeta mockTransMeta = mock(TransMeta.class);
    Trans mockTrans = mock(Trans.class);
    when(mockTransMeta.findStep("testName")).thenReturn(mockStepMeta);
    StepInterface step = new UnivariateStatsMeta().getStep(mockStepMeta, mockStepDataInterface, cnr, mockTransMeta, mockTrans);
    assertTrue("Expected Step to be instanceof " + UnivariateStats.class, step instanceof UnivariateStats);
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) TransMeta(org.pentaho.di.trans.TransMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) StepDataInterface(org.pentaho.di.trans.step.StepDataInterface) Trans(org.pentaho.di.trans.Trans) Test(org.junit.Test)

Aggregations

StepDataInterface (org.pentaho.di.trans.step.StepDataInterface)22 StepMeta (org.pentaho.di.trans.step.StepMeta)19 Test (org.junit.Test)15 StepInterface (org.pentaho.di.trans.step.StepInterface)13 Trans (org.pentaho.di.trans.Trans)9 TransMeta (org.pentaho.di.trans.TransMeta)9 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 KettleException (org.pentaho.di.core.exception.KettleException)5 StepMetaDataCombi (org.pentaho.di.trans.step.StepMetaDataCombi)5 ArrayList (java.util.ArrayList)4 KettleStepException (org.pentaho.di.core.exception.KettleStepException)3 List (java.util.List)2 FileObject (org.apache.commons.vfs2.FileObject)2 Mockito.anyString (org.mockito.Mockito.anyString)2 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2 BaseStep (org.pentaho.di.trans.step.BaseStep)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1