use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-kettle by pentaho.
the class JavaScriptStringIT method testStringsPadCase.
/**
* Test case for javascript functionality: lpad(), rpad(), upper(), lower().
*/
public void testStringsPadCase() throws Exception {
KettleEnvironment.init();
//
// Create a new transformation...
//
TransMeta transMeta = new TransMeta();
transMeta.setName("test javascript pad casing");
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();
ScriptValuesScript[] js = new ScriptValuesScript[] { new ScriptValuesScript(ScriptValuesScript.TRANSFORM_SCRIPT, "script", "var lpadded1 = lpad(string, \"x\", 10);\n" + "var lpadded2 = lpad(string, \" \", 9);\n" + "var rpadded1 = rpad(string, \"x\", 10);\n" + "var rpadded2 = rpad(string, \" \", 9);\n" + "var upperStr = upper(string);\n" + "var lowerStr = lower(string);\n") };
svm.setJSScripts(js);
svm.setFieldname(new String[] { "lpadded1", "lpadded2", "rpadded1", "rpadded2", "upperStr", "lowerStr" });
svm.setRename(new String[] { "", "", "", "", "", "", "" });
svm.setType(new int[] { ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING });
svm.setLength(new int[] { -1, -1, -1, -1, -1, -1, -1 });
svm.setPrecision(new int[] { -1, -1, -1, -1, -1, -1, -1 });
svm.setReplace(new boolean[] { false, false, false, false, false, false, false });
svm.setCompatible(true);
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 = createData2();
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 SplitFieldToRowsIT method splitFieldToRows.
/**
* Splits the "stringToSplit" with the passed "delimiter". The "delimiter" is assumed by this method to be a Kettle
* variable. The parameter "delimiterVariableValue" should contain the variables value.
*
* The "isDelimiterRegex" parameter will process the use regex for pattern matching if true.
*
* @param testName
* @param stringToSplit
* @param isDelimiterRegex
* @param delimiter
* @param delimiterVariableValue
* @return
* @throws Exception
*/
private List<RowMetaAndData> splitFieldToRows(String testName, String stringToSplit, boolean isDelimiterRegex, String delimiter, String delimiterVariableValue) {
RowStepCollector rc = new RowStepCollector();
try {
KettleEnvironment.init();
// Create a new transformation...
TransMeta transMeta = new TransMeta();
transMeta.setName("Split field to rows test");
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 Split Field to Rows step
String splitfieldToRowsName = "Split field to rows";
SplitFieldToRowsMeta splitFieldtoRowsMeta = new SplitFieldToRowsMeta();
splitFieldtoRowsMeta.setDelimiter(delimiter);
splitFieldtoRowsMeta.setDelimiterRegex(isDelimiterRegex);
splitFieldtoRowsMeta.setSplitField(FIELD_TO_SPLIT_NAME);
splitFieldtoRowsMeta.setNewFieldname(NEW_FIELD_NAME);
String splitFieldTotRowsPid = registry.getPluginId(StepPluginType.class, splitFieldtoRowsMeta);
StepMeta splitFieldToRows = new StepMeta(splitFieldTotRowsPid, splitfieldToRowsName, splitFieldtoRowsMeta);
transMeta.addStep(splitFieldToRows);
// hop the injector to the split field to rows step
TransHopMeta hop_injector_splitfieldToRows = new TransHopMeta(injectorStep, splitFieldToRows);
transMeta.addTransHop(hop_injector_splitfieldToRows);
// 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 hop_SplitFieldToRows_Dummy = new TransHopMeta(splitFieldToRows, dummyStep);
transMeta.addTransHop(hop_SplitFieldToRows_Dummy);
if (!Utils.isEmpty(delimiterVariableValue)) {
String delimiterVariableName = delimiter.replace("${", "");
delimiterVariableName = delimiterVariableName.replace("}", "");
transMeta.setVariable(delimiterVariableName, delimiterVariableValue);
}
// Now execute the transformation...
Trans trans = new Trans(transMeta);
trans.prepareExecution(null);
StepInterface si = trans.getStepInterface(dummyStepname, 0);
si.addRowListener(rc);
RowProducer rowProducer = trans.addRowProducer(injectorStepname, 0);
trans.startThreads();
// add rows
List<RowMetaAndData> inputList = createData(stringToSplit);
for (RowMetaAndData rm : inputList) {
rowProducer.putRow(rm.getRowMeta(), rm.getData());
}
rowProducer.finished();
trans.waitUntilFinished();
} catch (KettleException e) {
fail("KettleEnvironment exception" + e.getMessage());
}
List<RowMetaAndData> resultRows = rc.getRowsWritten();
return resultRows;
}
use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-kettle by pentaho.
the class DetectLastRowStepIT method detectLastRowStepTest.
/**
* Test case Detect Last Row step. Nr of rows to test with as argument.
*
* @param nrRows
* Number of rows to test.
*
* @throws Exception
* upon any exception
*/
public void detectLastRowStepTest(int nrRows) throws Exception {
KettleEnvironment.init();
//
// Create a new transformation...
//
TransMeta transMeta = new TransMeta();
transMeta.setName("detectlastrowtest1");
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 detect last row step
//
String delectLastRowStepname = "detect last row step";
DetectLastRowMeta dlrm = new DetectLastRowMeta();
dlrm.setResultFieldName("result");
String detectLastRowStepPid = registry.getPluginId(StepPluginType.class, dlrm);
StepMeta detectLastRowStep = new StepMeta(detectLastRowStepPid, delectLastRowStepname, dlrm);
transMeta.addStep(detectLastRowStep);
TransHopMeta hi2 = new TransHopMeta(dummyStep1, detectLastRowStep);
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(detectLastRowStep, 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(delectLastRowStepname, 0);
RowStepCollector detectLastRc = new RowStepCollector();
si.addRowListener(detectLastRc);
RowProducer rp = trans.addRowProducer(injectorStepname, 0);
trans.startThreads();
// add rows
List<RowMetaAndData> inputList = createData(3);
Iterator<RowMetaAndData> it = inputList.iterator();
while (it.hasNext()) {
RowMetaAndData rm = it.next();
rp.putRow(rm.getRowMeta(), rm.getData());
}
rp.finished();
trans.waitUntilFinished();
List<RowMetaAndData> resultRows1 = dummyRc1.getRowsRead();
checkRows(resultRows1, inputList);
List<RowMetaAndData> goldRows = createResultData(3);
List<RowMetaAndData> resultRows2 = detectLastRc.getRowsWritten();
checkRows(resultRows2, goldRows);
}
use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-metaverse by pentaho.
the class AbstractStepMetaJsonSerializerTest method testGetStepFieldMapper.
@Test
public void testGetStepFieldMapper() throws Exception {
IStepAnalyzerProvider provider = mock(IStepAnalyzerProvider.class);
IStepAnalyzer<DummyTransMeta> analyzer = mock(IStepAnalyzer.class, withSettings().extraInterfaces(IFieldLineageMetadataProvider.class));
List<IStepAnalyzer> analyzers = new ArrayList<IStepAnalyzer>(1);
analyzers.add(analyzer);
when(provider.getAnalyzers(any(Set.class))).thenReturn(analyzers);
serializer.setStepAnalyzerProvider(provider);
IFieldLineageMetadataProvider handler = serializer.getFieldLineageMetadataProvider(spyMeta);
assertFalse(handler instanceof GenericStepMetaAnalyzer);
}
use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-metaverse by pentaho.
the class TransMetaJsonSerializerTest method testSerializeSteps.
@Test
public void testSerializeSteps() throws Exception {
final StepMeta spyStep1 = spy(new StepMeta());
final StepMeta spyStep2 = spy(new StepMeta());
final StepMeta spyStep3 = spy(new StepMeta());
DummyTransMeta spyDummy1 = spy(new DummyTransMeta());
DummyTransMeta spyDummy2 = spy(new DummyTransMeta());
DummyTransMeta spyDummy3 = spy(new DummyTransMeta());
List<StepMeta> steps = new ArrayList<StepMeta>() {
{
add(spyStep1);
add(spyStep2);
add(spyStep3);
}
};
when(transMeta.getSteps()).thenReturn(steps);
when(spyStep1.getStepMetaInterface()).thenReturn(spyDummy1);
when(spyStep2.getStepMetaInterface()).thenReturn(spyDummy2);
when(spyStep3.getStepMetaInterface()).thenReturn(spyDummy3);
doThrow(new KettleException()).when(spyDummy3).saveRep(any(Repository.class), any(IMetaStore.class), any(ObjectId.class), any(ObjectId.class));
serializer.serializeSteps(transMeta, json);
verify(json).writeArrayFieldStart(TransMetaJsonSerializer.JSON_PROPERTY_STEPS);
// make sure we call the saveRep method for each step to collect the common attribute stuff
verify(spyDummy1).saveRep(any(Repository.class), any(IMetaStore.class), any(ObjectId.class), any(ObjectId.class));
verify(spyDummy2).saveRep(any(Repository.class), any(IMetaStore.class), any(ObjectId.class), any(ObjectId.class));
verify(spyDummy3).saveRep(any(Repository.class), any(IMetaStore.class), any(ObjectId.class), any(ObjectId.class));
// make sure we are writing out each step
verify(json).writeObject(spyDummy1);
verify(json).writeObject(spyDummy2);
verify(json).writeObject(spyDummy3);
}
Aggregations