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);
}
Aggregations