use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class XmlFieldReaderTest method testReadParentCollectionEmptyItem.
@Test
public void testReadParentCollectionEmptyItem() throws Exception {
final Document document = getDocumentFromFile("src/test/resources/complex-repeated-empty-item.xml", false);
reader.setDocument(document);
FieldGroup orders = new FieldGroup();
orders.setFieldType(FieldType.COMPLEX);
orders.setDocId("xml");
orders.setPath("/orders/order[]");
orders.setCollectionType(CollectionType.ARRAY);
FieldGroup address = new FieldGroup();
address.setFieldType(FieldType.COMPLEX);
address.setDocId("xml");
address.setPath("/orders/order[]/address");
orders.getField().add(address);
XmlField addressLine1 = AtlasXmlModelFactory.createXmlField();
addressLine1.setFieldType(FieldType.STRING);
addressLine1.setDocId("xml");
addressLine1.setPath("/orders/order[]/address/addressLine1");
address.getField().add(addressLine1);
AtlasInternalSession session = mock(AtlasInternalSession.class);
when(session.head()).thenReturn(mock(Head.class));
when(session.head().getSourceField()).thenReturn(address);
Field readField = reader.read(session);
assertNotNull(readField);
assertEquals(FieldGroup.class, readField.getClass());
FieldGroup readGroup = FieldGroup.class.cast(readField);
assertEquals(2, readGroup.getField().size());
FieldGroup address0 = (FieldGroup) readGroup.getField().get(0);
assertEquals("/orders/order[0]/address", address0.getPath());
assertEquals(1, address0.getField().size());
Field addressLine0 = (Field) address0.getField().get(0);
assertEquals("/orders/order[0]/address/addressLine1", addressLine0.getPath());
assertEquals("123 Main St (1)", addressLine0.getValue());
FieldGroup address2 = (FieldGroup) readGroup.getField().get(1);
assertEquals("/orders/order[2]/address", address2.getPath());
assertEquals(1, address2.getField().size());
Field addressLine2 = (Field) address2.getField().get(0);
assertEquals("/orders/order[2]/address/addressLine1", addressLine2.getPath());
assertEquals("123 Main St (3)", addressLine2.getValue());
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class BaseDefaultAtlasContextTest method populateComplexCollectionSourceField.
protected FieldGroup populateComplexCollectionSourceField(Mapping mapping, String docId, String seed) {
String basePath = "/testPath" + seed;
FieldGroup fieldGroup = new FieldGroup();
fieldGroup.setFieldType(FieldType.COMPLEX);
fieldGroup.setDocId(docId);
fieldGroup.setPath(basePath + "<>");
if (mapping != null) {
mapping.setInputFieldGroup(fieldGroup);
}
List<Field> terminals = new ArrayList<>();
for (int i = 0; i < 10; i++) {
FieldGroup child = new FieldGroup();
child.setFieldType(FieldType.COMPLEX);
child.setDocId(docId);
child.setPath(basePath + "<" + i + ">");
child.setIndex(i);
Field terminal = new SimpleField();
terminal.setFieldType(FieldType.STRING);
terminal.setDocId(docId);
terminal.setPath(basePath + "<" + i + ">/value");
terminal.setValue(seed + i);
child.getField().add(terminal);
reader.sources.put(terminal.getPath(), terminal.getValue());
fieldGroup.getField().add(child);
reader.sources.put(child.getPath(), child);
reader.sources.put(terminal.getPath(), terminal);
terminals.add(terminal);
}
reader.sources.put(fieldGroup.getPath(), fieldGroup);
FieldGroup valueGroup = AtlasModelFactory.copyFieldGroup(fieldGroup);
valueGroup.getField().addAll(terminals);
valueGroup.setPath(fieldGroup.getPath() + "/value");
reader.sources.put(valueGroup.getPath(), valueGroup);
return fieldGroup;
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class DefaultAtlasFieldActionsServiceTest method testProcessOldExpressionActionWithoutRoot.
@Test
public void testProcessOldExpressionActionWithoutRoot() throws Exception {
DefaultAtlasSession session = mock(DefaultAtlasSession.class);
FieldGroup fieldGroup = new 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})");
fieldGroup.setActions(new ArrayList<Action>());
fieldGroup.getActions().add(action);
Field answer = fieldActionsService.processActions(session, fieldGroup);
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.FieldGroup 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.FieldGroup 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());
}
Aggregations