Fix RestManager test issue 54/69554/1
authorJim Hahn <jrh3@att.com>
Sat, 29 Sep 2018 14:06:26 +0000 (10:06 -0400)
committerJim Hahn <jrh3@att.com>
Sat, 29 Sep 2018 14:09:26 +0000 (10:09 -0400)
Apparently drools-pdp code depends on Dmaap topic factories throwing
IllegalArgumentException instead of IllegalStateException (which is what
the other topic factories throw) when an unknown topic name is requested.
Therefore, the change to make them consistent has been backed out.

Change-Id: Ia3d7e26a61027977eb626c9ddad6369982eae002
Issue-ID: POLICY-1148
Signed-off-by: Jim Hahn <jrh3@att.com>
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSinkFactory.java
policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSourceFactory.java
policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicFactoryTestBase.java

index dc207a8..0907872 100644 (file)
@@ -395,7 +395,7 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory {
             if (dmaapTopicWriters.containsKey(topic)) {
                 return dmaapTopicWriters.get(topic);
             } else {
-                throw new IllegalStateException("DmaapTopicSink for " + topic + " not found");
+                throw new IllegalArgumentException("DmaapTopicSink for " + topic + " not found");
             }
         }
     }
index ae6c6c3..f45164f 100644 (file)
@@ -448,7 +448,7 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory {
             if (dmaapTopicSources.containsKey(topic)) {
                 return dmaapTopicSources.get(topic);
             } else {
-                throw new IllegalStateException("DmaapTopiceSource for " + topic + " not found");
+                throw new IllegalArgumentException("DmaapTopiceSource for " + topic + " not found");
             }
         }
     }
index c008a3b..440120e 100644 (file)
@@ -106,4 +106,28 @@ public abstract class DmaapTopicFactoryTestBase<T extends Topic> extends BusTopi
         BusTopicParams params = getLastParams();
         assertEquals(false, params.isAllowSelfSignedCerts());
     }
+
+    /**
+     * Tests exception cases with get(topic).  DMaaP topics are special in that they
+     * throw IllegalArgumentException, even for an unknown topic name; all of the
+     * other Topic Factory classes throw IllegalStateException, thus we override
+     * the default test method.
+     */
+    @Override
+    public void testGet_Ex() {
+        // null topic
+        RuntimeException actual = expectException(() -> getTopic(null));
+        assertEquals("null topic", IllegalArgumentException.class, actual.getClass());
+
+        // empty topic
+        actual = expectException(() -> getTopic(""));
+        assertEquals("empty topic", IllegalArgumentException.class, actual.getClass());
+
+        // unknown topic
+        initFactory();
+        buildTopics(makePropBuilder().makeTopic(MY_TOPIC).build());
+
+        actual = expectException(() -> getTopic(TOPIC2));
+        assertEquals("unknown topic", IllegalArgumentException.class, actual.getClass());
+    }
 }