use of io.atlasmap.v2.ConvertMassUnit in project atlasmap by atlasmap.
the class NumberFieldActionsTest method testConvertMassUnitErrorNoFromNorToSpecified.
@Test(expected = IllegalArgumentException.class)
public void testConvertMassUnitErrorNoFromNorToSpecified() {
ConvertMassUnit action = new ConvertMassUnit();
assertEquals(11, NumberFieldActions.convertMassUnit(action, 5));
}
use of io.atlasmap.v2.ConvertMassUnit in project atlasmap by atlasmap.
the class NumberFieldActionsTest method testConvertMassUnit.
@Test
public void testConvertMassUnit() {
ConvertMassUnit action = new ConvertMassUnit();
action.setFromUnit(MassUnitType.KILO_GRAM);
action.setToUnit(MassUnitType.POUND);
assertEquals(11, NumberFieldActions.convertMassUnit(action, 5).intValue());
action.setFromUnit(MassUnitType.POUND);
action.setToUnit(MassUnitType.KILO_GRAM);
assertEquals(4.5359235f, NumberFieldActions.convertMassUnit(action, 10.0f).floatValue(), 0);
assertEquals(0, NumberFieldActions.convertMassUnit(action, null).intValue());
}
use of io.atlasmap.v2.ConvertMassUnit in project atlasmap by atlasmap.
the class NumberFieldActions method convertMassUnit.
@AtlasFieldActionInfo(name = "ConvertMassUnit", sourceType = FieldType.NUMBER, targetType = FieldType.NUMBER, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static Number convertMassUnit(Action action, Number input) {
if (input == null) {
return 0;
}
if (action == null || !(action instanceof ConvertMassUnit) || ((ConvertMassUnit) action).getFromUnit() == null || ((ConvertMassUnit) action).getToUnit() == null) {
throw new IllegalArgumentException("ConvertMassUnit must be specfied with fromUnit and toUnit");
}
MassUnitType fromUnit = ((ConvertMassUnit) action).getFromUnit();
MassUnitType toUnit = ((ConvertMassUnit) action).getToUnit();
double rate = massConvertionTable.get(fromUnit).get(toUnit);
return doMultiply(input, rate);
}
use of io.atlasmap.v2.ConvertMassUnit in project atlasmap by atlasmap.
the class NumberFieldActionsTest method testConvertMassUnitErrorNoFromSpecified.
@Test(expected = IllegalArgumentException.class)
public void testConvertMassUnitErrorNoFromSpecified() {
ConvertMassUnit action = new ConvertMassUnit();
action.setToUnit(MassUnitType.POUND);
assertEquals(11, NumberFieldActions.convertMassUnit(action, 5));
}
use of io.atlasmap.v2.ConvertMassUnit in project atlasmap by atlasmap.
the class NumberFieldActionsTest method testConvertMassUnitErrorNoToSpecified.
@Test(expected = IllegalArgumentException.class)
public void testConvertMassUnitErrorNoToSpecified() {
ConvertMassUnit action = new ConvertMassUnit();
action.setFromUnit(MassUnitType.KILO_GRAM);
assertEquals(11, NumberFieldActions.convertMassUnit(action, 5));
}
Aggregations