diff options
Diffstat (limited to 'controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VsonhControlLoopTest.java')
-rw-r--r-- | controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VsonhControlLoopTest.java | 171 |
1 files changed, 9 insertions, 162 deletions
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VsonhControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VsonhControlLoopTest.java index 3859b7405..d0427e47f 100644 --- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VsonhControlLoopTest.java +++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VsonhControlLoopTest.java @@ -26,128 +26,39 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import java.io.IOException; -import java.net.URLEncoder; import java.time.Instant; import java.util.HashMap; -import java.util.List; -import java.util.Properties; import java.util.UUID; -import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.kie.api.runtime.KieSession; -import org.kie.api.runtime.rule.FactHandle; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; -import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager; import org.onap.policy.common.endpoints.event.comm.TopicListener; import org.onap.policy.common.endpoints.event.comm.TopicSink; -import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; -import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; import org.onap.policy.controlloop.ControlLoopEventStatus; import org.onap.policy.controlloop.ControlLoopNotificationType; import org.onap.policy.controlloop.ControlLoopTargetType; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.VirtualControlLoopNotification; import org.onap.policy.controlloop.policy.ControlLoopPolicy; -import org.onap.policy.drools.protocol.coders.EventProtocolCoder; -import org.onap.policy.drools.protocol.coders.EventProtocolParams; -import org.onap.policy.drools.protocol.coders.JsonProtocolFilter; -import org.onap.policy.drools.system.PolicyController; -import org.onap.policy.drools.system.PolicyEngine; -import org.onap.policy.drools.utils.logging.LoggerUtil; import org.onap.policy.sdnr.PciRequest; import org.onap.policy.sdnr.PciRequestWrapper; import org.onap.policy.sdnr.PciResponse; import org.onap.policy.sdnr.PciResponseWrapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -public class VsonhControlLoopTest implements TopicListener { - - private static final Logger logger = LoggerFactory.getLogger(VsonhControlLoopTest.class); - - private static List<? extends TopicSink> noopTopics; - - private static KieSession kieSession; - private static SupportUtil.Pair<ControlLoopPolicy, String> pair; - private UUID requestId; - - static { - /* Set environment properties */ - SupportUtil.setAaiProps(); - SupportUtil.setGuardProps(); - SupportUtil.setPuProp(); - LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "DEBUG"); - } +public class VsonhControlLoopTest extends ControlLoopBase implements TopicListener { /** * Setup the simulator. */ @BeforeClass - public static void setUpSimulator() { - PolicyEngine.manager.configure(new Properties()); - assertTrue(PolicyEngine.manager.start()); - Properties noopSinkProperties = new Properties(); - noopSinkProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS, "SDNR-CL,POLICY-CL-MGT"); - noopSinkProperties.put("noop.sink.topics.SDNR-CL.events", "org.onap.policy.sdnr.PciRequestWrapper"); - noopSinkProperties.put("noop.sink.topics.SDNR-CL.events.custom.gson", - "org.onap.policy.sdnr.util.Serialization,gson"); - noopSinkProperties.put("noop.sink.topics.POLICY-CL-MGT.events", - "org.onap.policy.controlloop.VirtualControlLoopNotification"); - noopSinkProperties.put("noop.sink.topics.POLICY-CL-MGT.events.custom.gson", - "org.onap.policy.controlloop.util.Serialization,gsonPretty"); - noopTopics = TopicEndpointManager.getManager().addTopicSinks(noopSinkProperties); - - EventProtocolCoder.manager.addEncoder(EventProtocolParams.builder() - .groupId("junit.groupId") - .artifactId("junit.artifactId") - .topic("POLICY-CL-MGT") - .eventClass("org.onap.policy.controlloop.VirtualControlLoopNotification") - .protocolFilter(new JsonProtocolFilter()) - .modelClassLoaderHash(1111)); - EventProtocolCoder.manager.addEncoder(EventProtocolParams.builder() - .groupId("junit.groupId") - .artifactId("junit.artifactId") - .topic("SDNR-CL") - .eventClass("org.onap.policy.sdnr.PciRequestWrapper") - .protocolFilter(new JsonProtocolFilter()) - .modelClassLoaderHash(1111)); - try { - SupportUtil.buildAaiSim(); - SupportUtil.buildGuardSim(); - } catch (Exception e) { - fail(e.getMessage()); - } - /* - * 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_vSONH.yaml", "type=operational", "CL_vSONH", "v4.0.0"); - } catch (IOException e) { - e.printStackTrace(); - logger.debug("Could not create kieSession"); - fail("Could not create kieSession"); - } - } - - /** - * Tear down the simulator. - */ - @AfterClass - public static void tearDownSimulator() { - /* - * Gracefully shut down the kie session - */ - kieSession.dispose(); - - PolicyEngine.manager.stop(); - HttpServletServerFactoryInstance.getServerFactory().destroy(); - PolicyController.factory.shutdown(); - TopicEndpointManager.getManager().shutdown(); + public static void setUpBeforeClass() { + ControlLoopBase.setUpBeforeClass( + "../archetype-cl-amsterdam/src/main/resources/archetype-resources" + + "/src/main/resources/__closedLoopControlName__.drl", + "src/test/resources/yaml/policy_ControlLoop_vSONH.yaml", + "type=operational", + "CL_vSONH", + "v4.0.0"); } @Test @@ -230,56 +141,6 @@ public class VsonhControlLoopTest implements TopicListener { } - /** - * This method will start a kie session and instantiate the Policy Engine. - * - * @param droolsTemplate - * the DRL rules file - * @param yamlFile - * the yaml file containing the policies - * @param policyScope - * scope for policy - * @param policyName - * name of the policy - * @param policyVersion - * version of the policy - * @return the kieSession to be used to insert facts - * @throws IOException - * IO exception - */ - private static KieSession startSession(String droolsTemplate, String yamlFile, String policyScope, - String policyName, String policyVersion) throws IOException { - - /* - * Load policies from yaml - */ - pair = SupportUtil.loadYaml(yamlFile); - assertNotNull(pair); - assertNotNull(pair.first); - assertNotNull(pair.first.getControlLoop()); - assertNotNull(pair.first.getControlLoop().getControlLoopName()); - assertTrue(pair.first.getControlLoop().getControlLoopName().length() > 0); - - /* - * Construct a kie session - */ - final KieSession kieSession = SupportUtil.buildContainer(droolsTemplate, - pair.first.getControlLoop().getControlLoopName(), policyScope, policyName, policyVersion, - URLEncoder.encode(pair.second, "UTF-8")); - - /* - * Retrieve the Policy Engine - */ - - logger.debug("======controlloop======"); - logger.debug(((ControlLoopPolicy) pair.first).toString()); - logger.debug("======policies======"); - logger.debug(URLEncoder.encode(pair.second, "UTF-8")); - logger.debug("============"); - - return kieSession; - } - /* * (non-Javadoc) * @@ -426,18 +287,4 @@ public class VsonhControlLoopTest implements TopicListener { logger.debug("\n============ event ===========\n {}", event); kieSession.insert(event); } - - /** - * This method will dump all the facts in the working memory. - * - * @param kieSession - * the session containing the facts - */ - public void dumpFacts(KieSession kieSession) { - logger.debug("Fact Count: {}", kieSession.getFactCount()); - for (FactHandle handle : kieSession.getFactHandles()) { - logger.debug("FACT: {}", handle); - } - } - } |