use of io.atlasmap.v2.Split in project atlasmap by atlasmap.
the class StringComplexFieldActionsTest method testSplitEscape.
@Test
public void testSplitEscape() {
Split action = new Split();
action.setDelimiter("\\");
assertArrayEquals(null, StringComplexFieldActions.split(action, null));
assertArrayEquals(new String[] { "1", "2", "3" }, StringComplexFieldActions.split(action, "1\\2\\3"));
action.setDelimiter("|");
assertArrayEquals(null, StringComplexFieldActions.split(action, null));
assertArrayEquals(new String[] { "1", "2", "3" }, StringComplexFieldActions.split(action, "1|2|3"));
action.setDelimiter(".");
assertArrayEquals(null, StringComplexFieldActions.split(action, null));
assertArrayEquals(new String[] { "1", "2", "3" }, StringComplexFieldActions.split(action, "1.2.3"));
action.setDelimiter("$");
assertArrayEquals(null, StringComplexFieldActions.split(action, null));
assertArrayEquals(new String[] { "1", "2", "3" }, StringComplexFieldActions.split(action, "1$2$3"));
}
use of io.atlasmap.v2.Split in project atlasmap by atlasmap.
the class StringComplexFieldActionsTest method testSplit.
@Test
public void testSplit() {
Split action = new Split();
action.setDelimiter(",");
assertArrayEquals(null, StringComplexFieldActions.split(action, null));
assertArrayEquals(new String[] { "1", "2", "3" }, StringComplexFieldActions.split(action, "1,2,3"));
}
use of io.atlasmap.v2.Split in project atlasmap by atlasmap.
the class DefaultAtlasPreviewContextTest method testProcessPreviewSplit.
@Test
public void testProcessPreviewSplit() throws AtlasException {
Mapping m = new Mapping();
Field source = new SimpleField();
source.setFieldType(FieldType.STRING);
source.setPath("/source");
source.setValue("one two three four");
source.setActions(new ArrayList<>());
Split action = new Split();
action.setDelimiter(" ");
source.getActions().add(action);
m.getInputField().add(source);
Field target1 = new SimpleField();
target1.setPath("/target1");
target1.setIndex(0);
target1.setFieldType(FieldType.STRING);
m.getOutputField().add(target1);
Field target2 = new SimpleField();
target2.setPath("/target2");
target2.setIndex(1);
target2.setFieldType(FieldType.STRING);
m.getOutputField().add(target2);
Field target3 = new SimpleField();
target3.setPath("/target3");
target3.setIndex(3);
target3.setFieldType(FieldType.STRING);
m.getOutputField().add(target3);
Audits audits = previewContext.processPreview(m);
assertEquals(0, audits.getAudit().size(), printAudit(audits));
target1 = m.getOutputField().get(0);
target2 = m.getOutputField().get(1);
target3 = m.getOutputField().get(2);
assertEquals("one", target1.getValue());
assertEquals("two", target2.getValue());
assertEquals("four", target3.getValue());
}
use of io.atlasmap.v2.Split in project atlasmap by atlasmap.
the class DefaultAtlasPreviewContextTest method testProcessPreviewSplitCollection.
@Test
public void testProcessPreviewSplitCollection() throws AtlasException {
Mapping m = new Mapping();
Field source = new SimpleField();
source.setFieldType(FieldType.STRING);
source.setPath("/source");
source.setValue("one two three four");
source.setActions(new ArrayList<>());
Split action = new Split();
action.setDelimiter(" ");
source.getActions().add(action);
m.getInputField().add(source);
Field target = new SimpleField();
target.setCollectionType(CollectionType.LIST);
target.setFieldType(FieldType.STRING);
target.setPath("/results<>");
m.getOutputField().add(target);
Audits audits = previewContext.processPreview(m);
assertEquals(0, audits.getAudit().size(), printAudit(audits));
target = m.getOutputField().get(0);
assertEquals(FieldGroup.class, target.getClass());
FieldGroup targetGroup = (FieldGroup) target;
Field one = targetGroup.getField().get(0);
Field two = targetGroup.getField().get(1);
Field three = targetGroup.getField().get(2);
Field four = targetGroup.getField().get(3);
assertEquals("/results<0>", one.getPath());
assertEquals("one", one.getValue());
assertEquals("/results<1>", two.getPath());
assertEquals("two", two.getValue());
assertEquals("/results<2>", three.getPath());
assertEquals("three", three.getValue());
assertEquals("/results<3>", four.getPath());
assertEquals("four", four.getValue());
target = new SimpleField();
target.setCollectionType(CollectionType.NONE);
target.setPath("/collection<>/result");
target.setFieldType(FieldType.STRING);
target.setIndex(0);
m.getOutputField().clear();
m.getOutputField().add(target);
audits = previewContext.processPreview(m);
assertEquals(0, audits.getAudit().size(), printAudit(audits));
target = m.getOutputField().get(0);
assertEquals(FieldGroup.class, target.getClass());
targetGroup = (FieldGroup) target;
one = targetGroup.getField().get(0);
two = targetGroup.getField().get(1);
three = targetGroup.getField().get(2);
four = targetGroup.getField().get(3);
assertEquals("/collection<0>/result", one.getPath());
assertEquals("one", one.getValue());
assertEquals("/collection<1>/result", two.getPath());
assertEquals("two", two.getValue());
assertEquals("/collection<2>/result", three.getPath());
assertEquals("three", three.getValue());
assertEquals("/collection<3>/result", four.getPath());
assertEquals("four", four.getValue());
}
use of io.atlasmap.v2.Split in project atlasmap by atlasmap.
the class JsonValidationServiceMultiplicityTest method testCollectionInTargetFields.
@Test
public void testCollectionInTargetFields() throws Exception {
AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/atlasmapping-multiplicity-transformation-concatenate-split.json");
for (BaseMapping m : mapping.getMappings().getMapping()) {
Mapping entry = (Mapping) m;
if ("split-into-multiple-fields".equals(entry.getId())) {
JsonField f = new JsonField();
f.setCollectionType(CollectionType.LIST);
f.setFieldType(FieldType.STRING);
f.setPath("/targetStringList<>");
entry.getOutputField().add(f);
break;
}
}
validations.addAll(sourceValidationService.validateMapping(mapping));
validations.addAll(targetValidationService.validateMapping(mapping));
assertFalse(validationHelper.hasErrors(), validationHelper.allValidationsToString());
assertFalse(validationHelper.hasWarnings(), validationHelper.allValidationsToString());
assertFalse(validationHelper.hasInfos(), validationHelper.allValidationsToString());
assertEquals(0, validationHelper.getCount());
}
Aggregations