use of org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta.SelectField in project pentaho-kettle by pentaho.
the class SelectValuesMetaTest method loadSaveTest.
@Test
public void loadSaveTest() throws KettleException {
List<String> attributes = Arrays.asList("selectFields", "deleteName");
SelectField selectField = new SelectField();
selectField.setName("TEST_NAME");
selectField.setRename("TEST_RENAME");
selectField.setLength(2);
selectField.setPrecision(2);
Map<String, FieldLoadSaveValidator<?>> fieldLoadSaveValidatorTypeMap = new HashMap<String, FieldLoadSaveValidator<?>>();
fieldLoadSaveValidatorTypeMap.put(SelectField[].class.getCanonicalName(), new ArrayLoadSaveValidator<SelectField>(new SelectFieldLoadSaveValidator(selectField), 2));
LoadSaveTester tester = new LoadSaveTester(SelectValuesMeta.class, attributes, new HashMap<String, String>(), new HashMap<String, String>(), new HashMap<String, FieldLoadSaveValidator<?>>(), fieldLoadSaveValidatorTypeMap);
tester.testSerialization();
}
use of org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta.SelectField in project pentaho-kettle by pentaho.
the class SelectValuesTest method testPDI16368.
@Test
public void testPDI16368() throws Exception {
// This tests that the fix for PDI-16388 doesn't get re-broken.
//
SelectValuesHandler step2 = null;
Object[] inputRow2 = null;
RowMeta inputRowMeta = null;
SelectValuesMeta stepMeta = null;
SelectValuesData stepData = null;
ValueMetaInterface vmi = null;
// First, test current behavior (it's worked this way since 5.x or so)
//
step2 = new SelectValuesHandler(helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans);
step2 = spy(step2);
// Starting with a BigDecimal (no places)
inputRow2 = new Object[] { new BigDecimal("589") };
doReturn(inputRow2).when(step2).getRow();
doNothing().when(step2).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), anyString(), anyString());
inputRowMeta = new RowMeta();
inputRowMeta.addValueMeta(new ValueMetaBigNumber(SELECTED_FIELD));
step2.setInputRowMeta(inputRowMeta);
stepMeta = new SelectValuesMeta();
stepMeta.allocate(1, 0, 1);
stepMeta.getSelectFields()[0] = new SelectField();
stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_INTEGER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, // no specified conversion type so should have default conversion mask.
null);
stepData = new SelectValuesData();
stepData.select = true;
stepData.metadata = true;
stepData.firstselect = true;
stepData.firstmetadata = true;
step2.processRow(stepMeta, stepData);
vmi = step2.rowMeta.getValueMeta(0);
assertEquals(ValueMetaBase.DEFAULT_BIG_NUMBER_FORMAT_MASK, vmi.getConversionMask());
step2 = new SelectValuesHandler(helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans);
step2 = spy(step2);
doReturn(inputRow2).when(step2).getRow();
doNothing().when(step2).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), anyString(), anyString());
inputRowMeta = new RowMeta();
inputRowMeta.addValueMeta(new ValueMetaBigNumber(SELECTED_FIELD));
step2.setInputRowMeta(inputRowMeta);
stepMeta = new SelectValuesMeta();
stepMeta.allocate(1, 0, 1);
stepMeta.getSelectFields()[0] = new SelectField();
stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_NUMBER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, // no specified conversion type so should have default conversion mask for Double.
null);
stepData = new SelectValuesData();
stepData.select = true;
stepData.metadata = true;
stepData.firstselect = true;
stepData.firstmetadata = true;
step2.processRow(stepMeta, stepData);
vmi = step2.rowMeta.getValueMeta(0);
assertEquals(ValueMetaBase.DEFAULT_BIG_NUMBER_FORMAT_MASK, vmi.getConversionMask());
step2 = new SelectValuesHandler(helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans);
step2 = spy(step2);
// Starting with a Long
inputRow2 = new Object[] { new Long("589") };
doReturn(inputRow2).when(step2).getRow();
doNothing().when(step2).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), anyString(), anyString());
inputRowMeta = new RowMeta();
inputRowMeta.addValueMeta(new ValueMetaInteger(SELECTED_FIELD));
step2.setInputRowMeta(inputRowMeta);
stepMeta = new SelectValuesMeta();
stepMeta.allocate(1, 0, 1);
stepMeta.getSelectFields()[0] = new SelectField();
stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
// no specified conversion type so should have default conversion mask for BigNumber
stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_BIGNUMBER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, null);
stepData = new SelectValuesData();
stepData.select = true;
stepData.metadata = true;
stepData.firstselect = true;
stepData.firstmetadata = true;
step2.processRow(stepMeta, stepData);
vmi = step2.rowMeta.getValueMeta(0);
assertEquals(ValueMetaBase.DEFAULT_INTEGER_FORMAT_MASK, vmi.getConversionMask());
// Now, test that setting the variable results in getting the default conversion mask
step2 = new SelectValuesHandler(helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans);
step2.setVariable(Const.KETTLE_COMPATIBILITY_SELECT_VALUES_TYPE_CHANGE_USES_TYPE_DEFAULTS, "Y");
step2 = spy(step2);
// Starting with a BigDecimal (no places)
inputRow2 = new Object[] { new BigDecimal("589") };
doReturn(inputRow2).when(step2).getRow();
doNothing().when(step2).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), anyString(), anyString());
inputRowMeta = new RowMeta();
inputRowMeta.addValueMeta(new ValueMetaBigNumber(SELECTED_FIELD));
step2.setInputRowMeta(inputRowMeta);
stepMeta = new SelectValuesMeta();
stepMeta.allocate(1, 0, 1);
stepMeta.getSelectFields()[0] = new SelectField();
stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_INTEGER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, // no specified conversion type so should have default conversion mask.
null);
stepData = new SelectValuesData();
stepData.select = true;
stepData.metadata = true;
stepData.firstselect = true;
stepData.firstmetadata = true;
step2.processRow(stepMeta, stepData);
vmi = step2.rowMeta.getValueMeta(0);
assertEquals(ValueMetaBase.DEFAULT_INTEGER_FORMAT_MASK, vmi.getConversionMask());
step2 = new SelectValuesHandler(helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans);
step2.setVariable(Const.KETTLE_COMPATIBILITY_SELECT_VALUES_TYPE_CHANGE_USES_TYPE_DEFAULTS, "Y");
step2 = spy(step2);
doReturn(inputRow2).when(step2).getRow();
doNothing().when(step2).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), anyString(), anyString());
inputRowMeta = new RowMeta();
inputRowMeta.addValueMeta(new ValueMetaBigNumber(SELECTED_FIELD));
step2.setInputRowMeta(inputRowMeta);
stepMeta = new SelectValuesMeta();
stepMeta.allocate(1, 0, 1);
stepMeta.getSelectFields()[0] = new SelectField();
stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_NUMBER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, // no specified conversion type so should have default conversion mask for Double.
null);
stepData = new SelectValuesData();
stepData.select = true;
stepData.metadata = true;
stepData.firstselect = true;
stepData.firstmetadata = true;
step2.processRow(stepMeta, stepData);
vmi = step2.rowMeta.getValueMeta(0);
assertEquals(ValueMetaBase.DEFAULT_NUMBER_FORMAT_MASK, vmi.getConversionMask());
step2 = new SelectValuesHandler(helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans);
step2.setVariable(Const.KETTLE_COMPATIBILITY_SELECT_VALUES_TYPE_CHANGE_USES_TYPE_DEFAULTS, "Y");
step2 = spy(step2);
// Starting with a Long
inputRow2 = new Object[] { new Long("589") };
doReturn(inputRow2).when(step2).getRow();
doNothing().when(step2).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), anyString(), anyString());
inputRowMeta = new RowMeta();
inputRowMeta.addValueMeta(new ValueMetaInteger(SELECTED_FIELD));
step2.setInputRowMeta(inputRowMeta);
stepMeta = new SelectValuesMeta();
stepMeta.allocate(1, 0, 1);
stepMeta.getSelectFields()[0] = new SelectField();
stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
// no specified conversion type so should have default conversion mask for BigNumber
stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_BIGNUMBER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, null);
stepData = new SelectValuesData();
stepData.select = true;
stepData.metadata = true;
stepData.firstselect = true;
stepData.firstmetadata = true;
step2.processRow(stepMeta, stepData);
vmi = step2.rowMeta.getValueMeta(0);
assertEquals(ValueMetaBase.DEFAULT_BIG_NUMBER_FORMAT_MASK, vmi.getConversionMask());
}
use of org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta.SelectField in project pentaho-kettle by pentaho.
the class SelectValues_LocaleHandling_Test method executeAndCheck.
private void executeAndCheck(String locale, String expectedWeekNumber) throws Exception {
RowMeta inputRowMeta = new RowMeta();
inputRowMeta.addValueMeta(new ValueMetaDate("field"));
step.setInputRowMeta(inputRowMeta);
SelectValuesMeta stepMeta = new SelectValuesMeta();
stepMeta.allocate(1, 0, 1);
stepMeta.getSelectFields()[0] = new SelectField();
stepMeta.getSelectFields()[0].setName("field");
stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, "field", null, ValueMetaInterface.TYPE_STRING, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, "ww", false, locale, null, false, null, null, null);
SelectValuesData stepData = new SelectValuesData();
stepData.select = true;
stepData.metadata = true;
stepData.firstselect = true;
stepData.firstmetadata = true;
List<Object[]> execute = TransTestingUtil.execute(step, stepMeta, stepData, 1, true);
TransTestingUtil.assertResult(execute, Collections.singletonList(new Object[] { expectedWeekNumber }));
}
use of org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta.SelectField in project pentaho-kettle by pentaho.
the class SelectValuesTest method errorRowSetObtainsFieldName.
@Test
public void errorRowSetObtainsFieldName() throws Exception {
SelectValuesMeta stepMeta = new SelectValuesMeta();
stepMeta.allocate(1, 0, 1);
stepMeta.getSelectFields()[0] = new SelectField();
stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_INTEGER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, null);
SelectValuesData stepData = new SelectValuesData();
stepData.select = true;
stepData.metadata = true;
stepData.firstselect = true;
stepData.firstmetadata = true;
step.processRow(stepMeta, stepData);
verify(step).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), eq(SELECTED_FIELD), anyString());
// additionally ensure conversion error causes KettleConversionError
boolean properException = false;
try {
step.metadataValues(step.getInputRowMeta(), inputRow);
} catch (KettleConversionException e) {
properException = true;
}
assertTrue(properException);
}
Aggregations