use of io.atlasmap.v2.Expression in project atlasmap by atlasmap.
the class ExpressionFieldActionTest method testDivide.
@Test
public void testDivide() throws Exception {
Expression action = new Expression();
action.setExpression("${0} / ${1}");
assertEquals(10.0, ExpressionFieldAction.process(action, Arrays.asList(100, 10)));
}
use of io.atlasmap.v2.Expression in project atlasmap by atlasmap.
the class ExpressionFieldActionTest method testOr.
@Test
public void testOr() throws Exception {
Expression action = new Expression();
action.setExpression("IF(${0} == ${1} || ${0} == ${2}, 'some of them are same', 'all different')");
assertEquals("some of them are same", ExpressionFieldAction.process(action, Arrays.asList("foo", "foo", "fo")));
assertEquals("some of them are same", ExpressionFieldAction.process(action, Arrays.asList(1, 1, 2)));
assertEquals("all different", ExpressionFieldAction.process(action, Arrays.asList("foo", "foo0", "fo")));
assertEquals("all different", ExpressionFieldAction.process(action, Arrays.asList(1, 3, 2)));
}
use of io.atlasmap.v2.Expression in project atlasmap by atlasmap.
the class ExpressionFieldActionTest method testConcatenateActionWithMissingArguments.
@Test
public void testConcatenateActionWithMissingArguments() throws Exception {
Expression action = new Expression();
action.setExpression("CONCATENATE(${0}, ${1})");
try {
ExpressionFieldAction.process(action, Arrays.asList(",", true));
fail();
} catch (IllegalArgumentException e) {
assertEquals(IllegalArgumentException.class, e.getClass());
assertEquals("The transformation 'CONCATENATE' expects more arguments", e.getMessage());
}
}
use of io.atlasmap.v2.Expression in project atlasmap by atlasmap.
the class ExpressionFieldActionTest method testConcatenateActionWithDelimiter.
@Test
public void testConcatenateActionWithDelimiter() throws Exception {
Expression action = new Expression();
action.setExpression("CONCATENATE(${0}, ${1}, ${2}, ${3}, ${4})");
assertEquals("a,b,c", ExpressionFieldAction.process(action, Arrays.asList(",", true, "a", "b", "c")));
}
use of io.atlasmap.v2.Expression in project atlasmap by atlasmap.
the class DefaultAtlasFieldActionService method processManyToOne.
private Field processManyToOne(Action action, ActionProcessor processor, FieldType sourceType, Field field) throws AtlasException {
ActionDetail detail = processor.getActionDetail();
List<Object> values = new LinkedList<>();
if (action instanceof Expression) {
// preserve top level list of parameters and arguments
this.extractNestedListValuesForExpressionAction(field, values);
convertCollectionValues(values, detail.getSourceType());
Object out = processor.process(action, values);
return packExpressionActionOutcomeIntoField(out, field);
}
if (field instanceof FieldGroup) {
extractFlatListValuesFromFieldGroup((FieldGroup) field, values);
} else {
Object value = field.getValue();
if (value != null && getConversionService().isAssignableFieldType(detail.getSourceType(), sourceType)) {
value = getConversionService().convertType(value, sourceType, detail.getSourceType());
}
values.add(value);
}
convertCollectionValues(values, detail.getSourceType());
Object out = processor.process(action, values);
field = AtlasModelFactory.cloneFieldToSimpleField(field);
if (out != null) {
field.setFieldType(getConversionService().fieldTypeFromClass(out.getClass()));
field.setValue(out);
}
return field;
}
Aggregations