use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class CsvFieldReaderTest method testWithSimpleDocumentWithoutHeader.
@Test
public void testWithSimpleDocumentWithoutHeader() throws Exception {
CsvConfig csvConfig = new CsvConfig();
CsvFieldReader csvFieldReader = new CsvFieldReader(csvConfig);
csvFieldReader.setDocument(new ByteArrayInputStream("Bob,Smith\nAndrew,Johnson".getBytes()));
AtlasInternalSession session = mock(AtlasInternalSession.class);
when(session.head()).thenReturn(mock(AtlasInternalSession.Head.class));
CsvField csvField = new CsvField();
csvField.setName("1");
csvField.setColumn(1);
csvField.setPath("/<>/1");
when(session.head().getSourceField()).thenReturn(csvField);
Audits audits = new Audits();
when(session.getAudits()).thenReturn(audits);
FieldGroup field = (FieldGroup) csvFieldReader.read(session);
assertEquals(0, audits.getAudit().size());
assertEquals("Smith", field.getField().get(0).getValue());
assertEquals("Johnson", field.getField().get(1).getValue());
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class DefaultAtlasFieldActionsServiceTest method testProcessActionForEachCollectionItem.
@Test
public void testProcessActionForEachCollectionItem() throws Exception {
DefaultAtlasSession session = mock(DefaultAtlasSession.class);
FieldGroup fieldGroup = new FieldGroup();
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 field4 = new SimpleField();
field4.setPath("/fields<3>");
field4.setValue("four");
fieldGroup.getField().add(field4);
Action action = new Uppercase();
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("/fields<0>", f.getPath());
assertEquals("ONE", f.getValue());
f = answerGroup.getField().get(1);
assertEquals("/fields<1>", f.getPath());
assertEquals("TWO", f.getValue());
f = answerGroup.getField().get(2);
assertEquals("/fields<3>", f.getPath());
assertEquals("FOUR", f.getValue());
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class DefaultAtlasExpressionProcessorTest method testCollection.
@Test
public void testCollection() throws Exception {
FieldGroup source = populateCollectionSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, "foo");
String expression = String.format("IF(ISEMPTY(${%s:/testPathfoo<0>}), null, ${%s:/testPathfoo<>})", AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID);
recreateSession();
FieldGroup wrapper = new FieldGroup();
wrapper.getField().add(source);
wrapper.getField().add(source.getField().get(0));
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());
assertEquals("foo0", fieldGroup.getField().get(0).getValue());
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class DefaultAtlasExpressionProcessorTest method testFilter.
@Test
public void testFilter() throws Exception {
FieldGroup source = populateComplexCollectionSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, "foo");
String expression = String.format("FILTER(${%s:/testPathfoo<>}, ${/value} != 'foo1')", 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<>", fieldGroup.getPath());
assertEquals(9, fieldGroup.getField().size());
FieldGroup childFieldGroup = (FieldGroup) fieldGroup.getField().get(0);
assertEquals("/testPathfoo<0>", childFieldGroup.getPath());
assertEquals(1, childFieldGroup.getField().size());
assertEquals("foo0", childFieldGroup.getField().get(0).getValue());
childFieldGroup = (FieldGroup) fieldGroup.getField().get(1);
assertEquals("/testPathfoo<1>", childFieldGroup.getPath());
assertEquals(1, childFieldGroup.getField().size());
assertEquals("foo2", childFieldGroup.getField().get(0).getValue());
}
use of io.atlasmap.v2.FieldGroup in project atlasmap by atlasmap.
the class DefaultAtlasExpressionProcessorTest method testComplexCollection.
@Test
public void testComplexCollection() throws Exception {
populateComplexCollectionSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, "foo");
String expression = String.format("IF(ISEMPTY(${%s:/testPathfoo<0>/value}), null, ${%s:/testPathfoo<>/value})", AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID);
recreateSession();
FieldGroup wrapper = new FieldGroup();
wrapper.getField().add((Field) reader.sources.get("/testPathfoo<0>/value"));
wrapper.getField().add((Field) reader.sources.get("/testPathfoo<>/value"));
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<>/value", fieldGroup.getPath());
assertEquals(10, fieldGroup.getField().size());
Field childField = fieldGroup.getField().get(0);
assertEquals("/testPathfoo<0>/value", childField.getPath());
assertEquals("foo0", childField.getValue());
childField = fieldGroup.getField().get(1);
assertEquals("/testPathfoo<1>/value", childField.getPath());
assertEquals("foo1", childField.getValue());
}
Aggregations