Search in sources :

Example 26 with Expression

use of io.atlasmap.v2.Expression 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());
}
Also used : FieldGroup(io.atlasmap.v2.FieldGroup) Test(org.junit.jupiter.api.Test)

Example 27 with Expression

use of io.atlasmap.v2.Expression 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());
}
Also used : FieldGroup(io.atlasmap.v2.FieldGroup) Test(org.junit.jupiter.api.Test)

Example 28 with Expression

use of io.atlasmap.v2.Expression in project atlasmap by atlasmap.

the class DefaultAtlasExpressionProcessorTest method testBoolean.

@Test
public void testBoolean() throws AtlasException {
    Field source = populateSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, FieldType.BOOLEAN, true);
    String expression = String.format("IF (${%s:/testPathtrue}, 'YES', 'NO')", AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID);
    recreateSession();
    session.head().setSourceField(source);
    DefaultAtlasExpressionProcessor.processExpression(session, expression);
    assertFalse(session.hasErrors(), printAudit(session));
    assertEquals("YES", session.head().getSourceField().getValue());
    source = populateSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, FieldType.BOOLEAN, true);
    expression = String.format("IF (${%s:/testPathtrue} == true, 'YES', 'NO')", AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID);
    recreateSession();
    session.head().setSourceField(source);
    DefaultAtlasExpressionProcessor.processExpression(session, expression);
    assertFalse(session.hasErrors(), printAudit(session));
    assertEquals("YES", session.head().getSourceField().getValue());
    source = populateSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, FieldType.BOOLEAN, Boolean.valueOf(true));
    expression = String.format("IF (${%s:/testPathtrue}, 'YES', 'NO')", AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID);
    recreateSession();
    session.head().setSourceField(source);
    DefaultAtlasExpressionProcessor.processExpression(session, expression);
    assertFalse(session.hasErrors(), printAudit(session));
    assertEquals("YES", session.head().getSourceField().getValue());
    source = populateSourceField(null, AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, FieldType.BOOLEAN, Boolean.valueOf(true));
    expression = String.format("IF (${%s:/testPathtrue} == true, 'YES', 'NO')", AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID);
    recreateSession();
    session.head().setSourceField(source);
    DefaultAtlasExpressionProcessor.processExpression(session, expression);
    assertFalse(session.hasErrors(), printAudit(session));
    assertEquals("YES", session.head().getSourceField().getValue());
}
Also used : PropertyField(io.atlasmap.v2.PropertyField) Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) Test(org.junit.jupiter.api.Test)

Example 29 with Expression

use of io.atlasmap.v2.Expression 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());
}
Also used : PropertyField(io.atlasmap.v2.PropertyField) Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) FieldGroup(io.atlasmap.v2.FieldGroup) Test(org.junit.jupiter.api.Test)

Example 30 with Expression

use of io.atlasmap.v2.Expression in project atlasmap by atlasmap.

the class DefaultAtlasExpressionProcessorTest method testScopedProperty.

@Test
public void testScopedProperty() throws Exception {
    FieldGroup source = new FieldGroup();
    PropertyField doc1Prop = new PropertyField();
    doc1Prop.setDocId("DOC.Properties.85731");
    doc1Prop.setScope("Doc1");
    doc1Prop.setPath("/Doc1/testprop");
    doc1Prop.setName("testprop");
    doc1Prop.setValue("doc1prop");
    source.getField().add(doc1Prop);
    PropertyField doc2Prop = new PropertyField();
    doc2Prop.setDocId("DOC.Properties.85731");
    doc2Prop.setScope("Doc2");
    doc2Prop.setPath("/Doc2/testprop");
    doc2Prop.setName("testprop");
    doc2Prop.setValue("doc2prop");
    source.getField().add(doc2Prop);
    PropertyField currentProp = new PropertyField();
    currentProp.setDocId("DOC.Properties.85731");
    currentProp.setPath("/testprop");
    currentProp.setName("testprop");
    currentProp.setValue("currentprop");
    source.getField().add(currentProp);
    String expression = "${DOC.Properties.85731:/Doc1/testprop} + ${DOC.Properties.85731:/Doc2/testprop}" + " + ${DOC.Properties.85731:/testprop}";
    recreateSession();
    context.getSourceModules().put(AtlasConstants.PROPERTIES_SOURCE_DOCUMENT_ID, new PropertyModule(new DefaultAtlasPropertyStrategy()));
    session.head().setSourceField(source);
    DefaultAtlasExpressionProcessor.processExpression(session, expression);
    assertFalse(session.hasErrors(), printAudit(session));
    assertEquals(SimpleField.class, session.head().getSourceField().getClass());
    SimpleField field = (SimpleField) session.head().getSourceField();
    assertEquals("$ATLASMAP", field.getPath());
    assertEquals("doc1propdoc2propcurrentprop", field.getValue());
}
Also used : PropertyField(io.atlasmap.v2.PropertyField) FieldGroup(io.atlasmap.v2.FieldGroup) SimpleField(io.atlasmap.v2.SimpleField) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)34 Expression (org.apache.commons.jexl2.Expression)28 Expression (io.atlasmap.v2.Expression)26 JexlContext (org.apache.commons.jexl2.JexlContext)25 JexlEngine (org.apache.commons.jexl2.JexlEngine)22 Field (io.atlasmap.v2.Field)21 FieldGroup (io.atlasmap.v2.FieldGroup)20 MapContext (org.apache.commons.jexl2.MapContext)20 SimpleField (io.atlasmap.v2.SimpleField)16 Test (org.testng.annotations.Test)13 PropertyField (io.atlasmap.v2.PropertyField)9 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)7 Expression (org.eclipse.xtext.resource.bug385636.Expression)7 Expression (org.kie.workbench.common.dmn.api.definition.v1_1.Expression)7 Expression (io.atlasmap.expression.Expression)6 ArrayList (java.util.ArrayList)6 List (java.util.List)5 ParseException (io.atlasmap.expression.parser.ParseException)4 Action (io.atlasmap.v2.Action)4 InformationItem (org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem)4