use of io.atlasmap.v2.ReplaceAll in project atlasmap by atlasmap.
the class StringComplexFieldActions method replaceAll.
@AtlasFieldActionInfo(name = "ReplaceAll", sourceType = FieldType.STRING, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String replaceAll(Action action, String input) {
if (action == null || !(action instanceof ReplaceAll)) {
throw new IllegalArgumentException("Action must be a ReplaceAll action");
}
ReplaceAll replaceAll = (ReplaceAll) action;
String match = replaceAll.getMatch();
if (match == null || match.length() == 0) {
throw new IllegalArgumentException("ReplaceAll action must be specified with a non-empty old string");
}
String newString = replaceAll.getNewString();
return input == null ? null : input.replaceAll(match, newString == null ? "" : newString);
}
use of io.atlasmap.v2.ReplaceAll in project atlasmap by atlasmap.
the class StringComplexFieldActionsTest method testReplaceAll.
@Test
public void testReplaceAll() {
ReplaceAll replaceAll = new ReplaceAll();
replaceAll.setMatch(" ");
assertNull(StringComplexFieldActions.replaceAll(replaceAll, null));
assertEquals("", StringComplexFieldActions.replaceAll(replaceAll, ""));
assertEquals("test", StringComplexFieldActions.replaceAll(replaceAll, "test"));
replaceAll.setMatch("e");
assertEquals("tst", StringComplexFieldActions.replaceAll(replaceAll, "test"));
replaceAll.setMatch("t");
replaceAll.setNewString("h");
assertEquals("hesh", StringComplexFieldActions.replaceAll(replaceAll, "test"));
replaceAll.setMatch("is");
replaceAll.setNewString("at");
assertEquals("That at a test", StringComplexFieldActions.replaceAll(replaceAll, "This is a test"));
}
use of io.atlasmap.v2.ReplaceAll in project atlasmap by atlasmap.
the class StringComplexFieldActionsTest method testReplaceAllNullOldString.
@Test(expected = IllegalArgumentException.class)
public void testReplaceAllNullOldString() {
ReplaceAll replaceAll = new ReplaceAll();
StringComplexFieldActions.replaceAll(replaceAll, " ");
}
use of io.atlasmap.v2.ReplaceAll in project atlasmap by atlasmap.
the class StringComplexFieldActionsTest method testReplaceAllEmptyMatch.
@Test(expected = IllegalArgumentException.class)
public void testReplaceAllEmptyMatch() {
ReplaceAll replaceAll = new ReplaceAll();
replaceAll.setMatch("");
StringComplexFieldActions.replaceAll(replaceAll, " ");
}
Aggregations