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));
}
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()));
}
}
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()));
}
}
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));
}
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());
}
Aggregations