Search in sources :

Example 1 with ConvertMassUnit

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));
}
Also used : ConvertMassUnit(io.atlasmap.v2.ConvertMassUnit) Test(org.junit.Test)

Example 2 with ConvertMassUnit

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());
}
Also used : ConvertMassUnit(io.atlasmap.v2.ConvertMassUnit) Test(org.junit.Test)

Example 3 with ConvertMassUnit

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);
}
Also used : ConvertMassUnit(io.atlasmap.v2.ConvertMassUnit) MassUnitType(io.atlasmap.v2.MassUnitType) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Example 4 with ConvertMassUnit

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));
}
Also used : ConvertMassUnit(io.atlasmap.v2.ConvertMassUnit) Test(org.junit.Test)

Example 5 with ConvertMassUnit

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));
}
Also used : ConvertMassUnit(io.atlasmap.v2.ConvertMassUnit) Test(org.junit.Test)

Aggregations

ConvertMassUnit (io.atlasmap.v2.ConvertMassUnit)5 Test (org.junit.Test)4 AtlasFieldActionInfo (io.atlasmap.spi.AtlasFieldActionInfo)1 MassUnitType (io.atlasmap.v2.MassUnitType)1