Search in sources :

Example 6 with Field

use of org.pentaho.di.trans.steps.nullif.NullIfMeta.Field in project pentaho-kettle by pentaho.

the class NullIfIT method testNullIf1.

/**
 * Test case for nullif step. Injector step to a nullif step to a dummy step.
 */
public void testNullIf1() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("nulliftest1");
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create an injector step...
    // 
    String injectorStepname = "injector step";
    InjectorMeta im = new InjectorMeta();
    // Set the information of the injector.
    String injectorPid = registry.getPluginId(StepPluginType.class, im);
    StepMeta injectorStep = new StepMeta(injectorPid, injectorStepname, im);
    transMeta.addStep(injectorStep);
    // 
    // Create a dummy step 1
    // 
    String dummyStepname1 = "dummy step 1";
    DummyTransMeta dm1 = new DummyTransMeta();
    String dummyPid1 = registry.getPluginId(StepPluginType.class, dm1);
    StepMeta dummyStep1 = new StepMeta(dummyPid1, dummyStepname1, dm1);
    transMeta.addStep(dummyStep1);
    TransHopMeta hi = new TransHopMeta(injectorStep, dummyStep1);
    transMeta.addTransHop(hi);
    // 
    // Create a NullIf step
    // 
    String nullIfName = "nullif step";
    NullIfMeta ni = new NullIfMeta();
    Field[] fields = new Field[2];
    fields[0] = new Field();
    fields[0].setFieldName("field2");
    fields[0].setFieldValue("1");
    fields[1] = new Field();
    fields[1].setFieldName("field1");
    fields[1].setFieldValue("tst");
    ni.setFields(fields);
    String nullIfPid = registry.getPluginId(StepPluginType.class, ni);
    StepMeta nullIfStep = new StepMeta(nullIfPid, nullIfName, ni);
    transMeta.addStep(nullIfStep);
    TransHopMeta hi2 = new TransHopMeta(dummyStep1, nullIfStep);
    transMeta.addTransHop(hi2);
    // 
    // Create a dummy step 2
    // 
    String dummyStepname2 = "dummy step 2";
    DummyTransMeta dm2 = new DummyTransMeta();
    String dummyPid2 = registry.getPluginId(StepPluginType.class, dm2);
    StepMeta dummyStep2 = new StepMeta(dummyPid2, dummyStepname2, dm2);
    transMeta.addStep(dummyStep2);
    TransHopMeta hi3 = new TransHopMeta(nullIfStep, dummyStep2);
    transMeta.addTransHop(hi3);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(dummyStepname1, 0);
    RowStepCollector dummyRc1 = new RowStepCollector();
    si.addRowListener(dummyRc1);
    si = trans.getStepInterface(nullIfName, 0);
    RowStepCollector nullIfRc = new RowStepCollector();
    si.addRowListener(nullIfRc);
    si = trans.getStepInterface(dummyStepname2, 0);
    RowStepCollector dummyRc = new RowStepCollector();
    si.addRowListener(dummyRc);
    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    trans.startThreads();
    // add rows
    List<RowMetaAndData> inputList = createData();
    Iterator<RowMetaAndData> it = inputList.iterator();
    while (it.hasNext()) {
        RowMetaAndData rm = it.next();
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    trans.waitUntilFinished();
    // Compare the results
    List<RowMetaAndData> resultRows = dummyRc.getRowsWritten();
    List<RowMetaAndData> goldenImageRows = createResultData1();
    checkRows(goldenImageRows, resultRows);
}
Also used : RowProducer(org.pentaho.di.trans.RowProducer) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) StepInterface(org.pentaho.di.trans.step.StepInterface) Field(org.pentaho.di.trans.steps.nullif.NullIfMeta.Field) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans)

Aggregations

Field (org.pentaho.di.trans.steps.nullif.NullIfMeta.Field)6 Test (org.junit.Test)3 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)1 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)1 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)1 RowProducer (org.pentaho.di.trans.RowProducer)1 RowStepCollector (org.pentaho.di.trans.RowStepCollector)1 Trans (org.pentaho.di.trans.Trans)1 TransHopMeta (org.pentaho.di.trans.TransHopMeta)1 TransMeta (org.pentaho.di.trans.TransMeta)1 StepInterface (org.pentaho.di.trans.step.StepInterface)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)1 InjectorMeta (org.pentaho.di.trans.steps.injector.InjectorMeta)1 LoadSaveTester (org.pentaho.di.trans.steps.loadsave.LoadSaveTester)1 ArrayLoadSaveValidator (org.pentaho.di.trans.steps.loadsave.validator.ArrayLoadSaveValidator)1 FieldLoadSaveValidator (org.pentaho.di.trans.steps.loadsave.validator.FieldLoadSaveValidator)1