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());
}
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());
}
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);
}
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());
}
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());
}
Aggregations