summaryrefslogtreecommitdiffstats
path: root/policy-core/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'policy-core/src/test')
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/core/DroolsContainerTest.java12
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/util/KieUtilsTest.java62
2 files changed, 73 insertions, 1 deletions
diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/DroolsContainerTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/DroolsContainerTest.java
index d168ca8b..2f45f01e 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/core/DroolsContainerTest.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/core/DroolsContainerTest.java
@@ -165,6 +165,18 @@ public class DroolsContainerTest {
container.insert("session1", result);
assertEquals(48, result.poll(TIMEOUT_SEC, TimeUnit.SECONDS).intValue());
+
+ // verify that default KiePackages have been added by testing
+ // that 'DroolsRunnable' is functioning
+
+ final LinkedBlockingQueue<String> lbq = new LinkedBlockingQueue<>();
+ container.insert("session1", new DroolsRunnable() {
+ @Override
+ public void run() {
+ lbq.add("DroolsRunnable String");
+ }
+ });
+ assertEquals("DroolsRunnable String", lbq.poll(TIMEOUT_SEC, TimeUnit.SECONDS));
} finally {
container.shutdown();
assertFalse(container.isAlive());
diff --git a/policy-core/src/test/java/org/onap/policy/drools/util/KieUtilsTest.java b/policy-core/src/test/java/org/onap/policy/drools/util/KieUtilsTest.java
index 83f62b32..89ab9d0a 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/util/KieUtilsTest.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/util/KieUtilsTest.java
@@ -22,12 +22,15 @@ package org.onap.policy.drools.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.IOException;
+import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Enumeration;
import java.util.stream.Collectors;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -119,4 +122,61 @@ public class KieUtilsTest {
public void getFacts() {
assertEquals(0, KieUtils.getFacts(session).size());
}
-} \ No newline at end of file
+
+ @Test
+ public void resourceToPackagesTests() {
+ // Some minimal logging -- it would be nice to verify the 'KieUtils' logger messages
+ StringBuffer log;
+
+ // test IOException from ClassLoader
+ log = new StringBuffer();
+ assertNull(KieUtils.resourceToPackages(new BogusClassLoader(log), "BogusClassLoader"));
+ assertEquals("IOException(BogusClassLoader)", log.toString());
+
+ // test 'null' return when no resources are found
+ assertNull(KieUtils.resourceToPackages(ClassLoader.getSystemClassLoader(), "no/such/url"));
+
+ // test IOException in 'IOUtils.toByteArray()' -> 'InputStream.read()'
+ log = new StringBuffer();
+ assertNull(KieUtils.resourceToPackages(new BogusClassLoader(log), "BogusUrl"));
+ assertEquals("", log.toString());
+
+ // don't know how to test 'KieBuilder' errors at this point
+
+ // success legs are tested in 'DroolsContainerTest'
+ }
+
+ static class BogusClassLoader extends ClassLoader {
+ StringBuffer log;
+
+ BogusClassLoader(StringBuffer log) {
+ this.log = log;
+ }
+
+ @Override
+ public Enumeration<URL> getResources(String name) throws IOException {
+ if ("BogusUrl".equals(name)) {
+ return new Enumeration<URL>() {
+ @Override
+ public boolean hasMoreElements() {
+ return true;
+ }
+
+ @Override
+ public URL nextElement() {
+ try {
+ // when the following URL is used, an IOException will occur
+ return new URL("http://127.0.0.1:1");
+ } catch (IOException e) {
+ // this should never happen, as the URL above is syntactically valid
+ return null;
+ }
+ }
+ };
+ } else {
+ log.append("IOException(BogusClassLoader)");
+ throw new IOException("BogusClassLoader");
+ }
+ }
+ }
+}