Search in sources :

Example 61 with Field

use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.

the class DefaultAtlasFieldActionsServiceTest method testProcessActionAddDays.

@Test
public void testProcessActionAddDays() throws Exception {
    DefaultAtlasSession session = mock(DefaultAtlasSession.class);
    Field field = new SimpleField();
    field.setFieldType(FieldType.DATE_TIME);
    field.setPath("/date");
    ZonedDateTime now = ZonedDateTime.now();
    field.setValue(now);
    field.setActions(new ArrayList<Action>());
    AddDays action = new AddDays();
    action.setDays(32);
    field.getActions().add(action);
    Field answer = fieldActionsService.processActions(session, field);
    ZonedDateTime expected = now.plusDays(32);
    assertEquals(ZonedDateTime.class, answer.getValue().getClass());
    ZonedDateTime actual = (ZonedDateTime) answer.getValue();
    assertEquals(expected.getYear(), actual.getYear());
    assertEquals(expected.getMonth(), actual.getMonth());
    assertEquals(expected.getDayOfMonth(), actual.getDayOfMonth());
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) Action(io.atlasmap.v2.Action) AddDays(io.atlasmap.v2.AddDays) ZonedDateTime(java.time.ZonedDateTime) SimpleField(io.atlasmap.v2.SimpleField) Test(org.junit.jupiter.api.Test)

Example 62 with Field

use of com.google.firestore.admin.v1.Field 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());
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) Action(io.atlasmap.v2.Action) FieldGroup(io.atlasmap.v2.FieldGroup) Uppercase(io.atlasmap.v2.Uppercase) SimpleField(io.atlasmap.v2.SimpleField) Test(org.junit.jupiter.api.Test)

Example 63 with Field

use of com.google.firestore.admin.v1.Field in project atlasmap by atlasmap.

the class DefaultAtlasContextTest method testProcess.

