diff options
Diffstat (limited to 'controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java')
-rw-r--r-- | controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java | 146 |
1 files changed, 128 insertions, 18 deletions
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java index c64764baf..9b9c2fe7c 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VDNSControlLoopTest.java @@ -62,8 +62,8 @@ public class VDNSControlLoopTest 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 { @@ -93,17 +93,7 @@ public class VDNSControlLoopTest 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 */ @@ -118,6 +108,24 @@ public class VDNSControlLoopTest 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 @@ -152,11 +160,90 @@ public class VDNSControlLoopTest implements TopicListener { * Print what's left in memory */ dumpFacts(kieSession); + } + + @Test + public void namedQueryFailTest() { /* - * Gracefully shut down the kie session + * Allows the PolicyEngine to callback to this object to + * notify that there is an event ready to be pulled + * from the queue */ - kieSession.dispose(); + for (TopicSink sink : noopTopics) { + assertTrue(sink.start()); + sink.register(this); + } + + /* + * Create a unique requestId + */ + 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, "error"); + + kieSession.fireUntilHalt(); + + /* + * The only fact in memory should be Params + */ + assertEquals(1, kieSession.getFactCount()); + + /* + * Print what's left in memory + */ + dumpFacts(kieSession); + } + + @Test + public void aaiGetFailTest() { + + /* + * Allows the PolicyEngine to callback to this object to + * notify that there is an event ready to be pulled + * from the queue + */ + for (TopicSink sink : noopTopics) { + assertTrue(sink.start()); + sink.register(this); + } + + /* + * Create a unique requestId + */ + 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); } /** @@ -176,7 +263,7 @@ public class VDNSControlLoopTest 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, @@ -232,7 +319,13 @@ public class VDNSControlLoopTest 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); @@ -266,7 +359,12 @@ public class VDNSControlLoopTest implements TopicListener { } else if (policyName.endsWith("EVENT.MANAGER")) { logger.debug("Rule Fired: " + notification.policyName); - assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.notification)); + if ("error".equals(notification.AAI.get("vserver.vserver-name"))) { + assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notification.notification); + } + else { + assertTrue(ControlLoopNotificationType.FINAL_SUCCESS.equals(notification.notification)); + } kieSession.halt(); } else if (policyName.endsWith("EVENT.MANAGER.TIMEOUT")) { @@ -303,6 +401,18 @@ public class VDNSControlLoopTest implements TopicListener { kieSession.insert(event); } + protected void sendEvent(ControlLoopPolicy policy, UUID requestID, ControlLoopEventStatus status, String vserverName) { + VirtualControlLoopEvent event = new VirtualControlLoopEvent(); + event.closedLoopControlName = policy.getControlLoop().getControlLoopName(); + event.requestID = requestID; + event.target = "vserver.vserver-name"; + event.closedLoopAlarmStart = Instant.now(); + event.AAI = new HashMap<>(); + event.AAI.put("vserver.vserver-name", vserverName); + event.closedLoopEventStatus = status; + kieSession.insert(event); + } + /** * This method will dump all the facts in the working memory. * |