Search in sources :

Example 36 with StepField

use of org.pentaho.metaverse.api.StepField in project pentaho-metaverse by pentaho.

the class SelectValuesStepAnalyzerTest method testIsPassthrough_onlyDelete.

@Test
public void testIsPassthrough_onlyDelete() throws Exception {
    String[] deleted = new String[] { "first", "last" };
    String[] selected = new String[0];
    SelectMetadataChange[] changed = new SelectMetadataChange[0];
    when(selectValuesMeta.getDeleteName()).thenReturn(deleted);
    when(selectValuesMeta.getSelectName()).thenReturn(selected);
    when(selectValuesMeta.getMeta()).thenReturn(changed);
    StepField stepField = new StepField("previousStep", "first");
    // first was deleted, not a passthrough
    assertFalse(analyzer.isPassthrough(stepField));
    stepField.setFieldName("last");
    // last was deleted, not a passthrough
    assertFalse(analyzer.isPassthrough(stepField));
    stepField.setFieldName("age");
    // age was NOT deleted, it is a passthrough
    assertTrue(analyzer.isPassthrough(stepField));
    stepField.setFieldName("birthday");
    // birthday was NOT deleted, it is a passthrough
    assertTrue(analyzer.isPassthrough(stepField));
}
Also used : StepField(org.pentaho.metaverse.api.StepField) SelectMetadataChange(org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange) Test(org.junit.Test)

Example 37 with StepField

use of org.pentaho.metaverse.api.StepField in project pentaho-metaverse by pentaho.

the class StringOperationsStepAnalyzerTest method testGetUsedFields.

@Test
public void testGetUsedFields() {
    Set<StepField> fields = new HashSet<>();
    fields.add(new StepField("prev", "firstName"));
    fields.add(new StepField("prev", "middleName"));
    fields.add(new StepField("prev", "lastName"));
    doReturn(fields).when(analyzer).createStepFields(anyString(), any(StepNodes.class));
    Set<StepField> usedFields = analyzer.getUsedFields(stringOperationsMeta);
    List<String> inFields = Arrays.asList(stringOperationsMeta.getFieldInStream());
    // This test class uses all incoming fields
    for (StepField usedField : usedFields) {
        assertTrue(inFields.contains(usedField.getFieldName()));
    }
}
Also used : StepField(org.pentaho.metaverse.api.StepField) Matchers.anyString(org.mockito.Matchers.anyString) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 38 with StepField

use of org.pentaho.metaverse.api.StepField in project pentaho-metaverse by pentaho.

the class StringsCutStepAnalyzerTest method testGetUsedFields.

@Test
public void testGetUsedFields() {
    Set<StepField> fields = new HashSet<>();
    fields.add(new StepField("prev", "firstName"));
    fields.add(new StepField("prev", "middleName"));
    fields.add(new StepField("prev", "lastName"));
    doReturn(fields).when(analyzer).createStepFields(anyString(), any(StepNodes.class));
    Set<StepField> usedFields = analyzer.getUsedFields(stringsCutMeta);
    List<String> inFields = Arrays.asList(stringsCutMeta.getFieldInStream());
    // This test class uses all incoming fields
    for (StepField usedField : usedFields) {
        assertTrue(inFields.contains(usedField.getFieldName()));
    }
}
Also used : StepField(org.pentaho.metaverse.api.StepField) Matchers.anyString(org.mockito.Matchers.anyString) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 39 with StepField

use of org.pentaho.metaverse.api.StepField in project pentaho-metaverse by pentaho.

the class StringsReplaceStepAnalyzerTest method setUp.

@Before
public void setUp() throws Exception {
    when(stringsReplaceMeta.getFieldInStream()).thenReturn(new String[] { "firstName", "middleName", "lastName" });
    when(stringsReplaceMeta.getFieldOutStream()).thenReturn(new String[] { "", "MN", "lastName" });
    when(stringsReplaceMeta.getFieldReplaceByString()).thenReturn(new String[] { "Tom", "Dick", "Harry" });
    when(stringsReplaceMeta.getReplaceString()).thenReturn(new String[] { "Bill", "Steve", "Jeff" });
    analyzer = spy(new StringsReplaceStepAnalyzer());
    stepFields = new HashSet<>();
    stepFields.add(new StepField("prev", "firstName"));
    stepFields.add(new StepField("prev", "middleName"));
    stepFields.add(new StepField("prev", "lastName"));
    StepNodes stepNodes = mock(StepNodes.class);
    when(stepNodes.findNodes(anyString())).thenAnswer(new Answer<List<IMetaverseNode>>() {

        @Override
        public List<IMetaverseNode> answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            List<IMetaverseNode> foundNodes = new ArrayList<>();
            String fieldName = (String) args[0];
            if (fieldName.equals("firstName") || fieldName.equals("middleName") || fieldName.equals("lastName")) {
                foundNodes.add(mock(IMetaverseNode.class));
            }
            return foundNodes;
        }
    });
    when(analyzer.getInputs()).thenReturn(stepNodes);
    doReturn(stepFields).when(analyzer).createStepFields(anyString(), any(StepNodes.class));
    // Call customAnalyze() for coverage, it does nothing
    analyzer.customAnalyze(stringsReplaceMeta, mock(IMetaverseNode.class));
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) StepField(org.pentaho.metaverse.api.StepField) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) Before(org.junit.Before)

Example 40 with StepField

use of org.pentaho.metaverse.api.StepField in project pentaho-metaverse by pentaho.

the class TextFileInputStepAnalyzerTest method testGetUsedFields_fileNameFromField.

@Test
public void testGetUsedFields_fileNameFromField() throws Exception {
    when(meta.isAcceptingFilenames()).thenReturn(true);
    when(meta.getAcceptingField()).thenReturn("filename");
    when(meta.getAcceptingStepName()).thenReturn("previousStep");
    Set<StepField> usedFields = analyzer.getUsedFields(meta);
    assertNotNull(usedFields);
    assertEquals(1, usedFields.size());
    StepField used = usedFields.iterator().next();
    assertEquals("previousStep", used.getStepName());
    assertEquals("filename", used.getFieldName());
}
Also used : StepField(org.pentaho.metaverse.api.StepField) Test(org.junit.Test)

Aggregations

StepField (org.pentaho.metaverse.api.StepField)53 Test (org.junit.Test)33 HashSet (java.util.HashSet)23 StepNodes (org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes)11 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)10 ComponentDerivationRecord (org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord)10 Matchers.anyString (org.mockito.Matchers.anyString)6 Before (org.junit.Before)4 SelectMetadataChange (org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange)4 Set (java.util.Set)3 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)3 MetaverseObjectFactory (org.pentaho.metaverse.api.MetaverseObjectFactory)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)2 IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)2 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Graph (com.tinkerpop.blueprints.Graph)1 Vertex (com.tinkerpop.blueprints.Vertex)1