use of io.atlasmap.v2.FieldGroup 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.FieldGroup 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());
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class DefaultAtlasExpressionProcessorTest method testFilterSelect.
@Test
public void testFilterSelect() throws Exception {
FieldGroup source = populateComplexCollectionSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, "foo");
String expression = String.format("SELECT(FILTER(${%s:/testPathfoo<>}, ${/value} != 'foo1'), ${/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(9, 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("foo2", child.getValue());
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class DefaultAtlasExpressionProcessorTest method testRepeatCount.
@Test
public void testRepeatCount() throws Exception {
Field source = populateSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, FieldType.STRING, "foo");
populateComplexCollectionSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, "count");
String expression = String.format("REPEAT(COUNT(${%s:/testPathcount<>/value}), ${%s:/testPathfoo})", AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID);
recreateSession();
FieldGroup wrapper = new FieldGroup();
wrapper.getField().add((Field) reader.sources.get("/testPathcount<>/value"));
wrapper.getField().add(source);
session.head().setSourceField(wrapper);
DefaultAtlasExpressionProcessor.processExpression(session, expression);
assertFalse(session.hasErrors(), printAudit(session));
assertEquals(FieldGroup.class, session.head().getSourceField().getClass());
FieldGroup fieldGroup = (FieldGroup) session.head().getSourceField();
assertEquals("/testPathfoo<>", fieldGroup.getPath());
assertEquals(10, fieldGroup.getField().size());
Field child = fieldGroup.getField().get(0);
assertEquals("/testPathfoo<0>", child.getPath());
assertNull(child.getIndex());
assertEquals("foo", child.getValue());
child = fieldGroup.getField().get(1);
assertEquals("/testPathfoo<1>", child.getPath());
assertNull(child.getIndex());
assertEquals("foo", child.getValue());
child = fieldGroup.getField().get(9);
assertEquals("/testPathfoo<9>", child.getPath());
assertNull(child.getIndex());
assertEquals("foo", child.getValue());
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class DefaultAtlasPreviewContextTest method testProcessPreviewSplitCollection.
@Test
public void testProcessPreviewSplitCollection() throws AtlasException {
Mapping m = new Mapping();
Field source = new SimpleField();
source.setFieldType(FieldType.STRING);
source.setPath("/source");
source.setValue("one two three four");
source.setActions(new ArrayList<>());
Split action = new Split();
action.setDelimiter(" ");
source.getActions().add(action);
m.getInputField().add(source);
Field target = new SimpleField();
target.setCollectionType(CollectionType.LIST);
target.setFieldType(FieldType.STRING);
target.setPath("/results<>");
m.getOutputField().add(target);
Audits audits = previewContext.processPreview(m);
assertEquals(0, audits.getAudit().size(), printAudit(audits));
target = m.getOutputField().get(0);
assertEquals(FieldGroup.class, target.getClass());
FieldGroup targetGroup = (FieldGroup) target;
Field one = targetGroup.getField().get(0);
Field two = targetGroup.getField().get(1);
Field three = targetGroup.getField().get(2);
Field four = targetGroup.getField().get(3);
assertEquals("/results<0>", one.getPath());
assertEquals("one", one.getValue());
assertEquals("/results<1>", two.getPath());
assertEquals("two", two.getValue());
assertEquals("/results<2>", three.getPath());
assertEquals("three", three.getValue());
assertEquals("/results<3>", four.getPath());
assertEquals("four", four.getValue());
target = new SimpleField();
target.setCollectionType(CollectionType.NONE);
target.setPath("/collection<>/result");
target.setFieldType(FieldType.STRING);
target.setIndex(0);
m.getOutputField().clear();
m.getOutputField().add(target);
audits = previewContext.processPreview(m);
assertEquals(0, audits.getAudit().size(), printAudit(audits));
target = m.getOutputField().get(0);
assertEquals(FieldGroup.class, target.getClass());
targetGroup = (FieldGroup) target;
one = targetGroup.getField().get(0);
two = targetGroup.getField().get(1);
three = targetGroup.getField().get(2);
four = targetGroup.getField().get(3);
assertEquals("/collection<0>/result", one.getPath());
assertEquals("one", one.getValue());
assertEquals("/collection<1>/result", two.getPath());
assertEquals("two", two.getValue());
assertEquals("/collection<2>/result", three.getPath());
assertEquals("three", three.getValue());
assertEquals("/collection<3>/result", four.getPath());
assertEquals("four", four.getValue());
}
Aggregations