Search in sources :

Example 21 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class MetaInjectTest method setEntryValue_number.

@Test
public void setEntryValue_number() throws KettleValueException {
    StepInjectionMetaEntry entry = mock(StepInjectionMetaEntry.class);
    doReturn(ValueMetaInterface.TYPE_NUMBER).when(entry).getValueType();
    RowMetaAndData row = createRowMetaAndData(new ValueMetaNumber(TEST_FIELD), new Double(1));
    SourceStepField sourceField = new SourceStepField(TEST_SOURCE_STEP_NAME, TEST_FIELD);
    MetaInject.setEntryValue(entry, row, sourceField);
    verify(entry).setValue(1.0D);
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 22 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class MetaInjectTest method setEntryValue_bignumber.

@Test
public void setEntryValue_bignumber() throws KettleValueException {
    StepInjectionMetaEntry entry = mock(StepInjectionMetaEntry.class);
    doReturn(ValueMetaInterface.TYPE_BIGNUMBER).when(entry).getValueType();
    RowMetaAndData row = createRowMetaAndData(new ValueMetaBigNumber(TEST_FIELD), new BigDecimal(1));
    SourceStepField sourceField = new SourceStepField(TEST_SOURCE_STEP_NAME, TEST_FIELD);
    MetaInject.setEntryValue(entry, row, sourceField);
    verify(entry).setValue(new BigDecimal(1));
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaBigNumber(org.pentaho.di.core.row.value.ValueMetaBigNumber) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) BigDecimal(java.math.BigDecimal) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 23 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class MetaInjectTest method setEntryValue_date.

@Test
public void setEntryValue_date() throws KettleValueException {
    StepInjectionMetaEntry entry = mock(StepInjectionMetaEntry.class);
    doReturn(ValueMetaInterface.TYPE_DATE).when(entry).getValueType();
    RowMetaAndData row = createRowMetaAndData(new ValueMetaDate(TEST_FIELD), null);
    SourceStepField sourceField = new SourceStepField(TEST_SOURCE_STEP_NAME, TEST_FIELD);
    MetaInject.setEntryValue(entry, row, sourceField);
    verify(entry).setValue(null);
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 24 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class MetaInjectTest method injectMetaFromMultipleInputSteps.

@Test
public void injectMetaFromMultipleInputSteps() throws KettleException {
    Map<TargetStepAttribute, SourceStepField> targetSourceMapping = new LinkedHashMap<TargetStepAttribute, SourceStepField>();
    targetSourceMapping.put(new TargetStepAttribute(INJECTOR_STEP_NAME, "DATA_TYPE", true), new SourceStepField("TYPE_INPUT", "col_type"));
    targetSourceMapping.put(new TargetStepAttribute(INJECTOR_STEP_NAME, "NAME", true), new SourceStepField("NAME_INPUT", "col_name"));
    meta.setTargetSourceMapping(targetSourceMapping);
    doReturn(new String[] { "NAME_INPUT", "TYPE_INPUT" }).when(transMeta).getPrevStepNames(any(StepMeta.class));
    RowSet nameInputRowSet = mock(RowSet.class);
    RowMeta nameRowMeta = new RowMeta();
    nameRowMeta.addValueMeta(new ValueMetaString("col_name"));
    doReturn(nameRowMeta).when(nameInputRowSet).getRowMeta();
    doReturn(nameInputRowSet).when(metaInject).findInputRowSet("NAME_INPUT");
    RowSet typeInputRowSet = mock(RowSet.class);
    RowMeta typeRowMeta = new RowMeta();
    typeRowMeta.addValueMeta(new ValueMetaString("col_type"));
    doReturn(typeRowMeta).when(typeInputRowSet).getRowMeta();
    doReturn(typeInputRowSet).when(metaInject).findInputRowSet("TYPE_INPUT");
    doReturn(new Object[] { "FIRST_NAME" }).doReturn(null).when(metaInject).getRowFrom(nameInputRowSet);
    doReturn(new Object[] { "String" }).doReturn(null).when(metaInject).getRowFrom(typeInputRowSet);
    List<StepInjectionMetaEntry> injectionMetaEntryList = new ArrayList<StepInjectionMetaEntry>();
    StepInjectionMetaEntry fields = new StepInjectionMetaEntry("FIELDS", ValueMetaInterface.TYPE_NONE, "");
    StepInjectionMetaEntry fieldEntry = new StepInjectionMetaEntry("FIELD", ValueMetaInterface.TYPE_NONE, "");
    fields.getDetails().add(fieldEntry);
    StepInjectionMetaEntry nameEntry = new StepInjectionMetaEntry("NAME", ValueMetaInterface.TYPE_STRING, "");
    fieldEntry.getDetails().add(nameEntry);
    StepInjectionMetaEntry dataEntry = new StepInjectionMetaEntry("DATA_TYPE", ValueMetaInterface.TYPE_STRING, "");
    fieldEntry.getDetails().add(dataEntry);
    injectionMetaEntryList.add(fields);
    doReturn(injectionMetaEntryList).when(metaInjectionInterface).getStepInjectionMetadataEntries();
    meta.setNoExecution(true);
    assertTrue(metaInject.init(meta, data));
    metaInject.processRow(meta, data);
    StepInjectionMetaEntry expectedNameEntry = new StepInjectionMetaEntry("NAME", "FIRST_NAME", ValueMetaInterface.TYPE_STRING, "");
    StepInjectionMetaEntry expectedDataEntry = new StepInjectionMetaEntry("DATA_TYPE", "String", ValueMetaInterface.TYPE_STRING, "");
    verify(metaInject, atLeastOnce()).setEntryValueIfFieldExists(refEq(expectedNameEntry), any(RowMetaAndData.class), any(SourceStepField.class));
    verify(metaInject, atLeastOnce()).setEntryValueIfFieldExists(refEq(expectedDataEntry), any(RowMetaAndData.class), any(SourceStepField.class));
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) ArrayList(java.util.ArrayList) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) LinkedHashMap(java.util.LinkedHashMap) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 25 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class MetaInjectTest method setEntryValue_string.

@Test
public void setEntryValue_string() throws KettleValueException {
    StepInjectionMetaEntry entry = mock(StepInjectionMetaEntry.class);
    doReturn(ValueMetaInterface.TYPE_STRING).when(entry).getValueType();
    RowMetaAndData row = createRowMetaAndData(new ValueMetaString(TEST_FIELD), TEST_VALUE);
    SourceStepField sourceField = new SourceStepField(TEST_SOURCE_STEP_NAME, TEST_FIELD);
    MetaInject.setEntryValue(entry, row, sourceField);
    verify(entry).setValue(TEST_VALUE);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

StepInjectionMetaEntry (org.pentaho.di.trans.step.StepInjectionMetaEntry)54 ArrayList (java.util.ArrayList)31 Test (org.junit.Test)17 KettleException (org.pentaho.di.core.exception.KettleException)10 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)6 KettleAttributeInterface (org.pentaho.di.core.KettleAttributeInterface)3 TextFileInputField (org.pentaho.di.trans.steps.textfileinput.TextFileInputField)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 ShellEvent (org.eclipse.swt.events.ShellEvent)1