use of io.atlasmap.v2.PadStringRight 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.PadStringRight in project atlasmap by atlasmap.
the class StringComplexFieldActions method padStringRight.
@AtlasFieldActionInfo(name = "PadStringRight", sourceType = FieldType.STRING, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String padStringRight(Action action, String input) {
if (action == null || !(action instanceof PadStringRight) || ((PadStringRight) action).getPadCharacter() == null || ((PadStringRight) action).getPadCount() == null) {
throw new IllegalArgumentException("PadStringRight must be specfied with padCharacter and padCount");
}
PadStringRight padStringRight = (PadStringRight) action;
StringBuilder builder = new StringBuilder();
if (input != null) {
builder.append(input);
}
for (int i = 0; i < padStringRight.getPadCount(); i++) {
builder.append(padStringRight.getPadCharacter());
}
return builder.toString();
}
use of io.atlasmap.v2.PadStringRight 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.PadStringRight in project atlasmap by atlasmap.
the class StringComplexFieldActionsTest method testPadStringRight.
@Test
public void testPadStringRight() {
PadStringRight padStringRight = new PadStringRight();
padStringRight.setPadCharacter("a");
padStringRight.setPadCount(3);
assertEquals("aaa", StringComplexFieldActions.padStringRight(padStringRight, null));
assertEquals("aaa", StringComplexFieldActions.padStringRight(padStringRight, ""));
assertEquals("aaaa", StringComplexFieldActions.padStringRight(padStringRight, "a"));
assertEquals("baaa", StringComplexFieldActions.padStringRight(padStringRight, "b"));
try {
StringComplexFieldActions.padStringRight(null, "aa");
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
}
try {
StringComplexFieldActions.padStringRight(new PadStringRight(), "aa");
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
}
try {
PadStringRight incomplete = new PadStringRight();
incomplete.setPadCharacter("f");
StringComplexFieldActions.padStringRight(incomplete, "aa");
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
}
try {
PadStringRight incomplete = new PadStringRight();
incomplete.setPadCount(3);
StringComplexFieldActions.padStringRight(incomplete, "aa");
fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
}
}
Aggregations