summaryrefslogtreecommitdiffstats
path: root/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java')
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java101
1 files changed, 59 insertions, 42 deletions
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java
index 6424d02b6..54591cad0 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java
@@ -35,7 +35,6 @@ import java.util.UUID;
import org.junit.AfterClass;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.FactHandle;
@@ -65,8 +64,8 @@ public class VFWControlLoopTest implements TopicListener {
private static List<? extends TopicSink> noopTopics;
- private KieSession kieSession;
- private Util.Pair<ControlLoopPolicy, String> pair;
+ private static KieSession kieSession;
+ private static Util.Pair<ControlLoopPolicy, String> pair;
private UUID requestID;
static {
@@ -97,16 +96,6 @@ public class VFWControlLoopTest implements TopicListener {
} catch (Exception e) {
fail(e.getMessage());
}
- }
-
- @AfterClass
- public static void tearDownSimulator() {
- HttpServletServer.factory.destroy();
- PolicyEngine.manager.shutdown();
- }
-
- @Test
- public void successTest() {
/*
* Start the kie session
@@ -122,8 +111,25 @@ public class VFWControlLoopTest implements TopicListener {
logger.debug("Could not create kieSession");
fail("Could not create kieSession");
}
+ }
+
+ @AfterClass
+ public static void tearDownSimulator() {
+ /*
+ * Gracefully shut down the kie session
+ */
+ kieSession.dispose();
- /*
+ HttpServletServer.factory.destroy();
+ PolicyEngine.manager.shutdown();
+ TopicEndpoint.manager.shutdown();
+ PolicyEngine.manager.stop();
+ }
+
+ @Test
+ public void successTest() {
+
+ /*
* Allows the PolicyEngine to callback to this object to
* notify that there is an event ready to be pulled
* from the queue
@@ -132,7 +138,7 @@ public class VFWControlLoopTest implements TopicListener {
assertTrue(sink.start());
sink.register(this);
}
-
+
/*
* Create a unique requestId
*/
@@ -164,30 +170,10 @@ public class VFWControlLoopTest implements TopicListener {
* Print what's left in memory
*/
dumpFacts(kieSession);
-
- /*
- * Gracefully shut down the kie session
- */
- kieSession.dispose();
}
@Test
- public void namedQueryFailTest() {
-
- /*
- * Start the kie session
- */
- try {
- kieSession = startSession("../archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl",
- "src/test/resources/yaml/policy_ControlLoop_vFW.yaml",
- "service=ServiceDemo;resource=Res1Demo;type=operational",
- "CL_vFW",
- "org.onap.closed_loop.ServiceDemo:VNFS:1.0.0");
- } catch (IOException e) {
- e.printStackTrace();
- logger.debug("Could not create kieSession");
- fail("Could not create kieSession");
- }
+ public void aaiFailTests() {
/*
* Allows the PolicyEngine to callback to this object to
@@ -210,7 +196,6 @@ public class VFWControlLoopTest implements TopicListener {
* the rules
*/
sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "error");
-
try {
kieSession.fireUntilHalt();
}
@@ -220,7 +205,6 @@ public class VFWControlLoopTest implements TopicListener {
fail(e.getMessage());
}
-
/*
* The only fact in memory should be Params
*/
@@ -232,9 +216,36 @@ public class VFWControlLoopTest implements TopicListener {
dumpFacts(kieSession);
/*
- * Gracefully shut down the kie session
+ * Create a unique requestId
*/
- kieSession.dispose();
+ requestID = UUID.randomUUID();
+
+ /*
+ * Simulate an onset event the policy engine will
+ * receive from DCAE to kick off processing through
+ * the rules
+ */
+
+ sendEvent(pair.a, requestID, ControlLoopEventStatus.ONSET, "getFail");
+
+ try {
+ kieSession.fireUntilHalt();
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ logger.warn(e.toString());
+ fail(e.getMessage());
+ }
+
+ /*
+ * The only fact in memory should be Params
+ */
+ assertEquals(1, kieSession.getFactCount());
+
+ /*
+ * Print what's left in memory
+ */
+ dumpFacts(kieSession);
}
/**
@@ -254,7 +265,7 @@ public class VFWControlLoopTest implements TopicListener {
* @return the kieSession to be used to insert facts
* @throws IOException
*/
- private KieSession startSession(String droolsTemplate,
+ private static KieSession startSession(String droolsTemplate,
String yamlFile,
String policyScope,
String policyName,
@@ -311,7 +322,13 @@ public class VFWControlLoopTest implements TopicListener {
String policyName = notification.policyName;
if (policyName.endsWith("EVENT")) {
logger.debug("Rule Fired: " + notification.policyName);
- assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification));
+ if ("getFail".equals(notification.AAI.get("generic-vnf.vnf-id"))) {
+ assertEquals(ControlLoopNotificationType.REJECTED, notification.notification);
+ kieSession.halt();
+ }
+ else {
+ assertTrue(ControlLoopNotificationType.ACTIVE.equals(notification.notification));
+ }
}
else if (policyName.endsWith("GUARD_NOT_YET_QUERIED")) {
logger.debug("Rule Fired: " + notification.policyName);