Search in sources :

Example 1 with TextFileOutputMeta

use of org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta in project pentaho-kettle by pentaho.

the class TransMetaTest method testGetPreviousStepsWhenStreamLookupStepPassedShouldClearCacheAndCallFindPreviousStepsWithFalseParam.

@Test
public void testGetPreviousStepsWhenStreamLookupStepPassedShouldClearCacheAndCallFindPreviousStepsWithFalseParam() {
    TransMeta transMeta = mock(TransMeta.class);
    StepMeta stepMeta = new StepMeta("stream_lookup_id", "stream_lookup_name", new StreamLookupMeta());
    List<StepMeta> expectedResult = new ArrayList<>();
    List<StepMeta> invalidResult = new ArrayList<>();
    expectedResult.add(new StepMeta("correct_mock", "correct_mock", new TextFileOutputMeta()));
    invalidResult.add(new StepMeta("incorrect_mock", "incorrect_mock", new TextFileOutputMeta()));
    doNothing().when(transMeta).clearPreviousStepCache();
    when(transMeta.findPreviousSteps(any(StepMeta.class), eq(false))).thenReturn(expectedResult);
    when(transMeta.findPreviousSteps(any(StepMeta.class), eq(true))).thenReturn(invalidResult);
    when(transMeta.getPreviousSteps(any())).thenCallRealMethod();
    List<StepMeta> actualResult = transMeta.getPreviousSteps(stepMeta);
    verify(transMeta, times(1)).clearPreviousStepCache();
    assertEquals(expectedResult, actualResult);
}
Also used : TextFileOutputMeta(org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta) StreamLookupMeta(org.pentaho.di.trans.steps.streamlookup.StreamLookupMeta) ArrayList(java.util.ArrayList) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test)

Example 2 with TextFileOutputMeta

use of org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method testTextFileOutputStepNode.

@Test
public void testTextFileOutputStepNode() throws Exception {
    TextFileOutputStepNode textFileOutputStepNode = root.getTextFileOutputStepNode("textFileOutput", "Text file output");
    TextFileOutputMeta meta = (TextFileOutputMeta) getStepMeta(textFileOutputStepNode);
    TransMeta tm = meta.getParentStepMeta().getParentTransMeta();
    String[] fileNames = meta.getFiles(tm);
    RowMetaInterface incomingFields = tm.getPrevStepFields(meta.getParentStepMeta());
    int outputFields = getExpectedOutputFieldCount(meta);
    assertNotNull(textFileOutputStepNode);
    // should write to one file
    Iterable<FramedMetaverseNode> outputFiles = textFileOutputStepNode.getOutputFiles();
    assertEquals(fileNames.length, getIterableSize(outputFiles));
    int i = 0;
    for (FramedMetaverseNode node : outputFiles) {
        assertEquals(normalizeFilePath(fileNames[i++]), normalizeFilePath(node.getName()));
    }
    Iterable<StreamFieldNode> outFields = textFileOutputStepNode.getOutputStreamFields();
    int outFieldCount = getIterableSize(outFields);
    // should have output stream nodes as well as file nodes
    assertEquals(outputFields + meta.getOutputFields().length, outFieldCount);
    int fileFieldCount = 0;
    for (StreamFieldNode outField : outFields) {
        if (DictionaryConst.NODE_TYPE_FILE_FIELD.equals(outField.getType())) {
            ValueMetaInterface vmi = incomingFields.searchValueMeta(outField.getName());
            assertEquals(vmi.getName(), outField.getFieldPopulatesMe().getName());
            fileFieldCount++;
        }
    }
    assertEquals(fileFieldCount, outFieldCount / 2);
}
Also used : TextFileOutputMeta(org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta) TransMeta(org.pentaho.di.trans.TransMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) FramedMetaverseNode(org.pentaho.metaverse.frames.FramedMetaverseNode) TextFileOutputStepNode(org.pentaho.metaverse.frames.TextFileOutputStepNode) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 3 with TextFileOutputMeta

use of org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta in project pentaho-metaverse by pentaho.

the class TextFileOutputExternalResourceConsumer method getResourcesFromRow.

@Override
public Collection<IExternalResourceInfo> getResourcesFromRow(TextFileOutput textFileOutput, RowMetaInterface rowMeta, Object[] row) {
    Collection<IExternalResourceInfo> resources = new LinkedList<IExternalResourceInfo>();
    // For some reason the step doesn't return the StepMetaInterface directly, so go around it
    TextFileOutputMeta meta = (TextFileOutputMeta) textFileOutput.getStepMeta().getStepMetaInterface();
    try {
        TextFileOutputData data = ((TextFileOutputData) textFileOutput.getStepDataInterface());
        String filename = rowMeta.getString(row, meta.getFileNameField(), meta.getFileName());
        if (null != data) {
            // For some reason, the first call to process row doesn't have the data.fileName filled in, so
            // fall back to the filename field value, and then to the meta's filename
            filename = textFileOutput.buildFilename(Const.isEmpty(data.fileName) ? filename : data.fileName, true);
        }
        if (!Const.isEmpty(filename)) {
            FileObject fileObject = KettleVFS.getFileObject(filename);
            resources.add(ExternalResourceInfoFactory.createFileResource(fileObject, false));
        }
    } catch (KettleException kve) {
    // TODO throw exception or ignore?
    }
    return resources;
}
Also used : TextFileOutputMeta(org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta) KettleException(org.pentaho.di.core.exception.KettleException) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) FileObject(org.apache.commons.vfs2.FileObject) LinkedList(java.util.LinkedList) TextFileOutputData(org.pentaho.di.trans.steps.textfileoutput.TextFileOutputData)

