use of io.atlasmap.v2.Expression in project atlasmap by atlasmap.
the class DefaultAtlasFieldActionsServiceTest method testProcessOldExpressionActionWithRoot.
@Test
public void testProcessOldExpressionActionWithRoot() throws Exception {
DefaultAtlasSession session = mock(DefaultAtlasSession.class);
FieldGroup root = new FieldGroup();
FieldGroup fieldGroup = new FieldGroup();
root.getField().add(fieldGroup);
fieldGroup.setPath("/fields<>");
fieldGroup.setCollectionType(CollectionType.LIST);
Field field1 = new SimpleField();
field1.setPath("/fields<0>");
field1.setValue("one");
fieldGroup.getField().add(field1);
Field field2 = new SimpleField();
field2.setPath("/fields<1>");
field2.setValue("two");
fieldGroup.getField().add(field2);
Field field3 = new SimpleField();
field3.setPath("/fields<3>");
field3.setValue("four");
fieldGroup.getField().add(field3);
Expression action = new Expression();
action.setExpression("capitalize(${0})");
root.setActions(new ArrayList<Action>());
root.getActions().add(action);
Field answer = fieldActionsService.processActions(session, root);
assertEquals(FieldGroup.class, answer.getClass());
FieldGroup answerGroup = (FieldGroup) answer;
assertEquals(3, answerGroup.getField().size());
Field f = answerGroup.getField().get(0);
assertEquals("/$ATLASMAP<0>", f.getPath());
assertEquals("One", f.getValue());
f = answerGroup.getField().get(1);
assertEquals("/$ATLASMAP<1>", f.getPath());
assertEquals("Two", f.getValue());
f = answerGroup.getField().get(2);
assertEquals("/$ATLASMAP<2>", f.getPath());
assertEquals("Four", f.getValue());
}
use of io.atlasmap.v2.Expression in project atlasmap by atlasmap.
the class DefaultAtlasFieldActionsServiceTest method testProcessOldExpressionActionConcatenateTwoCollections.
@Test
public void testProcessOldExpressionActionConcatenateTwoCollections() throws Exception {
DefaultAtlasSession session = mock(DefaultAtlasSession.class);
Field delimiter = new SimpleField();
delimiter.setPath("/delim");
delimiter.setValue("-");
FieldGroup list = new FieldGroup();
list.setPath("/fields<>");
list.setCollectionType(CollectionType.LIST);
Field field1 = new SimpleField();
field1.setPath("/fields<0>");
field1.setValue("one");
list.getField().add(field1);
Field field2 = new SimpleField();
field2.setPath("/fields<1>");
field2.setValue("two");
list.getField().add(field2);
Field field3 = new SimpleField();
field3.setPath("/fields<2>");
field3.setValue("three");
list.getField().add(field3);
FieldGroup list2 = new FieldGroup();
list2.setPath("/fields2<>");
list2.setCollectionType(CollectionType.LIST);
Field field21 = new SimpleField();
field21.setPath("/fields2<0>");
field21.setValue("one");
list2.getField().add(field21);
Field field22 = new SimpleField();
field22.setPath("/fields2<1>");
field22.setValue("two");
list2.getField().add(field22);
Field field23 = new SimpleField();
field23.setPath("/fields2<2>");
field23.setValue("three");
list2.getField().add(field23);
FieldGroup fieldGroup = new FieldGroup();
fieldGroup.getField().add(delimiter);
fieldGroup.getField().add(list);
fieldGroup.getField().add(list2);
Expression action = new Expression();
action.setExpression("concatenate(${0}, true, ${1}, ${2})");
fieldGroup.setActions(new ArrayList<Action>());
fieldGroup.getActions().add(action);
Field answer = fieldActionsService.processActions(session, fieldGroup);
assertEquals("$ATLASMAP", answer.getPath());
assertEquals("one-two-three-one-two-three", answer.getValue());
}
use of io.atlasmap.v2.Expression in project atlasmap by atlasmap.
the class DefaultAtlasFieldActionsServiceTest method testProcessOldExpressionActionConcatenateCollection.
@Test
public void testProcessOldExpressionActionConcatenateCollection() throws Exception {
DefaultAtlasSession session = mock(DefaultAtlasSession.class);
Field delimiter = new SimpleField();
delimiter.setPath("/delim");
delimiter.setValue("-");
FieldGroup list = new FieldGroup();
list.setPath("/fields<>");
list.setCollectionType(CollectionType.LIST);
Field field1 = new SimpleField();
field1.setPath("/fields<0>");
field1.setValue("one");
list.getField().add(field1);
Field field2 = new SimpleField();
field2.setPath("/fields<1>");
field2.setValue("two");
list.getField().add(field2);
Field field3 = new SimpleField();
field3.setPath("/fields<2>");
field3.setValue("three");
list.getField().add(field3);
FieldGroup fieldGroup = new FieldGroup();
fieldGroup.getField().add(delimiter);
fieldGroup.getField().add(list);
Expression action = new Expression();
action.setExpression("concatenate(${0}, true, capitalize(${1}))");
fieldGroup.setActions(new ArrayList<Action>());
fieldGroup.getActions().add(action);
Field answer = fieldActionsService.processActions(session, fieldGroup);
assertEquals("$ATLASMAP", answer.getPath());
assertEquals("One-Two-Three", answer.getValue());
}
use of io.atlasmap.v2.Expression in project atlasmap by atlasmap.
the class DefaultAtlasExpressionProcessorTest method testSingle.
@Test
public void testSingle() throws AtlasException {
Field source = populateSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, FieldType.STRING, "foo");
String expression = String.format("${%s:/testPathfoo}", AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID);
recreateSession();
session.head().setSourceField(source);
DefaultAtlasExpressionProcessor.processExpression(session, expression);
assertFalse(session.hasErrors(), printAudit(session));
assertEquals("foo", session.head().getSourceField().getValue());
}
use of io.atlasmap.v2.Expression in project atlasmap by atlasmap.
the class DefaultAtlasExpressionProcessorTest method testSelect.
@Test
public void testSelect() throws Exception {
FieldGroup source = populateComplexCollectionSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, "foo");
String expression = String.format("SELECT(${%s:/testPathfoo<>}, ${/value})", AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID);
recreateSession();
session.head().setSourceField(source);
DefaultAtlasExpressionProcessor.processExpression(session, expression);
assertFalse(session.hasErrors(), printAudit(session));
assertEquals(FieldGroup.class, session.head().getSourceField().getClass());
FieldGroup fieldGroup = (FieldGroup) session.head().getSourceField();
assertEquals("/testPathfoo<>/value", fieldGroup.getPath());
assertEquals(10, fieldGroup.getField().size());
Field child = fieldGroup.getField().get(0);
assertEquals("/testPathfoo<0>/value", child.getPath());
assertEquals("foo0", child.getValue());
child = fieldGroup.getField().get(1);
assertEquals("/testPathfoo<1>/value", child.getPath());
assertEquals("foo1", child.getValue());
}
Aggregations