use of org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange in project pentaho-metaverse by pentaho.
the class SelectValuesStepAnalyzerTest method testIsPassthrough.
@Test
public void testIsPassthrough() throws Exception {
String[] deleted = new String[] { "first, last" };
String[] selected = new String[] { "age" };
SelectMetadataChange[] changed = new SelectMetadataChange[] { testChange1, testChange2 };
when(selectValuesMeta.getDeleteName()).thenReturn(deleted);
when(selectValuesMeta.getSelectName()).thenReturn(selected);
when(selectValuesMeta.getMeta()).thenReturn(changed);
StepField stepField = new StepField("previousStep", "first");
assertFalse(analyzer.isPassthrough(stepField));
stepField.setFieldName("last");
assertFalse(analyzer.isPassthrough(stepField));
stepField.setFieldName("age");
assertFalse(analyzer.isPassthrough(stepField));
// birthday should not be a passthrough, there are fields "selected"
stepField.setFieldName("birthday");
assertFalse(analyzer.isPassthrough(stepField));
}
use of org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange in project pentaho-metaverse by pentaho.
the class SelectValuesStepAnalyzerTest method testIsPassthrough_deleteAndMeta.
@Test
public void testIsPassthrough_deleteAndMeta() throws Exception {
String[] deleted = new String[] { "first", "age" };
String[] selected = new String[0];
SelectMetadataChange[] changed = new SelectMetadataChange[] { testChange1, testChange2 };
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 not deleted but it is meta-modified, not a passthrough
assertFalse(analyzer.isPassthrough(stepField));
stepField.setFieldName("age");
// age was deleted, it is NOT passthrough
assertFalse(analyzer.isPassthrough(stepField));
stepField.setFieldName("birthday");
// birthday was NOT deleted and not meta-modified, it is a passthrough
assertTrue(analyzer.isPassthrough(stepField));
}
use of org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange in project pentaho-metaverse by pentaho.
the class SelectValuesStepAnalyzerTest method setUp.
@Before
public void setUp() throws Exception {
analyzer = spy(new SelectValuesStepAnalyzer());
analyzer.setParentTransMeta(parentTransMeta);
analyzer.setBaseStepMeta(selectValuesMeta);
doNothing().when(analyzer).validateState(null, selectValuesMeta);
prevFields = new HashMap<>();
prevFields.put("previousStep", rmi);
doReturn(prevFields).when(analyzer).getInputFields(selectValuesMeta);
doReturn("select values").when(analyzer).getStepName();
when(parentTransMeta.getPrevStepNames(analyzer.getStepName())).thenReturn(new String[] { "previousStep" });
inputs = new StepNodes();
inputs.addNode("previousStep", "first", node);
inputs.addNode("previousStep", "last", node);
inputs.addNode("previousStep", "age", node);
inputs.addNode("previousStep", "birthday", node);
doReturn(inputs).when(analyzer).getInputs();
testChange1 = new SelectMetadataChange(selectValuesMeta);
testChange1.setName("first");
testChange1.setCurrencySymbol("~");
testChange1.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
testChange1.setDateFormatLocale("en_UK");
testChange1.setGroupingSymbol("...");
testChange2 = new SelectMetadataChange(selectValuesMeta);
testChange2.setName("last");
testChange2.setRename("last name");
testChange2.setDateFormatLenient(true);
testChange2.setConversionMask("##.#");
testChange2.setDateFormatTimeZone("YYYY-MM-DD");
testChange2.setDecimalSymbol(",");
}
use of org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange in project pentaho-metaverse by pentaho.
the class SelectValuesStepAnalyzerTest method testGetChangeRecords_meta.
@Test
public void testGetChangeRecords_meta() throws Exception {
SelectMetadataChange[] metadataChanges = new SelectMetadataChange[] { testChange1, testChange2 };
when(selectValuesMeta.getMeta()).thenReturn(metadataChanges);
ValueMetaInterface vmiFirst = mock(ValueMetaInterface.class);
ValueMetaInterface vmiLast = mock(ValueMetaInterface.class);
when(rmi.searchValueMeta("first")).thenReturn(vmiFirst);
when(rmi.searchValueMeta("last")).thenReturn(vmiLast);
when(vmiFirst.getName()).thenReturn("first");
when(vmiFirst.getCurrencySymbol()).thenReturn("$");
when(vmiFirst.getStorageType()).thenReturn(ValueMetaInterface.STORAGE_TYPE_NORMAL);
when(vmiLast.getDateFormatLocale()).thenReturn(Locale.US);
when(vmiLast.getGroupingSymbol()).thenReturn(",");
when(vmiLast.getName()).thenReturn("last");
when(vmiLast.getConversionMask()).thenReturn("000.##");
when(vmiLast.getDateFormatTimeZone()).thenReturn(TimeZone.getDefault());
when(vmiLast.getDecimalSymbol()).thenReturn(".");
when(vmiLast.isDateFormatLenient()).thenReturn(false);
Set<ComponentDerivationRecord> changeRecords = analyzer.getChangeRecords(selectValuesMeta);
assertNotNull(changeRecords);
assertEquals(metadataChanges.length, changeRecords.size());
}
use of org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange 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));
}
Aggregations