use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-kettle by pentaho.
the class ValueMapperIT method testValueMapper1.
/**
* Test case for valuemapper step. Injector step to a valuemapper step to a dummy step. Rows go in and should be
* mapped accordingly.
*
* This test will write the mappings in a new field.
*/
public void testValueMapper1() throws Exception {
KettleEnvironment.init();
//
// Create a new transformation...
//
TransMeta transMeta = new TransMeta();
transMeta.setName("valuemappertest1");
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 ValueMapper step
//
String valueMapperName = "valuemapper step";
ValueMapperMeta vm = new ValueMapperMeta();
vm.setFieldToUse("field1");
vm.setTargetField("new_field");
vm.setSourceValue(new String[] { "abc", "ABC", "def", "ghij" });
vm.setTargetValue(new String[] { "begin", "BEG_LONGER", "test", "" });
String valueMapperPid = registry.getPluginId(StepPluginType.class, vm);
StepMeta valueMapperStep = new StepMeta(valueMapperPid, valueMapperName, vm);
transMeta.addStep(valueMapperStep);
TransHopMeta hi2 = new TransHopMeta(dummyStep1, valueMapperStep);
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(valueMapperStep, 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(valueMapperName, 0);
RowStepCollector valueMapperRc = new RowStepCollector();
si.addRowListener(valueMapperRc);
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);
}
use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-kettle by pentaho.
the class JavaScriptSpecialIT method testTransStatus.
/**
* Test case for javascript functionality: trans_Status and SKIP_TRANSFORMATION. Regression test case for JIRA defect
* PDI-364.
*/
public void testTransStatus() throws Exception {
KettleEnvironment.init();
//
// Create a new transformation...
//
TransMeta transMeta = new TransMeta();
transMeta.setName("test javascript trans_Status");
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 javascript step
//
String javaScriptStepname = "javascript step";
ScriptValuesMetaMod svm = new ScriptValuesMetaMod();
// process 3 rows and skip the rest.
ScriptValuesScript[] js = new ScriptValuesScript[] { new ScriptValuesScript(ScriptValuesScript.TRANSFORM_SCRIPT, "script", "trans_Status = CONTINUE_TRANSFORMATION;\n" + "if (getProcessCount(\"r\") > 3) {\n" + " \ttrans_Status = SKIP_TRANSFORMATION;\n" + "}") };
svm.setJSScripts(js);
svm.setFieldname(new String[] {});
svm.setRename(new String[] {});
svm.setType(new int[] {});
svm.setLength(new int[] {});
svm.setPrecision(new int[] {});
svm.setCompatible(false);
String javaScriptStepPid = registry.getPluginId(StepPluginType.class, svm);
StepMeta javaScriptStep = new StepMeta(javaScriptStepPid, javaScriptStepname, svm);
transMeta.addStep(javaScriptStep);
TransHopMeta hi1 = new TransHopMeta(injectorStep, javaScriptStep);
transMeta.addTransHop(hi1);
//
// Create a dummy step
//
String dummyStepname = "dummy step";
DummyTransMeta dm = new DummyTransMeta();
String dummyPid = registry.getPluginId(StepPluginType.class, dm);
StepMeta dummyStep = new StepMeta(dummyPid, dummyStepname, dm);
transMeta.addStep(dummyStep);
TransHopMeta hi2 = new TransHopMeta(javaScriptStep, dummyStep);
transMeta.addTransHop(hi2);
// Now execute the transformation...
Trans trans = new Trans(transMeta);
trans.prepareExecution(null);
StepInterface si;
si = trans.getStepInterface(javaScriptStepname, 0);
RowStepCollector javaScriptRc = new RowStepCollector();
si.addRowListener(javaScriptRc);
si = trans.getStepInterface(dummyStepname, 0);
RowStepCollector dummyRc = new RowStepCollector();
si.addRowListener(dummyRc);
RowProducer rp = trans.addRowProducer(injectorStepname, 0);
trans.startThreads();
// add rows
List<RowMetaAndData> inputList = createData1();
Iterator<RowMetaAndData> it = inputList.iterator();
while (it.hasNext()) {
RowMetaAndData rm = it.next();
rp.putRow(rm.getRowMeta(), rm.getData());
}
rp.finished();
trans.waitUntilFinished();
List<RowMetaAndData> goldenImageRows = createResultData2();
List<RowMetaAndData> resultRows1 = javaScriptRc.getRowsWritten();
checkRows(resultRows1, goldenImageRows);
List<RowMetaAndData> resultRows2 = dummyRc.getRowsRead();
checkRows(resultRows2, goldenImageRows);
}
use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta 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);
}
use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-kettle by pentaho.
the class SpoonTest method testCopyPasteStepsErrorHandling.
/**
* test two steps
* @see http://jira.pentaho.com/browse/PDI-689
*
* @throws KettleException
*/
@Test
public void testCopyPasteStepsErrorHandling() throws KettleException {
final TransMeta transMeta = new TransMeta();
// for check copy both step and hop
StepMeta sourceStep = new StepMeta("CsvInput", "Step1", new CsvInputMeta());
StepMeta targetStep = new StepMeta("Dummy", "Dummy Step1", new DummyTransMeta());
sourceStep.setSelected(true);
targetStep.setSelected(true);
transMeta.addStep(sourceStep);
transMeta.addStep(targetStep);
StepErrorMeta errorMeta = new StepErrorMeta(transMeta, sourceStep, targetStep);
sourceStep.setStepErrorMeta(errorMeta);
errorMeta.setSourceStep(sourceStep);
errorMeta.setTargetStep(targetStep);
final int stepsSizeBefore = transMeta.getSteps().size();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
spoon.pasteXML(transMeta, (String) invocation.getArguments()[0], mock(Point.class));
assertTrue("Steps was not copied", stepsSizeBefore < transMeta.getSteps().size());
// selected copied step
for (StepMeta s : transMeta.getSelectedSteps()) {
if (s.getStepMetaInterface() instanceof CsvInputMeta) {
// check that stepError was copied
assertNotNull("Error hop was not copied", s.getStepErrorMeta());
}
}
return null;
}
}).when(spoon).toClipboard(anyString());
spoon.copySelected(transMeta, transMeta.getSelectedSteps(), Collections.<NotePadMeta>emptyList());
}
use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-kettle by pentaho.
the class SpoonTest method testCopyPasteOneStepWithErrorHandling.
/**
* test copy one step with error handling
* @see http://jira.pentaho.com/browse/PDI-13358
*
* @throws KettleException
*/
@Test
public void testCopyPasteOneStepWithErrorHandling() throws KettleException {
final TransMeta transMeta = new TransMeta();
StepMeta sourceStep = new StepMeta("CsvInput", "Step1", new CsvInputMeta());
StepMeta targetStep = new StepMeta("Dummy", "Dummy Step1", new DummyTransMeta());
sourceStep.setSelected(true);
transMeta.addStep(sourceStep);
transMeta.addStep(targetStep);
StepErrorMeta errorMeta = new StepErrorMeta(transMeta, sourceStep, targetStep);
sourceStep.setStepErrorMeta(errorMeta);
errorMeta.setSourceStep(sourceStep);
errorMeta.setTargetStep(targetStep);
final int stepsSizeBefore = transMeta.getSteps().size();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
spoon.pasteXML(transMeta, (String) invocation.getArguments()[0], mock(Point.class));
assertTrue("Steps was not copied", stepsSizeBefore < transMeta.getSteps().size());
// selected copied step
for (StepMeta s : transMeta.getSelectedSteps()) {
if (s.getStepMetaInterface() instanceof CsvInputMeta) {
// check that stepError was empty, because we copy only one step from pair
assertNull("Error hop was not copied", s.getStepErrorMeta());
}
}
return null;
}
}).when(spoon).toClipboard(anyString());
spoon.copySelected(transMeta, transMeta.getSelectedSteps(), Collections.<NotePadMeta>emptyList());
}
Aggregations