use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.
the class XMLOutputStepAnalyzerTest method testXMLOutputExternalResourceConsumer.
@Test
public void testXMLOutputExternalResourceConsumer() throws Exception {
XMLOutputExternalResourceConsumer consumer = new XMLOutputExternalResourceConsumer();
StepMeta meta = new StepMeta("test", this.meta);
StepMeta spyMeta = spy(meta);
when(this.meta.getParentStepMeta()).thenReturn(spyMeta);
when(spyMeta.getParentTransMeta()).thenReturn(mockTransMeta);
when(this.meta.getFileName()).thenReturn(null);
String[] filePaths = { "/path/to/file1", "/another/path/to/file2" };
when(this.meta.getFiles(Mockito.any(VariableSpace.class))).thenReturn(filePaths);
assertFalse(consumer.isDataDriven(this.meta));
Collection<IExternalResourceInfo> resources = consumer.getResourcesFromMeta(this.meta);
assertFalse(resources.isEmpty());
assertEquals(2, resources.size());
when(this.meta.getExtension()).thenReturn("txt");
assertEquals(XMLOutputMeta.class, consumer.getMetaClass());
}
use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.
the class XsltTest method runTestWithParams.
public void runTestWithParams(String xmlFieldname, String resultFieldname, boolean xslInField, boolean xslFileInField, String xslFileField, String xslFilename, String xslFactory) throws Exception {
KettleEnvironment.init();
//
// Create a new transformation...
//
TransMeta transMeta = new TransMeta();
transMeta.setName("xslt");
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 XSLT step
//
String xsltName = "xslt step";
XsltMeta xm = new XsltMeta();
String xsltPid = registry.getPluginId(StepPluginType.class, xm);
StepMeta xsltStep = new StepMeta(xsltPid, xsltName, xm);
transMeta.addStep(xsltStep);
TextFileInputField[] fields = new TextFileInputField[3];
for (int idx = 0; idx < fields.length; idx++) {
fields[idx] = new TextFileInputField();
}
fields[0].setName("XML");
fields[0].setType(ValueMetaInterface.TYPE_STRING);
fields[0].setFormat("");
fields[0].setLength(-1);
fields[0].setPrecision(-1);
fields[0].setCurrencySymbol("");
fields[0].setDecimalSymbol("");
fields[0].setGroupSymbol("");
fields[0].setTrimType(ValueMetaInterface.TRIM_TYPE_NONE);
fields[1].setName("XSL");
fields[1].setType(ValueMetaInterface.TYPE_STRING);
fields[1].setFormat("");
fields[1].setLength(-1);
fields[1].setPrecision(-1);
fields[1].setCurrencySymbol("");
fields[1].setDecimalSymbol("");
fields[1].setGroupSymbol("");
fields[1].setTrimType(ValueMetaInterface.TRIM_TYPE_NONE);
fields[2].setName("filename");
fields[2].setType(ValueMetaInterface.TYPE_STRING);
fields[2].setFormat("");
fields[2].setLength(-1);
fields[2].setPrecision(-1);
fields[2].setCurrencySymbol("");
fields[2].setDecimalSymbol("");
fields[2].setGroupSymbol("");
fields[2].setTrimType(ValueMetaInterface.TRIM_TYPE_NONE);
xm.setFieldname(xmlFieldname);
xm.setResultfieldname(resultFieldname);
xm.setXSLField(xslInField);
xm.setXSLFileField(xslFileField);
xm.setXSLFieldIsAFile(xslFileInField);
xm.setXslFilename(xslFilename);
xm.setXSLFactory(xslFactory);
TransHopMeta hi = new TransHopMeta(injectorStep, xsltStep);
transMeta.addTransHop(hi);
//
// 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 hi1 = new TransHopMeta(xsltStep, dummyStep1);
transMeta.addTransHop(hi1);
// 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);
RowProducer rp = trans.addRowProducer(injectorStepname, 0);
trans.startThreads();
// add rows
List<RowMetaAndData> inputList = createData(xslFilename);
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 = dummyRc1.getRowsWritten();
List<RowMetaAndData> goldenImageRows = createResultData1();
checkRows(goldenImageRows, resultRows, 2);
}
use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.
the class TransTestFactory method getReadStepMeta.
static StepMeta getReadStepMeta(String name) {
DummyTransMeta twoMeta = new DummyTransMeta();
StepMeta two = new StepMeta(registry.getPluginId(StepPluginType.class, twoMeta), name, twoMeta);
two.setLocation(250, 50);
two.setDraw(true);
return two;
}
use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.
the class TransTestFactory method generateTestTransformationError.
public static TransMeta generateTestTransformationError(VariableSpace parent, StepMetaInterface oneMeta, String oneStepname) {
TransMeta previewMeta = new TransMeta(parent);
if (parent == null) {
parent = new Variables();
}
// First the injector step...
StepMeta zero = getInjectorStepMeta();
previewMeta.addStep(zero);
// Then the middle step to test...
//
StepMeta one = new StepMeta(registry.getPluginId(StepPluginType.class, oneMeta), oneStepname, oneMeta);
one.setLocation(150, 50);
one.setDraw(true);
previewMeta.addStep(one);
// Then we add the dummy step to read the results from
StepMeta two = getReadStepMeta();
previewMeta.addStep(two);
// error handling step
StepMeta err = getReadStepMeta(ERROR_STEPNAME);
previewMeta.addStep(err);
// Add the hops between the 3 steps.
TransHopMeta zeroOne = new TransHopMeta(zero, one);
previewMeta.addTransHop(zeroOne);
TransHopMeta oneTwo = new TransHopMeta(one, two);
previewMeta.addTransHop(oneTwo);
StepErrorMeta errMeta = new StepErrorMeta(parent, one, err);
errMeta.setEnabled(true);
errMeta.setNrErrorsValuename(NUMBER_ERRORS_FIELD);
errMeta.setErrorDescriptionsValuename(ERROR_DESC_FIELD);
errMeta.setErrorFieldsValuename(ERROR_FIELD_VALUE);
errMeta.setErrorCodesValuename(ERROR_CODE_VALUE);
one.setStepErrorMeta(errMeta);
TransHopMeta oneErr = new TransHopMeta(one, err);
previewMeta.addTransHop(oneErr);
return previewMeta;
}
use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.
the class TransTestFactory method getInjectorStepMeta.
static StepMeta getInjectorStepMeta() {
InjectorMeta zeroMeta = new InjectorMeta();
StepMeta zero = new StepMeta(registry.getPluginId(StepPluginType.class, zeroMeta), INJECTOR_STEPNAME, zeroMeta);
zero.setLocation(50, 50);
zero.setDraw(true);
return zero;
}
Aggregations