Search in sources :

Example 6 with Split

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

the class StringComplexFieldActionsTest method testSplitCollapse.

@Test
public void testSplitCollapse() {
    Split action = new Split();
    action.setCollapseRepeatingDelimiters(true);
    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"));
    action.setDelimiter(" ");
    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 7 with Split

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

the class StringComplexFieldActionsTest method testSplitNoDelimiter.

@Test
public void testSplitNoDelimiter() {
    assertThrows(IllegalArgumentException.class, () -> {
        Split action = new Split();
        StringComplexFieldActions.split(action, "foobar");
    });
}
Also used : Split(io.atlasmap.v2.Split) Test(org.junit.jupiter.api.Test)

Example 8 with Split

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

the class StringComplexFieldActions method split.

/**
 * Splits the String with the specified delimiter.
 * @param split action model
 * @param input source
 * @return splitted
 */
@AtlasActionProcessor(sourceType = FieldType.ANY)
public static String[] split(Split split, String input) {
    if (split == null || split.getDelimiter() == null) {
        throw new IllegalArgumentException("Split must be specified with a delimiter");
    }
    String quotedDelimiter = Pattern.quote(split.getDelimiter());
    boolean collapseRepeatingDelimiter = split.getCollapseRepeatingDelimiters() == null ? false : split.getCollapseRepeatingDelimiters();
    if (collapseRepeatingDelimiter) {
        quotedDelimiter = "(" + quotedDelimiter + ")+";
    }
    return input == null ? null : input.toString().split(quotedDelimiter);
}
Also used : SubString(io.atlasmap.v2.SubString) AtlasActionProcessor(io.atlasmap.spi.AtlasActionProcessor)

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