Author: cziegeler Date: Wed Oct 12 06:48:35 2016 New Revision: 1764390 URL: http://svn.apache.org/viewvc?rev=1764390&view=rev Log: SLING-6133 : Refactor Event Utility. Apply patch from Jörg Hoh
Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/Utility.java sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/UtilityTest.java Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/Utility.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/Utility.java?rev=1764390&r1=1764389&r2=1764390&view=diff ============================================================================== --- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/Utility.java (original) +++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/jobs/Utility.java Wed Oct 12 06:48:35 2016 @@ -43,25 +43,19 @@ public abstract class Utility { public static volatile boolean LOG_DEPRECATION_WARNINGS = true; /** - * Check the job topic. - * @return <code>null</code> if the topic is correct, otherwise an error description is returned + * Check if the job topic is a valid OSGI event name (see 113.3.1 of the OSGI spec) + * @return <code>null</code> if the topic is syntactically correct otherwise an error description is returned */ public static String checkJobTopic(final Object jobTopic) { - final String message; + String message = null; if ( jobTopic != null ) { if ( jobTopic instanceof String ) { - boolean topicIsCorrect = false; try { new Event((String)jobTopic, (Dictionary<String, Object>)null); - topicIsCorrect = true; } catch (final IllegalArgumentException iae) { - // we just have to catch it - } - if ( !topicIsCorrect ) { - message = "Discarding job - job has an illegal job topic"; - } else { - message = null; + message = String.format("Discarding job - job has an illegal job topic '%s'",jobTopic); } + } else { message = "Discarding job - job topic is not of type string"; } Modified: sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/UtilityTest.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/UtilityTest.java?rev=1764390&r1=1764389&r2=1764390&view=diff ============================================================================== --- sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/UtilityTest.java (original) +++ sling/trunk/bundles/extensions/event/src/test/java/org/apache/sling/event/impl/jobs/UtilityTest.java Wed Oct 12 06:48:35 2016 @@ -67,4 +67,14 @@ public class UtilityTest extends TestCas public void test_filter_consecutive_replace() { assertEquals("a_b_", ResourceHelper.filterName("a/[b]")); } + + public void test_checkJobTopic() { + assertNull (Utility.checkJobTopic("simpleTopic")); + final String result = Utility.checkJobTopic("simpleTopic.withDots"); + assertNotNull(result); + assertTrue ("Discarding job - job has an illegal job topic 'simpleTopic.withDots'".equals(result)); + assertNotNull (Utility.checkJobTopic(new StringBuilder("simpleTopic"))); + assertNotNull (Utility.checkJobTopic(null)); + } + }