Example 4 with TextFileOutputMeta

use of org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta in project pentaho-metaverse by pentaho.

the class MetaverseValidationIT method testTextFileOutputStepNode_FileFromStreamField.

@Test
public void testTextFileOutputStepNode_FileFromStreamField() throws Exception {
    TextFileOutputStepNode textFileOutputStepNode = root.getTextFileOutputStepNode("textFileOutput", "Text file output - file from field");
    TextFileOutputMeta meta = (TextFileOutputMeta) getStepMeta(textFileOutputStepNode);
    TransMeta tm = meta.getParentStepMeta().getParentTransMeta();
    RowMetaInterface incomingFields = tm.getPrevStepFields(meta.getParentStepMeta());
    int outputFields = getExpectedOutputFieldCount(meta);
    assertNotNull(textFileOutputStepNode);
    // should write to one file
    Iterable<FramedMetaverseNode> outputFiles = textFileOutputStepNode.getOutputFiles();
    assertEquals(0, getIterableSize(outputFiles));
    Iterable<StreamFieldNode> usedFields = textFileOutputStepNode.getStreamFieldNodesUses();
    int usedFieldCount = getIterableSize(usedFields);
    assertEquals(1, usedFieldCount);
    Iterable<StreamFieldNode> outFields = textFileOutputStepNode.getOutputStreamFields();
    int outFieldCount = getIterableSize(outFields);
    // should have output stream nodes as well as file nodes
    assertEquals(outputFields + meta.getOutputFields().length, outFieldCount);
    int fileFieldCount = 0;
    for (StreamFieldNode outField : outFields) {
        if (DictionaryConst.NODE_TYPE_FILE_FIELD.equals(outField.getType())) {
            ValueMetaInterface vmi = incomingFields.searchValueMeta(outField.getName());
            assertEquals(vmi.getName(), outField.getFieldPopulatesMe().getName());
            fileFieldCount++;
        }
    }
    assertEquals(fileFieldCount, outFieldCount / 2);
}
Also used : TextFileOutputMeta(org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta) TransMeta(org.pentaho.di.trans.TransMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StreamFieldNode(org.pentaho.metaverse.frames.StreamFieldNode) FramedMetaverseNode(org.pentaho.metaverse.frames.FramedMetaverseNode) TextFileOutputStepNode(org.pentaho.metaverse.frames.TextFileOutputStepNode) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 5 with TextFileOutputMeta

use of org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta in project pentaho-kettle by pentaho.

the class TransMetaTest method testGetPreviousStepsWhenNotStreamLookupStepPassedShouldCallFindPreviousStepsWithTrueParam.

@Test
public void testGetPreviousStepsWhenNotStreamLookupStepPassedShouldCallFindPreviousStepsWithTrueParam() {
    TransMeta transMeta = mock(TransMeta.class);
    StepMeta stepMeta = new StepMeta("not_stream_lookup_id", "not_stream_lookup_name", new TextFileOutputMeta());
    List<StepMeta> expectedResult = new ArrayList<>();
    List<StepMeta> invalidResult = new ArrayList<>();
    expectedResult.add(new StepMeta("correct_mock", "correct_mock", new TextFileOutputMeta()));
    invalidResult.add(new StepMeta("incorrect_mock", "incorrect_mock", new TextFileOutputMeta()));
    doNothing().when(transMeta).clearPreviousStepCache();
    when(transMeta.getPreviousSteps(any())).thenCallRealMethod();
    when(transMeta.findPreviousSteps(any(StepMeta.class))).thenCallRealMethod();
    when(transMeta.findPreviousSteps(any(StepMeta.class), eq(true))).thenReturn(expectedResult);
    when(transMeta.findPreviousSteps(any(StepMeta.class), eq(false))).thenReturn(invalidResult);
    List<StepMeta> actualResult = transMeta.getPreviousSteps(stepMeta);
    verify(transMeta, times(0)).clearPreviousStepCache();
    assertEquals(expectedResult, actualResult);
}
Also used : TextFileOutputMeta(org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta) ArrayList(java.util.ArrayList) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test)

Aggregations

TextFileOutputMeta (org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta)7 Test (org.junit.Test)5 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)4 StepMeta (org.pentaho.di.trans.step.StepMeta)4 ArrayList (java.util.ArrayList)3 KettleException (org.pentaho.di.core.exception.KettleException)2 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)2 TransMeta (org.pentaho.di.trans.TransMeta)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 FileObject (org.apache.commons.vfs2.FileObject)1 CCombo (org.eclipse.swt.custom.CCombo)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 FocusListener (org.eclipse.swt.events.FocusListener)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 ShellAdapter (org.eclipse.swt.events.ShellAdapter)1