Search in sources :

Example 1 with Split

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

Example 2 with Split

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

Example 3 with Split

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());
}
Also used : SimpleField(io.atlasmap.v2.SimpleField) ConstantField(io.atlasmap.v2.ConstantField) Field(io.atlasmap.v2.Field) Audits(io.atlasmap.v2.Audits) Mapping(io.atlasmap.v2.Mapping) SimpleField(io.atlasmap.v2.SimpleField) Split(io.atlasmap.v2.Split) Test(org.junit.jupiter.api.Test)

Example 4 with Split

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());
}
Also used : SimpleField(io.atlasmap.v2.SimpleField) ConstantField(io.atlasmap.v2.ConstantField) Field(io.atlasmap.v2.Field) Audits(io.atlasmap.v2.Audits) FieldGroup(io.atlasmap.v2.FieldGroup) Mapping(io.atlasmap.v2.Mapping) SimpleField(io.atlasmap.v2.SimpleField) Split(io.atlasmap.v2.Split) Test(org.junit.jupiter.api.Test)

Example 5 with Split

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());
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) BaseMapping(io.atlasmap.v2.BaseMapping) BaseMapping(io.atlasmap.v2.BaseMapping) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)7 Split (io.atlasmap.v2.Split)6 Mapping (io.atlasmap.v2.Mapping)3 Audits (io.atlasmap.v2.Audits)2 ConstantField (io.atlasmap.v2.ConstantField)2 Field (io.atlasmap.v2.Field)2 SimpleField (io.atlasmap.v2.SimpleField)2 JsonField (io.atlasmap.json.v2.JsonField)1 AtlasActionProcessor (io.atlasmap.spi.AtlasActionProcessor)1 AtlasMapping (io.atlasmap.v2.AtlasMapping)1 BaseMapping (io.atlasmap.v2.BaseMapping)1 FieldGroup (io.atlasmap.v2.FieldGroup)1 SubString (io.atlasmap.v2.SubString)1