use of io.atlasmap.v2.SubStringBefore in project atlasmap by atlasmap.
the class StringComplexFieldActions method subStringBefore.
@AtlasFieldActionInfo(name = "SubStringBefore", sourceType = FieldType.STRING, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String subStringBefore(Action action, String input) {
if (input == null || input.length() == 0) {
return input;
}
if (action == null || !(action instanceof SubStringBefore) || ((SubStringBefore) action).getStartIndex() == null || ((SubStringBefore) action).getStartIndex() < 0 || ((SubStringBefore) action).getMatch() == null || (((SubStringBefore) action).getEndIndex() != null && ((SubStringBefore) action).getEndIndex() < ((SubStringBefore) action).getStartIndex())) {
throw new IllegalArgumentException("SubStringBefore action must be specified with a positive startIndex and a string to match");
}
SubStringBefore subStringBefore = (SubStringBefore) action;
int idx = input.indexOf(subStringBefore.getMatch());
if (idx < 0) {
return input;
}
return doSubString(input.substring(0, idx), subStringBefore.getStartIndex(), subStringBefore.getEndIndex());
}
use of io.atlasmap.v2.SubStringBefore in project atlasmap by atlasmap.
the class AtlasBaseActionsTest method testActions.
@Test
public void testActions() throws Exception {
List<ActionDetail> actions = DefaultAtlasContextFactory.getInstance().getFieldActionService().listActionDetails();
for (ActionDetail d : actions) {
System.out.println(d.getName());
}
this.runActionTest(new Uppercase(), "fname", "FNAME", String.class);
this.runActionTest(new Lowercase(), "fnAme", "fname", String.class);
this.runActionTest(new Trim(), " fname ", "fname", String.class);
this.runActionTest(new TrimLeft(), " fname ", "fname ", String.class);
this.runActionTest(new TrimRight(), " fname ", " fname", String.class);
this.runActionTest(new Capitalize(), "fname", "Fname", String.class);
this.runActionTest(new SeparateByDash(), "f:name", "f-name", String.class);
this.runActionTest(new SeparateByUnderscore(), "f-na_me", "f_na_me", String.class);
SubString s = new SubString();
s.setStartIndex(0);
s.setEndIndex(3);
this.runActionTest(s, "12345", "123", String.class);
SubStringAfter s1 = new SubStringAfter();
s1.setStartIndex(3);
s1.setEndIndex(null);
s1.setMatch("foo");
this.runActionTest(s1, "foobarblah", "blah", String.class);
SubStringBefore s2 = new SubStringBefore();
s2.setStartIndex(3);
s2.setEndIndex(null);
s2.setMatch("blah");
this.runActionTest(s2, "foobarblah", "bar", String.class);
PadStringRight ps = new PadStringRight();
ps.setPadCharacter("X");
ps.setPadCount(5);
this.runActionTest(ps, "fname", "fnameXXXXX", String.class);
PadStringLeft pl = new PadStringLeft();
pl.setPadCharacter("X");
pl.setPadCount(5);
this.runActionTest(pl, "fname", "XXXXXfname", String.class);
/* ref https://github.com/atlasmap/atlasmap/issues/674
String result = (String) runActionTest(new GenerateUUID(), "fname", null, String.class);
assertTrue(Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}").matcher(result)
.matches());
*/
}
use of io.atlasmap.v2.SubStringBefore in project atlasmap by atlasmap.
the class AtlasBaseActionsTest method testActions.
@Test
public void testActions() throws Exception {
List<ActionDetail> actions = DefaultAtlasContextFactory.getInstance().getFieldActionService().listActionDetails();
for (ActionDetail d : actions) {
System.out.println(d.getName());
}
this.runActionTest(new Uppercase(), "fname", "FNAME", String.class);
this.runActionTest(new Lowercase(), "fnAme", "fname", String.class);
this.runActionTest(new Trim(), " fname ", "fname", String.class);
this.runActionTest(new TrimLeft(), " fname ", "fname ", String.class);
this.runActionTest(new TrimRight(), " fname ", " fname", String.class);
this.runActionTest(new Capitalize(), "fname", "Fname", String.class);
this.runActionTest(new SeparateByDash(), "f:name", "f-name", String.class);
this.runActionTest(new SeparateByUnderscore(), "f-na_me", "f_na_me", String.class);
SubString s = new SubString();
s.setStartIndex(0);
s.setEndIndex(3);
this.runActionTest(s, "12345", "123", String.class);
SubStringAfter s1 = new SubStringAfter();
s1.setStartIndex(3);
s1.setEndIndex(null);
s1.setMatch("foo");
this.runActionTest(s1, "foobarblah", "blah", String.class);
SubStringBefore s2 = new SubStringBefore();
s2.setStartIndex(3);
s2.setEndIndex(null);
s2.setMatch("blah");
this.runActionTest(s2, "foobarblah", "bar", String.class);
PadStringRight ps = new PadStringRight();
ps.setPadCharacter("X");
ps.setPadCount(5);
this.runActionTest(ps, "fname", "fnameXXXXX", String.class);
PadStringLeft pl = new PadStringLeft();
pl.setPadCharacter("X");
pl.setPadCount(5);
this.runActionTest(pl, "fname", "XXXXXfname", String.class);
String result = (String) runActionTest(new GenerateUUID(), "fname", null, String.class);
assertTrue(Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}").matcher(result).matches());
}
use of io.atlasmap.v2.SubStringBefore in project atlasmap by atlasmap.
the class StringComplexFieldActionsTest method testSubStringBefore.
@Test
public void testSubStringBefore() {
SubStringBefore action = new SubStringBefore();
action.setStartIndex(3);
action.setEndIndex(null);
action.setMatch("blah");
assertNull(StringComplexFieldActions.subStringBefore(action, null));
assertEquals("", StringComplexFieldActions.subStringBefore(action, ""));
assertEquals("bar", StringComplexFieldActions.subStringBefore(action, "foobarblah"));
assertEquals("foobar", StringComplexFieldActions.subStringBefore(action, "foofoobarblahfoo"));
assertEquals("", StringComplexFieldActions.subStringBefore(action, "barblah"));
action.setEndIndex(5);
assertEquals("ba", StringComplexFieldActions.subStringBefore(action, "foobarblah"));
action.setEndIndex(3);
assertEquals("", StringComplexFieldActions.subStringBefore(action, "foobarblah"));
try {
StringComplexFieldActions.subStringBefore(null, "aa");
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
assertTrue(true);
}
try {
SubStringBefore err = new SubStringBefore();
StringComplexFieldActions.subStringBefore(err, "aa");
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
assertTrue(true);
}
try {
SubStringBefore err = new SubStringBefore();
err.setEndIndex(5);
err.setStartIndex(0);
StringComplexFieldActions.subStringBefore(err, "aa");
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
assertTrue(true);
}
try {
SubStringBefore err = new SubStringBefore();
err.setEndIndex(0);
err.setStartIndex(5);
StringComplexFieldActions.subStringBefore(err, "aa");
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
assertTrue(true);
}
}
Aggregations