Search in sources :

Example 6 with TestFailedException

use of org.pentaho.di.TestFailedException in project pentaho-kettle by pentaho.

the class TextFileOutputIT method testTextFileOutput6.

/**
 * Tests the normal output capability of the TextFileOutput step
 *
 * @throws Exception
 */
@Test
public void testTextFileOutput6() throws Exception {
    KettleEnvironment.init();
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("testTextFileOutput6");
    PluginRegistry registry = PluginRegistry.getInstance();
    // create an injector step
    String injectorStepName = "injector step";
    StepMeta injectorStep = TestUtilities.createInjectorStep(injectorStepName, registry);
    transMeta.addStep(injectorStep);
    // create a row generator step
    StepMeta rowGeneratorStep = createRowGeneratorStep("Create rows for testTextFileOutput5", registry);
    transMeta.addStep(rowGeneratorStep);
    // create a TransHopMeta for injector and add it to the transMeta
    TransHopMeta hop_injectory_rowGenerator = new TransHopMeta(injectorStep, rowGeneratorStep);
    transMeta.addTransHop(hop_injectory_rowGenerator);
    // create the text file output step with no compression
    // but first lets get a filename
    String textFileName = "testTextFileOutput6";
    String textFileOutputStepName = "text file output step";
    StepMeta textFileOutputStep = createTextFileOutputStep(textFileOutputStepName, textFileName, "None", registry);
    transMeta.addStep(textFileOutputStep);
    // create a TransHopMeta for textFileOutputStep and add it to the transMeta
    TransHopMeta hop_RowGenerator_outputTextFile = new TransHopMeta(rowGeneratorStep, textFileOutputStep);
    transMeta.addTransHop(hop_RowGenerator_outputTextFile);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    // Create a row collector and add it to the dummy step interface
    StepInterface dummyStepInterface = trans.getStepInterface(textFileOutputStepName, 0);
    RowStepCollector dummyRowCollector = new RowStepCollector();
    dummyStepInterface.addRowListener(dummyRowCollector);
    trans.startThreads();
    trans.waitUntilFinished();
    // Compare the results
    List<RowMetaAndData> resultRows = dummyRowCollector.getRowsWritten();
    Object[][] rows = new Object[10][3];
    File f = new File(textFileName + "." + EXTENSION);
    f.deleteOnExit();
    try {
        FileInputStream fin = new FileInputStream(f);
        InputStreamReader xover = new InputStreamReader(fin);
        BufferedReader input = new BufferedReader(xover);
        readData1Rows(rows, input);
        fin.close();
    } catch (IOException e) {
        fail(e.getLocalizedMessage());
    }
    List<RowMetaAndData> outFileRows = createResultDataFromObjects(rows);
    try {
        TestUtilities.checkRows(resultRows, outFileRows);
    } catch (TestFailedException tfe) {
        fail(tfe.getMessage());
    }
}
Also used : TestFailedException(org.pentaho.di.TestFailedException) InputStreamReader(java.io.InputStreamReader) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) IOException(java.io.IOException) StepMeta(org.pentaho.di.trans.step.StepMeta) FileInputStream(java.io.FileInputStream) StepInterface(org.pentaho.di.trans.step.StepInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) BufferedReader(java.io.BufferedReader) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans) ZipFile(java.util.zip.ZipFile) File(java.io.File) Test(org.junit.Test)

Aggregations

TestFailedException (org.pentaho.di.TestFailedException)6 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)6 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)6 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)6 RowStepCollector (org.pentaho.di.trans.RowStepCollector)6 Trans (org.pentaho.di.trans.Trans)6 TransHopMeta (org.pentaho.di.trans.TransHopMeta)6 TransMeta (org.pentaho.di.trans.TransMeta)6 StepInterface (org.pentaho.di.trans.step.StepInterface)6 StepMeta (org.pentaho.di.trans.step.StepMeta)6 Test (org.junit.Test)4 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)4 BufferedReader (java.io.BufferedReader)3 File (java.io.File)3 IOException (java.io.IOException)3 InputStreamReader (java.io.InputStreamReader)3 ZipFile (java.util.zip.ZipFile)3 FileInputStream (java.io.FileInputStream)2 GZIPInputStream (java.util.zip.GZIPInputStream)1 ZipEntry (java.util.zip.ZipEntry)1