Search in sources :

Example 6 with MappingOutput

use of org.pentaho.di.trans.steps.mappingoutput.MappingOutput in project pentaho-kettle by pentaho.

the class SimpleMappingTest method setup.

@Before
public void setup() throws Exception {
    stepMockHelper = new StepMockHelper<SimpleMappingMeta, SimpleMappingData>("SIMPLE_MAPPING_TEST", SimpleMappingMeta.class, SimpleMappingData.class);
    when(stepMockHelper.logChannelInterfaceFactory.create(any(), any(LoggingObjectInterface.class))).thenReturn(stepMockHelper.logChannelInterface);
    when(stepMockHelper.trans.isRunning()).thenReturn(true);
    // Mock for MappingInput
    MappingInput mpInputMock = mock(MappingInput.class);
    when(mpInputMock.getStepname()).thenReturn(MAPPING_INPUT_STEP_NAME);
    // Mock for MappingOutput
    MappingOutput mpOutputMock = mock(MappingOutput.class);
    when(mpOutputMock.getStepname()).thenReturn(MAPPING_OUTPUT_STEP_NAME);
    // Mock for RowDataInputMapper
    RowDataInputMapper rdInputMpMock = mock(RowDataInputMapper.class);
    RowMetaInterface rwMetaInMock = mock(RowMeta.class);
    doReturn(Boolean.TRUE).when(rdInputMpMock).putRow(rwMetaInMock, new Object[] {});
    // Mock for RowProducer
    RowProducer rProducerMock = mock(RowProducer.class);
    when(rProducerMock.putRow(any(RowMetaInterface.class), any(Object[].class), anyBoolean())).thenReturn(true);
    // Mock for MappingIODefinition
    MappingIODefinition mpIODefMock = mock(MappingIODefinition.class);
    // Set up real SimpleMappingData with some mocked elements
    simpleMpData.mappingInput = mpInputMock;
    simpleMpData.mappingOutput = mpOutputMock;
    simpleMpData.rowDataInputMapper = rdInputMpMock;
    simpleMpData.mappingTrans = stepMockHelper.trans;
    when(stepMockHelper.trans.findStepInterface(MAPPING_OUTPUT_STEP_NAME, 0)).thenReturn(mpOutputMock);
    when(stepMockHelper.trans.addRowProducer(MAPPING_INPUT_STEP_NAME, 0)).thenReturn(rProducerMock);
    when(stepMockHelper.processRowsStepMetaInterface.getInputMapping()).thenReturn(mpIODefMock);
}
Also used : MappingInput(org.pentaho.di.trans.steps.mappinginput.MappingInput) RowProducer(org.pentaho.di.trans.RowProducer) MappingIODefinition(org.pentaho.di.trans.steps.mapping.MappingIODefinition) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) MappingOutput(org.pentaho.di.trans.steps.mappingoutput.MappingOutput) Before(org.junit.Before)

Example 7 with MappingOutput

use of org.pentaho.di.trans.steps.mappingoutput.MappingOutput in project pentaho-kettle by pentaho.

the class SimpleMappingTest method testStepShouldStopProcessingInput_IfUnderlyingTransitionIsStopped.

@Test
public void testStepShouldStopProcessingInput_IfUnderlyingTransitionIsStopped() throws Exception {
    MappingInput mappingInput = mock(MappingInput.class);
    when(mappingInput.getStepname()).thenReturn(MAPPING_INPUT_STEP_NAME);
    stepMockHelper.processRowsStepDataInterface.mappingInput = mappingInput;
    RowProducer rowProducer = mock(RowProducer.class);
    when(rowProducer.putRow(any(RowMetaInterface.class), any(Object[].class), anyBoolean())).thenReturn(true);
    StepInterface stepInterface = mock(StepInterface.class);
    Trans mappingTrans = mock(Trans.class);
    when(mappingTrans.addRowProducer(anyString(), anyInt())).thenReturn(rowProducer);
    when(mappingTrans.findStepInterface(anyString(), anyInt())).thenReturn(stepInterface);
    when(mappingTrans.isFinishedOrStopped()).thenReturn(Boolean.FALSE).thenReturn(Boolean.TRUE);
    stepMockHelper.processRowsStepDataInterface.mappingTrans = mappingTrans;
    MappingOutput mappingOutput = mock(MappingOutput.class);
    when(mappingOutput.getStepname()).thenReturn(MAPPING_OUTPUT_STEP_NAME);
    stepMockHelper.processRowsStepDataInterface.mappingOutput = mappingOutput;
    smp = new SimpleMapping(stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans);
    smp.init(stepMockHelper.initStepMetaInterface, simpleMpData);
    smp.addRowSetToInputRowSets(stepMockHelper.getMockInputRowSet(new Object[] {}));
    smp.addRowSetToInputRowSets(stepMockHelper.getMockInputRowSet(new Object[] {}));
    assertTrue(smp.processRow(stepMockHelper.processRowsStepMetaInterface, stepMockHelper.processRowsStepDataInterface));
    assertFalse(smp.processRow(stepMockHelper.processRowsStepMetaInterface, stepMockHelper.processRowsStepDataInterface));
}
Also used : MappingInput(org.pentaho.di.trans.steps.mappinginput.MappingInput) StepInterface(org.pentaho.di.trans.step.StepInterface) RowProducer(org.pentaho.di.trans.RowProducer) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Trans(org.pentaho.di.trans.Trans) MappingOutput(org.pentaho.di.trans.steps.mappingoutput.MappingOutput) Test(org.junit.Test)

Aggregations

MappingOutput (org.pentaho.di.trans.steps.mappingoutput.MappingOutput)7 MappingInput (org.pentaho.di.trans.steps.mappinginput.MappingInput)5 KettleException (org.pentaho.di.core.exception.KettleException)3 StepInterface (org.pentaho.di.trans.step.StepInterface)3 RowSet (org.pentaho.di.core.RowSet)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 RowProducer (org.pentaho.di.trans.RowProducer)2 Trans (org.pentaho.di.trans.Trans)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Test (org.junit.Test)1 BlockingRowSet (org.pentaho.di.core.BlockingRowSet)1 Result (org.pentaho.di.core.Result)1 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)1 LogTableField (org.pentaho.di.core.logging.LogTableField)1 LoggingObjectInterface (org.pentaho.di.core.logging.LoggingObjectInterface)1 SingleThreadedTransExecutor (org.pentaho.di.trans.SingleThreadedTransExecutor)1 RemoteStep (org.pentaho.di.trans.step.RemoteStep)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 StepMetaDataCombi (org.pentaho.di.trans.step.StepMetaDataCombi)1