aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/templates/template.demo/src
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/templates/template.demo/src')
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnBwControlLoopTest.java156
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnControlLoopTest.java156
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopBase.java229
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopEventCleanupTest.java26
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java164
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/SupportUtil.java36
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VcpeControlLoopTest.java165
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VdnsControlLoopTest.java156
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcControlLoopTest.java157
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfwControlLoopTest.java167
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VpciControlLoopTest.java171
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VsonhControlLoopTest.java171
12 files changed, 342 insertions, 1412 deletions
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnBwControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnBwControlLoopTest.java
index 42742b261..bf81c2d19 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnBwControlLoopTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnBwControlLoopTest.java
@@ -25,120 +25,35 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
-import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
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.sdnc.SdncRequest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-public class CcvpnBwControlLoopTest implements TopicListener {
-
- private static final Logger logger = LoggerFactory.getLogger(CcvpnBwControlLoopTest.class);
-
- private static List<? extends TopicSink> noopTopics;
-
- private static KieSession kieSession;
- private static SupportUtil.Pair<ControlLoopPolicy, String> pair;
-
- static {
- /* Set environment properties */
- SupportUtil.setAaiProps();
- SupportUtil.setSdncProps();
- SupportUtil.setGuardProps();
- LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
- }
+public class CcvpnBwControlLoopTest 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, "POLICY-CL-MGT");
- 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));
-
- try {
- SupportUtil.buildAaiSim();
- SupportUtil.buildSdncSim();
- 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_CCVPN_BW.yaml", "type=operational",
- "BandwidthOnDemand", "2.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_CCVPN_BW.yaml",
+ "type=operational",
+ "BandwidthOnDemand", "2.0.0");
}
@Test
@@ -221,49 +136,6 @@ public class CcvpnBwControlLoopTest implements TopicListener {
dumpFacts(kieSession);
}
- /**
- * 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,
- StandardCharsets.UTF_8.name()));
-
- /*
- * Retrieve the Policy Engine
- */
-
- logger.debug("============");
- logger.debug(URLEncoder.encode(pair.second, StandardCharsets.UTF_8.name()));
- logger.debug("============");
-
- return kieSession;
- }
-
/*
* (non-Javadoc)
*
@@ -359,16 +231,4 @@ public class CcvpnBwControlLoopTest implements TopicListener {
event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
kieSession.insert(event);
}
-
- /**
- * Dumps the kie session facts.
- *
- * @param kieSession input session
- */
- public static void dumpFacts(KieSession kieSession) {
- logger.debug("Fact Count: " + kieSession.getFactCount());
- for (FactHandle handle : kieSession.getFactHandles()) {
- logger.debug("FACT: " + handle);
- }
- }
}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnControlLoopTest.java
index 2c2b5d8fb..8fda5b4df 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnControlLoopTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/CcvpnControlLoopTest.java
@@ -25,119 +25,36 @@ 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.sdnc.SdncRequest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-public class CcvpnControlLoopTest implements TopicListener {
-
- private static final Logger logger = LoggerFactory.getLogger(CcvpnControlLoopTest.class);
-
- private static List<? extends TopicSink> noopTopics;
-
- private static KieSession kieSession;
- private static SupportUtil.Pair<ControlLoopPolicy, String> pair;
-
- static {
- /* Set environment properties */
- SupportUtil.setAaiProps();
- SupportUtil.setSdncProps();
- SupportUtil.setGuardProps();
- LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
- }
+public class CcvpnControlLoopTest 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, "POLICY-CL-MGT");
- 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));
-
- try {
- SupportUtil.buildAaiSim();
- SupportUtil.buildSdncSim();
- 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_CCVPN.yaml", "type=operational", "Connectivity Reroute",
- "2.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_CCVPN.yaml",
+ "type=operational",
+ "Connectivity Reroute",
+ "2.0.0");
}
@Test
@@ -220,48 +137,6 @@ public class CcvpnControlLoopTest implements TopicListener {
dumpFacts(kieSession);
}
- /**
- * 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("============");
- logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
- logger.debug("============");
-
- return kieSession;
- }
-
/*
* (non-Javadoc)
*
@@ -353,17 +228,4 @@ public class CcvpnControlLoopTest implements TopicListener {
event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
kieSession.insert(event);
}
-
- /**
- * Dumps the kie session facts.
- *
- * @param kieSession input session
- */
- public static void dumpFacts(KieSession kieSession) {
- logger.debug("Fact Count: " + kieSession.getFactCount());
- for (FactHandle handle : kieSession.getFactHandles()) {
- logger.debug("FACT: " + handle);
- }
- }
}
-
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopBase.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopBase.java
new file mode 100644
index 000000000..ab6ec5a3a
--- /dev/null
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopBase.java
@@ -0,0 +1,229 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * demo
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.template.demo;
+
+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.util.List;
+import java.util.Properties;
+import java.util.UUID;
+import org.junit.AfterClass;
+import org.kie.api.runtime.KieSession;
+import org.kie.api.runtime.rule.FactHandle;
+import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
+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.policy.ControlLoopPolicy;
+import org.onap.policy.drools.protocol.coders.EventProtocolCoderConstants;
+import org.onap.policy.drools.protocol.coders.EventProtocolParams;
+import org.onap.policy.drools.protocol.coders.JsonProtocolFilter;
+import org.onap.policy.drools.system.PolicyControllerConstants;
+import org.onap.policy.drools.system.PolicyEngineConstants;
+import org.onap.policy.drools.utils.logging.LoggerUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Common super class used by various Control Loop test classes. It manages the simulators
+ * and the kie session.
+ */
+public class ControlLoopBase {
+
+ private static final String JUNIT_ARTIFACT_ID = "junit.artifactId";
+
+ private static final String JUNIT_GROUP_ID = "junit.groupId";
+
+ protected static final Logger logger = LoggerFactory.getLogger(ControlLoopBase.class);
+
+ protected static List<? extends TopicSink> noopTopics;
+
+ protected static KieSession kieSession;
+ protected static SupportUtil.Pair<ControlLoopPolicy, String> pair;
+
+ protected UUID requestId;
+
+ /**
+ * Starts the simulator and the kie session.
+ *
+ * @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
+ */
+ public static void setUpBeforeClass(String droolsTemplate, String yamlFile, String policyScope,
+ String policyName, String policyVersion) {
+
+ /* Set environment properties */
+ SupportUtil.setAaiProps();
+ SupportUtil.setGuardProps();
+ SupportUtil.setSdncProps();
+ SupportUtil.setSoProps();
+ SupportUtil.setVfcProps();
+ SupportUtil.setPuProp();
+
+ LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
+
+ PolicyEngineConstants.getManager().configure(new Properties());
+ assertTrue(PolicyEngineConstants.getManager().start());
+ Properties noopSinkProperties = new Properties();
+ noopSinkProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS,
+ "APPC-LCM-READ,APPC-CL,SDNR-CL,POLICY-CL-MGT");
+ noopSinkProperties.put("noop.sink.topics.APPC-LCM-READ.events", "org.onap.policy.appclcm.LcmRequestWrapper");
+ noopSinkProperties.put("noop.sink.topics.APPC-LCM-READ.events.custom.gson",
+ "org.onap.policy.appclcm.util.Serialization,gson");
+ noopSinkProperties.put("noop.sink.topics.APPC-CL.events", "org.onap.policy.appc.Response");
+ noopSinkProperties.put("noop.sink.topics.APPC-CL.events.custom.gson",
+ "org.onap.policy.appc.util.Serialization,gsonPretty");
+ 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);
+
+ EventProtocolCoderConstants.getManager().addEncoder(EventProtocolParams.builder()
+ .groupId(JUNIT_GROUP_ID)
+ .artifactId(JUNIT_ARTIFACT_ID)
+ .topic("POLICY-CL-MGT")
+ .eventClass("org.onap.policy.controlloop.VirtualControlLoopNotification")
+ .protocolFilter(new JsonProtocolFilter())
+ .modelClassLoaderHash(1111));
+ EventProtocolCoderConstants.getManager().addEncoder(EventProtocolParams.builder()
+ .groupId(JUNIT_GROUP_ID)
+ .artifactId(JUNIT_ARTIFACT_ID)
+ .topic("APPC-LCM-READ")
+ .eventClass("org.onap.policy.appclcm.LcmRequestWrapper")
+ .protocolFilter(new JsonProtocolFilter())
+ .modelClassLoaderHash(1111));
+ EventProtocolCoderConstants.getManager().addEncoder(EventProtocolParams.builder()
+ .groupId(JUNIT_GROUP_ID)
+ .artifactId(JUNIT_ARTIFACT_ID)
+ .topic("APPC-CL")
+ .eventClass("org.onap.policy.appc.Request")
+ .protocolFilter(new JsonProtocolFilter())
+ .modelClassLoaderHash(1111));
+ EventProtocolCoderConstants.getManager().addEncoder(EventProtocolParams.builder()
+ .groupId(JUNIT_GROUP_ID)
+ .artifactId(JUNIT_ARTIFACT_ID)
+ .topic("SDNR-CL")
+ .eventClass("org.onap.policy.sdnr.PciRequestWrapper")
+ .protocolFilter(new JsonProtocolFilter())
+ .modelClassLoaderHash(1111));
+ try {
+ SupportUtil.buildAaiSim();
+ SupportUtil.buildSdncSim();
+ SupportUtil.buildSoSim();
+ SupportUtil.buildVfcSim();
+ SupportUtil.buildGuardSim();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+
+ /*
+ * Start the kie session
+ */
+ try {
+ kieSession = startSession(droolsTemplate, yamlFile, policyScope,
+ policyName, policyVersion);
+ } catch (IOException e) {
+ e.printStackTrace();
+ logger.debug("Could not create kieSession");
+ fail("Could not create kieSession");
+ }
+ }
+
+ /**
+ * Stops the simulators and the kie session.
+ */
+ @AfterClass
+ public static void tearDownAfterClass() {
+ /*
+ * Gracefully shut down the kie session
+ */
+ kieSession.dispose();
+
+ PolicyEngineConstants.getManager().stop();
+ HttpServletServerFactoryInstance.getServerFactory().destroy();
+ PolicyControllerConstants.getFactory().shutdown();
+ TopicEndpointManager.getManager().shutdown();
+ }
+
+ /**
+ * 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("============");
+ logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
+ logger.debug("============");
+
+ return kieSession;
+ }
+
+ /**
+ * 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);
+ }
+ }
+
+}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopEventCleanupTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopEventCleanupTest.java
index 928bcb80c..08215e958 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopEventCleanupTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopEventCleanupTest.java
@@ -46,11 +46,11 @@ import org.onap.policy.controlloop.ControlLoopEventStatus;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager;
import org.onap.policy.controlloop.policy.ControlLoopPolicy;
-import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
+import org.onap.policy.drools.protocol.coders.EventProtocolCoderConstants;
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.system.PolicyControllerConstants;
+import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.drools.utils.logging.LoggerUtil;
import org.onap.policy.template.demo.SupportUtil.Pair;
import org.slf4j.Logger;
@@ -107,13 +107,13 @@ public class ControlLoopEventCleanupTest {
public static void setUpSimulator() {
LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
- saveGuardFlag = PolicyEngine.manager.getEnvironmentProperty(GUARD_DISABLED);
- PolicyEngine.manager.getEnvironment().setProperty(GUARD_DISABLED, "true");
+ saveGuardFlag = PolicyEngineConstants.getManager().getEnvironmentProperty(GUARD_DISABLED);
+ PolicyEngineConstants.getManager().getEnvironment().setProperty(GUARD_DISABLED, "true");
SupportUtil.setAaiProps();
- PolicyEngine.manager.configure(new Properties());
- assertTrue(PolicyEngine.manager.start());
+ PolicyEngineConstants.getManager().configure(new Properties());
+ assertTrue(PolicyEngineConstants.getManager().start());
Properties noopSinkProperties = new Properties();
noopSinkProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS, "APPC-CL,POLICY-CL-MGT");
noopSinkProperties.put("noop.sink.topics.APPC-CL.events", "org.onap.policy.appc.Response");
@@ -125,14 +125,14 @@ public class ControlLoopEventCleanupTest {
"org.onap.policy.controlloop.util.Serialization,gsonPretty");
final List<TopicSink> noopTopics = TopicEndpointManager.getManager().addTopicSinks(noopSinkProperties);
- EventProtocolCoder.manager.addEncoder(EventProtocolParams.builder()
+ EventProtocolCoderConstants.getManager().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()
+ EventProtocolCoderConstants.getManager().addEncoder(EventProtocolParams.builder()
.groupId("junit.groupId")
.artifactId("junit.artifactId")
.topic("APPC-CL")
@@ -176,16 +176,16 @@ public class ControlLoopEventCleanupTest {
public static void tearDown() {
kieSession.dispose();
- PolicyEngine.manager.stop();
+ PolicyEngineConstants.getManager().stop();
HttpServletServerFactoryInstance.getServerFactory().destroy();
- PolicyController.factory.shutdown();
+ PolicyControllerConstants.getFactory().shutdown();
TopicEndpointManager.getManager().shutdown();
if (saveGuardFlag == null) {
- PolicyEngine.manager.getEnvironment().remove(GUARD_DISABLED);
+ PolicyEngineConstants.getManager().getEnvironment().remove(GUARD_DISABLED);
} else {
- PolicyEngine.manager.getEnvironment().setProperty(GUARD_DISABLED, saveGuardFlag);
+ PolicyEngineConstants.getManager().getEnvironment().setProperty(GUARD_DISABLED, saveGuardFlag);
}
}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java
index 6dbe17ee2..bc5a9828b 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopFailureTest.java
@@ -25,131 +25,42 @@ 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.appclcm.LcmRequest;
import org.onap.policy.appclcm.LcmRequestWrapper;
import org.onap.policy.appclcm.LcmResponse;
import org.onap.policy.appclcm.LcmResponseWrapper;
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.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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-public class ControlLoopFailureTest implements TopicListener {
+public class ControlLoopFailureTest extends ControlLoopBase implements TopicListener {
- private static final Logger logger = LoggerFactory.getLogger(ControlLoopFailureTest.class);
-
- private static List<? extends TopicSink> noopTopics;
-
- private static KieSession kieSession;
- private static SupportUtil.Pair<ControlLoopPolicy, String> pair;
- private UUID requestId;
private UUID requestId2;
private UUID requestId3;
private int eventCount;
- static {
- /* Set environment properties */
- SupportUtil.setAaiProps();
- SupportUtil.setGuardProps();
- SupportUtil.setPuProp();
- }
-
/**
* Setup 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, "APPC-LCM-READ,POLICY-CL-MGT");
- noopSinkProperties.put("noop.sink.topics.APPC-LCM-READ.events", "org.onap.policy.appclcm.LcmRequestWrapper");
- noopSinkProperties.put("noop.sink.topics.APPC-LCM-READ.events.custom.gson",
- "org.onap.policy.appclcm.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("APPC-LCM-READ")
- .eventClass("org.onap.policy.appclcm.LcmRequestWrapper")
- .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_vCPE.yaml",
- "service=ServiceDemo;resource=Res1Demo;type=operational", "CL_vCPE",
- "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");
- }
- }
-
- /**
- * Tear down 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_vCPE.yaml",
+ "service=ServiceDemo;resource=Res1Demo;type=operational",
+ "CL_vCPE",
+ "org.onap.closed_loop.ServiceDemo:VNFS:1.0.0");
}
/**
@@ -217,49 +128,6 @@ public class ControlLoopFailureTest implements TopicListener {
* Print what's left in memory
*/
dumpFacts(kieSession);
-
- }
-
- /**
- * 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 throws 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("============");
- logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
- logger.debug("============");
-
- return kieSession;
}
/*
@@ -387,18 +255,4 @@ public class ControlLoopFailureTest implements TopicListener {
event.setClosedLoopEventStatus(status);
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);
- }
- }
-
}
-
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/SupportUtil.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/SupportUtil.java
index 493ab9b2c..a4e8bef65 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/SupportUtil.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/SupportUtil.java
@@ -46,7 +46,7 @@ import org.kie.api.runtime.KieSession;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.controlloop.policy.ControlLoopPolicy;
import org.onap.policy.controlloop.policy.guard.ControlLoopGuard;
-import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.guard.PolicyGuardYamlToXacml;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -289,27 +289,27 @@ public final class SupportUtil {
* Set the A&AI properties.
*/
public static void setAaiProps() {
- PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
- PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
- PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
+ PolicyEngineConstants.getManager().setEnvironmentProperty("aai.url", "http://localhost:6666");
+ PolicyEngineConstants.getManager().setEnvironmentProperty("aai.username", "AAI");
+ PolicyEngineConstants.getManager().setEnvironmentProperty("aai.password", "AAI");
}
/**
* Set the SO properties.
*/
public static void setSoProps() {
- PolicyEngine.manager.setEnvironmentProperty("so.url", "http://localhost:6667");
- PolicyEngine.manager.setEnvironmentProperty("so.username", "SO");
- PolicyEngine.manager.setEnvironmentProperty("so.password", "SO");
+ PolicyEngineConstants.getManager().setEnvironmentProperty("so.url", "http://localhost:6667");
+ PolicyEngineConstants.getManager().setEnvironmentProperty("so.username", "SO");
+ PolicyEngineConstants.getManager().setEnvironmentProperty("so.password", "SO");
}
/**
* Set the SDNC properties.
*/
public static void setSdncProps() {
- PolicyEngine.manager.setEnvironmentProperty("sdnc.url", "http://localhost:6670/restconf/operations");
- PolicyEngine.manager.setEnvironmentProperty("sdnc.username", "sdnc");
- PolicyEngine.manager.setEnvironmentProperty("sdnc.password", "sdnc");
+ PolicyEngineConstants.getManager().setEnvironmentProperty("sdnc.url", "http://localhost:6670/restconf/operations");
+ PolicyEngineConstants.getManager().setEnvironmentProperty("sdnc.username", "sdnc");
+ PolicyEngineConstants.getManager().setEnvironmentProperty("sdnc.password", "sdnc");
}
/**
@@ -319,19 +319,21 @@ public final class SupportUtil {
/*
* Guard PDP-x connection Properties
*/
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_URL, "http://localhost:6669/policy/pdpx/v1/decision");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_USER, "python");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_PASS, "test");
- PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_DISABLED, "false");
+ PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_URL,
+ "http://localhost:6669/policy/pdpx/v1/decision");
+ PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_USER, "python");
+ PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_PASS, "test");
+ PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_DISABLED,
+ "false");
}
/**
* Set the VFC properties.
*/
public static void setVfcProps() {
- PolicyEngine.manager.setEnvironmentProperty("vfc.url", "http://localhost:6668/api/nslcm/v1");
- PolicyEngine.manager.setEnvironmentProperty("vfc.username", "VFC");
- PolicyEngine.manager.setEnvironmentProperty("vfc.password", "VFC");
+ PolicyEngineConstants.getManager().setEnvironmentProperty("vfc.url", "http://localhost:6668/api/nslcm/v1");
+ PolicyEngineConstants.getManager().setEnvironmentProperty("vfc.username", "VFC");
+ PolicyEngineConstants.getManager().setEnvironmentProperty("vfc.password", "VFC");
}
/**
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VcpeControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VcpeControlLoopTest.java
index 28706fd66..1cd431f50 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VcpeControlLoopTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VcpeControlLoopTest.java
@@ -25,130 +25,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.appclcm.LcmRequest;
import org.onap.policy.appclcm.LcmRequestWrapper;
import org.onap.policy.appclcm.LcmResponse;
import org.onap.policy.appclcm.LcmResponseWrapper;
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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-public class VcpeControlLoopTest implements TopicListener {
-
- private static final Logger logger = LoggerFactory.getLogger(VcpeControlLoopTest.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, "INFO");
- }
+public class VcpeControlLoopTest 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, "APPC-LCM-READ,POLICY-CL-MGT");
- noopSinkProperties.put("noop.sink.topics.APPC-LCM-READ.events", "org.onap.policy.appclcm.LcmRequestWrapper");
- noopSinkProperties.put("noop.sink.topics.APPC-LCM-READ.events.custom.gson",
- "org.onap.policy.appclcm.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("APPC-LCM-READ")
- .eventClass("org.onap.policy.appclcm.LcmRequestWrapper")
- .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_vCPE.yaml",
- "service=ServiceDemo;resource=Res1Demo;type=operational", "CL_vCPE",
- "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");
- }
- }
-
- /**
- * 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_vCPE.yaml",
+ "service=ServiceDemo;resource=Res1Demo;type=operational",
+ "CL_vCPE",
+ "org.onap.closed_loop.ServiceDemo:VNFS:1.0.0");
}
@Test
@@ -228,49 +137,6 @@ public class VcpeControlLoopTest implements TopicListener {
* Print what's left in memory
*/
dumpFacts(kieSession);
-
- }
-
- /**
- * 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("============");
- logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
- logger.debug("============");
-
- return kieSession;
}
/*
@@ -406,17 +272,4 @@ public class VcpeControlLoopTest implements TopicListener {
event.setClosedLoopEventStatus(status);
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);
- }
- }
-
}
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 3e5825bc1..d1453f7b1 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
@@ -25,119 +25,35 @@ 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.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.so.SoRequest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-public class VdnsControlLoopTest implements TopicListener {
-
- private static final Logger logger = LoggerFactory.getLogger(VdnsControlLoopTest.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.setSoProps();
- SupportUtil.setGuardProps();
- SupportUtil.setPuProp();
- LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
- }
+public class VdnsControlLoopTest 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, "POLICY-CL-MGT");
- 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));
-
- try {
- SupportUtil.buildAaiSim();
- SupportUtil.buildSoSim();
- 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_SO-test.yaml", "type=operational", "CL_vDNS", "v2.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_SO-test.yaml",
+ "type=operational",
+ "CL_vDNS",
+ "v2.0");
}
@Test
@@ -265,48 +181,6 @@ public class VdnsControlLoopTest implements TopicListener {
dumpFacts(kieSession);
}
- /**
- * 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("============");
- logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
- logger.debug("============");
-
- return kieSession;
- }
-
/*
* (non-Javadoc)
*
@@ -410,16 +284,4 @@ public class VdnsControlLoopTest implements TopicListener {
event.setClosedLoopEventStatus(status);
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);
- }
- }
}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcControlLoopTest.java
index fdf27490c..4f47bd0a9 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcControlLoopTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VfcControlLoopTest.java
@@ -27,120 +27,37 @@ 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.vfc.VfcRequest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-public class VfcControlLoopTest implements TopicListener {
-
- private static final Logger logger = LoggerFactory.getLogger(VfcControlLoopTest.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.setVfcProps();
- SupportUtil.setGuardProps();
- SupportUtil.setPuProp();
- LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
- }
+public class VfcControlLoopTest 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, "POLICY-CL-MGT");
- 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));
-
- try {
- SupportUtil.buildAaiSim();
- SupportUtil.buildVfcSim();
- 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_VFC.yaml", "type=operational", "CL_VoLTE", "v2.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_VFC.yaml",
+ "type=operational",
+ "CL_VoLTE",
+ "v2.0");
}
@Test
@@ -233,48 +150,6 @@ public class VfcControlLoopTest implements TopicListener {
dumpFacts(kieSession);
}
- /**
- * 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("============");
- logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
- logger.debug("============");
-
- return kieSession;
- }
-
/*
* (non-Javadoc)
*
@@ -369,18 +244,4 @@ public class VfcControlLoopTest implements TopicListener {
event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
kieSession.insert(event);
}
-
- /**
- * Dumps the kie session facts.
- *
- * @param kieSession input session
- */
- public static void dumpFacts(KieSession kieSession) {
- logger.debug("Fact Count: " + kieSession.getFactCount());
- for (FactHandle handle : kieSession.getFactHandles()) {
- logger.debug("FACT: " + handle);
- }
- }
-
}
-
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 327a1b4dc..221ef5e6b 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
@@ -25,130 +25,37 @@ 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.appc.Request;
import org.onap.policy.appc.Response;
import org.onap.policy.appc.ResponseCode;
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.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.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class VfwControlLoopTest implements TopicListener {
-
- private static final Logger logger = LoggerFactory.getLogger(VfwControlLoopTest.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, "INFO");
- }
+
+public class VfwControlLoopTest 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, "APPC-CL,POLICY-CL-MGT");
- noopSinkProperties.put("noop.sink.topics.APPC-CL.events", "org.onap.policy.appc.Response");
- noopSinkProperties.put("noop.sink.topics.APPC-CL.events.custom.gson",
- "org.onap.policy.appc.util.Serialization,gsonPretty");
- 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("APPC-CL")
- .eventClass("org.onap.policy.appc.Request")
- .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_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");
- }
- }
-
- /**
- * 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_vFW.yaml",
+ "service=ServiceDemo;resource=Res1Demo;type=operational",
+ "CL_vFW",
+ "org.onap.closed_loop.ServiceDemo:VNFS:1.0.0");
}
@Test
@@ -277,48 +184,6 @@ public class VfwControlLoopTest implements TopicListener {
dumpFacts(kieSession);
}
- /**
- * 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("============");
- logger.debug(URLEncoder.encode(pair.second, "UTF-8"));
- logger.debug("============");
-
- return kieSession;
- }
-
/*
* @see org.onap.policy.drools.PolicyEngineListener#newEventNotification(java.lang.String)
*/
@@ -441,16 +306,4 @@ public class VfwControlLoopTest implements TopicListener {
event.setClosedLoopEventStatus(status);
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);
- }
- }
}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VpciControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VpciControlLoopTest.java
index 3278d4396..9d3486f5b 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VpciControlLoopTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VpciControlLoopTest.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 VpciControlLoopTest implements TopicListener {
-
- private static final Logger logger = LoggerFactory.getLogger(VpciControlLoopTest.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 VpciControlLoopTest 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_vPCI.yaml", "type=operational", "CL_vPCI", "v3.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_vPCI.yaml",
+ "type=operational",
+ "CL_vPCI",
+ "v3.0.0");
}
@Test
@@ -230,56 +141,6 @@ public class VpciControlLoopTest 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)
*
@@ -419,18 +280,4 @@ public class VpciControlLoopTest 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);
- }
- }
-
}
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);
- }
- }
-
}