@Test
public void testProcess() throws AtlasException {
    DefaultAtlasSession session = mock(DefaultAtlasSession.class);
    when(session.getAtlasContext()).thenReturn(context);
    Head head = mock(Head.class);
    when(session.head()).thenReturn(head);
    when(head.setMapping(any(Mapping.class))).thenReturn(head);
    when(head.setLookupTable(any(LookupTable.class))).thenReturn(head);
    Field headField = mock(ConstantField.class);
    when(head.getSourceField()).thenReturn(headField);
    Audits audits = mock(Audits.class);
    when(session.getAudits()).thenReturn(audits);
    Validations validations = mock(Validations.class);
    when(session.getValidations()).thenReturn(validations);
    AtlasMapping mapping = mock(AtlasMapping.class);
    when(session.getMapping()).thenReturn(mapping);
    when(session.hasErrors()).thenReturn(true);
    context.process(session);
    when(session.hasErrors()).thenReturn(false);
    Mappings mappings = mock(Mappings.class);
    when(mapping.getMappings()).thenReturn(mappings);
    List<BaseMapping> baseMappings = new ArrayList<>();
    Collection baseMapping = mock(Collection.class);
    when(baseMapping.getMappingType()).thenReturn(MappingType.COLLECTION);
    baseMappings.add(baseMapping);
    when(mappings.getMapping()).thenReturn(baseMappings);
    Mappings subMappings = mock(Mappings.class);
    when(baseMapping.getMappings()).thenReturn(subMappings);
    List<BaseMapping> baseMappingList = new ArrayList<>();
    Mapping mappingElement1 = mock(Mapping.class);
    List<Field> sourceFieldList = new ArrayList<>();
    ConstantField sourceField = mock(ConstantField.class);
    sourceFieldList.add(sourceField);
    when(sourceField.getPath()).thenReturn("contact.firstName");
    when(mappingElement1.getInputField()).thenReturn(sourceFieldList);
    List<Field> outputFieldList = new ArrayList<>();
    Field outputField = mock(Field.class);
    outputFieldList.add(outputField);
    when(outputField.getPath()).thenReturn("contact.firstName");
    when(mappingElement1.getOutputField()).thenReturn(outputFieldList);
    when(mappingElement1.getMappingType()).thenReturn(MappingType.ALL);
    baseMappingList.add(mappingElement1);
    when(subMappings.getMapping()).thenReturn(baseMappingList);
    Mapping mappingElement2 = mock(Mapping.class);
    when(mappingElement2.getMappingType()).thenReturn(MappingType.ALL);
    baseMappingList.add(mappingElement2);
    List<Field> sourceFieldList2 = new ArrayList<>();
    ConstantField sourceField2 = mock(ConstantField.class);
    sourceFieldList2.add(sourceField2);
    when(sourceField2.getPath()).thenReturn("contact[1]");
    when(mappingElement2.getInputField()).thenReturn(sourceFieldList2);
    ConstantModule mockConstantModule = mock(ConstantModule.class);
    ConstantField clonedField = mock(ConstantField.class);
    when(clonedField.getPath()).thenReturn("cloned[1]");
    when(mockConstantModule.cloneField(any(Field.class))).thenReturn(clonedField);
    List<Field> mockSourceFieldList = new ArrayList<>();
    ConstantField mockSourceField = mock(ConstantField.class);
    mockSourceFieldList.add(mockSourceField);
    when(mockSourceField.getPath()).thenReturn("source[1]");
    when(mappingElement2.getInputField()).thenReturn(mockSourceFieldList);
    List<Field> mockOutputFieldList = new ArrayList<>();
    ConstantField mockOutputField = mock(ConstantField.class);
    mockOutputFieldList.add(mockOutputField);
    when(mockOutputField.getPath()).thenReturn("output[1]");
    when(mappingElement2.getOutputField()).thenReturn(mockOutputFieldList);
    context.getSourceModules().put(AtlasConstants.CONSTANTS_DOCUMENT_ID, mockConstantModule);
    context.getTargetModules().put(AtlasConstants.DEFAULT_TARGET_DOCUMENT_ID, mockConstantModule);
    context.process(session);
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) ConstantField(io.atlasmap.v2.ConstantField) ArrayList(java.util.ArrayList) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Field(io.atlasmap.v2.Field) ConstantField(io.atlasmap.v2.ConstantField) Validations(io.atlasmap.v2.Validations) Audits(io.atlasmap.v2.Audits) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) LookupTable(io.atlasmap.v2.LookupTable) Collection(io.atlasmap.v2.Collection) BaseMapping(io.atlasmap.v2.BaseMapping) Test(org.junit.jupiter.api.Test)

Example 64 with Field

use of com.google.firestore.admin.v1.Field 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 65 with Field

use of com.google.firestore.admin.v1.Field 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)

Aggregations

Field (io.atlasmap.v2.Field)221 FieldGroup (io.atlasmap.v2.FieldGroup)86 Test (org.junit.jupiter.api.Test)67 SimpleField (io.atlasmap.v2.SimpleField)62 Field (org.apache.tapestry5.Field)46 JavaField (io.atlasmap.java.v2.JavaField)45 ArrayList (java.util.ArrayList)42 Mapping (io.atlasmap.v2.Mapping)39 Test (org.testng.annotations.Test)39 AtlasPath (io.atlasmap.core.AtlasPath)29 ConstantField (io.atlasmap.v2.ConstantField)29 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)26 AtlasException (io.atlasmap.api.AtlasException)25 JsonField (io.atlasmap.json.v2.JsonField)25 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)25 PropertyField (io.atlasmap.v2.PropertyField)22 AtlasMapping (io.atlasmap.v2.AtlasMapping)21 KafkaConnectField (io.atlasmap.kafkaconnect.v2.KafkaConnectField)19 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)19 Head (io.atlasmap.spi.AtlasInternalSession.Head)18