[ https://issues.apache.org/jira/browse/METRON-830?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15962491#comment-15962491 ]
ASF GitHub Bot commented on METRON-830: --------------------------------------- Github user anandsubbu commented on a diff in the pull request: https://github.com/apache/incubator-metron/pull/516#discussion_r110581665 --- Diff: metron-platform/metron-common/src/test/java/org/apache/metron/common/dsl/functions/StringFunctionsTest.java --- @@ -207,4 +207,78 @@ public void testFormatWithNoArguments() throws Exception { public void testFormatWithMissingArguments() throws Exception { run("FORMAT('missing arg: %d')", Collections.emptyMap()); } + + + /** + * CHOP StringFunction + * @throws Exception + */ + @Test + public void testChop() throws Exception { + Assert.assertEquals("ab", run("CHOP('abc')", new HashedMap())); + Assert.assertEquals(null, run("CHOP(null)", new HashedMap())); + Assert.assertEquals("abc", run("CHOP(msg)", ImmutableMap.of("msg", "abc\r\n"))); + Assert.assertEquals("", run("CHOP(msg)", ImmutableMap.of("msg", "\n"))); + } + + @Test(expected = ParseException.class) + public void testChopWithMissingArguments() throws Exception { + run("CHOP()", Collections.emptyMap()); + } + + /** + * PREPENDIFMISSING StringFunction + * @throws Exception + */ + @Test + public void testPrependIfMissing() throws Exception { + Assert.assertEquals("xyzabc", run("PREPENDIFMISSING('abc', 'xyz')", new HashedMap())); + Assert.assertEquals("xyzXYZabc", run("PREPENDIFMISSING('XYZabc', 'xyz', 'mno')", new HashedMap())); + Assert.assertEquals(null, run("PREPENDIFMISSING(null, null, null)", new HashedMap())); + Assert.assertEquals("xyz", run("PREPENDIFMISSING('', 'xyz', null)", new HashedMap())); + } + + @Test(expected = ParseException.class) + public void testPrependIfMissingWithIncorrectArgs() throws Exception { --- End diff -- Yup, you're right. Added try/catch blocks now. > Adding StringFunctions to Stellar - chop, prependifmissing, appendifmissing > and countmatches > -------------------------------------------------------------------------------------------- > > Key: METRON-830 > URL: https://issues.apache.org/jira/browse/METRON-830 > Project: Metron > Issue Type: Bug > Affects Versions: 0.3.1 > Reporter: Anand Subramanian > Assignee: Anand Subramanian > Fix For: Next + 1 > > > Enhance Stellar by adding the following apache common string functions. > - chop -> Remove the last character from a String. > - prependifmissing -> Prepends the prefix to the start of the string if the > string does not already start with any of the prefixes. > - appendifmissing -> Appends the suffix to the end of the string if the > string does not already end with any of the suffixes. > - countmatches -> Counts how many times the substring appears in the larger > string. -- This message was sent by Atlassian JIRA (v6.3.15#6346)