Search in sources :

Example 6 with SelectMetadataChange

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));
}
Also used : StepField(org.pentaho.metaverse.api.StepField) SelectMetadataChange(org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange) Test(org.junit.Test)

Example 7 with SelectMetadataChange

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));
}
Also used : StepField(org.pentaho.metaverse.api.StepField) SelectMetadataChange(org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange) Test(org.junit.Test)

Example 8 with SelectMetadataChange

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(",");
}
Also used : SelectMetadataChange(org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) Before(org.junit.Before)

Example 9 with SelectMetadataChange

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());
}
Also used : ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) SelectMetadataChange(org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 10 with SelectMetadataChange

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));
}
Also used : StepField(org.pentaho.metaverse.api.StepField) SelectMetadataChange(org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange) Test(org.junit.Test)

Aggregations

SelectMetadataChange (org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange)13 Test (org.junit.Test)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 StepField (org.pentaho.metaverse.api.StepField)4 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)3 HashSet (java.util.HashSet)2 TableItem (org.eclipse.swt.widgets.TableItem)2 KettleException (org.pentaho.di.core.exception.KettleException)2 TransHopMeta (org.pentaho.di.trans.TransHopMeta)2 TransMeta (org.pentaho.di.trans.TransMeta)2 StepMeta (org.pentaho.di.trans.step.StepMeta)2 SelectValuesMeta (org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta)2 ComponentDerivationRecord (org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord)2 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Before (org.junit.Before)1 Condition (org.pentaho.di.core.Condition)1 Const (org.pentaho.di.core.Const)1 NotePadMeta (org.pentaho.di.core.NotePadMeta)1 Database (org.pentaho.di.core.database.Database)1