Search in sources :

Example 86 with StepMeta

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());
}
Also used : IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) VariableSpace(org.pentaho.di.core.variables.VariableSpace) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Example 87 with StepMeta

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);
}
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) TextFileInputField(org.pentaho.di.trans.steps.textfileinput.TextFileInputField) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) StepInterface(org.pentaho.di.trans.step.StepInterface) 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)

Example 88 with StepMeta

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;
}
Also used : StepPluginType(org.pentaho.di.core.plugins.StepPluginType) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)

Example 89 with StepMeta

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;
}
Also used : Variables(org.pentaho.di.core.variables.Variables) StepPluginType(org.pentaho.di.core.plugins.StepPluginType) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) StepErrorMeta(org.pentaho.di.trans.step.StepErrorMeta) StepMeta(org.pentaho.di.trans.step.StepMeta)

Example 90 with StepMeta

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;
}
Also used : StepPluginType(org.pentaho.di.core.plugins.StepPluginType) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) StepMeta(org.pentaho.di.trans.step.StepMeta)

Aggregations

StepMeta (org.pentaho.di.trans.step.StepMeta)637 TransMeta (org.pentaho.di.trans.TransMeta)228 KettleException (org.pentaho.di.core.exception.KettleException)174 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)167 Test (org.junit.Test)162 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)147 TransHopMeta (org.pentaho.di.trans.TransHopMeta)128 Trans (org.pentaho.di.trans.Trans)119 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)113 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)107 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)106 StepInterface (org.pentaho.di.trans.step.StepInterface)92 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)79 Point (org.pentaho.di.core.gui.Point)79 FormAttachment (org.eclipse.swt.layout.FormAttachment)76 FormData (org.eclipse.swt.layout.FormData)76 FormLayout (org.eclipse.swt.layout.FormLayout)76 Label (org.eclipse.swt.widgets.Label)76 Shell (org.eclipse.swt.widgets.Shell)76 Button (org.eclipse.swt.widgets.Button)75