summaryrefslogtreecommitdiffstats
path: root/controlloop/templates
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/templates')
-rw-r--r--controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl66
-rw-r--r--controlloop/templates/archetype-cl-usecases/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl68
-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
14 files changed, 409 insertions, 1479 deletions
diff --git a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
index f28ee173f..049bd9a23 100644
--- a/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
+++ b/controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
@@ -73,7 +73,7 @@ import java.time.Instant;
import java.util.LinkedList;
import java.util.Iterator;
-import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.drools.system.PolicyEngineConstants;
/*
* This structure mimics the Params structure.
@@ -191,7 +191,7 @@ rule "${policyName}.EVENT"
//
// Let interested parties know
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Retract it from memory
@@ -225,7 +225,7 @@ rule "${policyName}.EVENT"
//
// Let interested parties know
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Setup the Overall Control Loop timer
//
@@ -242,7 +242,7 @@ rule "${policyName}.EVENT"
//
// Let interested parties know
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Retract it from memory
//
@@ -267,7 +267,7 @@ rule "${policyName}.EVENT"
//
//
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Retract the event
//
@@ -364,7 +364,7 @@ rule "${policyName}.EVENT.MANAGER"
//
// In this case, we are done
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Unlock the target
//
@@ -409,7 +409,7 @@ rule "${policyName}.EVENT.MANAGER"
//
// In this case, we are done
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Unlock the target
//
@@ -475,7 +475,7 @@ rule "${policyName}.EVENT.MANAGER"
notification.setPolicyScope("${policyScope}");
notification.setPolicyVersion("${policyVersion}");
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
retract($event);
@@ -509,7 +509,7 @@ rule "${policyName}.EVENT.MANAGER"
notification.setPolicyScope("${policyScope}");
notification.setPolicyVersion("${policyVersion}");
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
retract($event);
@@ -562,16 +562,16 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
notification.setPolicyScope("${policyScope}");
notification.setPolicyVersion("${policyVersion}");
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
switch ($operation.policy.getActor()){
case "APPC":
if (request instanceof Request) {
- PolicyEngine.manager.deliver("APPC-CL", request);
+ PolicyEngineConstants.getManager().deliver("APPC-CL", request);
}
else if (request instanceof LcmRequestWrapper) {
- PolicyEngine.manager.deliver("APPC-LCM-READ", request);
+ PolicyEngineConstants.getManager().deliver("APPC-LCM-READ", request);
}
break;
case "SO":
@@ -589,9 +589,9 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
SoActorServiceProvider.sendRequest($event.getRequestId().toString(),
new mySoCallback(),
request,
- PolicyEngine.manager.getEnvironmentProperty("so.url"),
- PolicyEngine.manager.getEnvironmentProperty("so.username"),
- PolicyEngine.manager.getEnvironmentProperty("so.password"));
+ PolicyEngineConstants.getManager().getEnvironmentProperty("so.url"),
+ PolicyEngineConstants.getManager().getEnvironmentProperty("so.username"),
+ PolicyEngineConstants.getManager().getEnvironmentProperty("so.password"));
}
break;
case "VFC":
@@ -606,9 +606,9 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
// Start VFC thread
Thread t = new Thread(new VfcManager(new myVfcCallback(),
(VfcRequest)request,
- PolicyEngine.manager.getEnvironmentProperty("vfc.url"),
- PolicyEngine.manager.getEnvironmentProperty("vfc.username"),
- PolicyEngine.manager.getEnvironmentProperty("vfc.password")));
+ PolicyEngineConstants.getManager().getEnvironmentProperty("vfc.url"),
+ PolicyEngineConstants.getManager().getEnvironmentProperty("vfc.username"),
+ PolicyEngineConstants.getManager().getEnvironmentProperty("vfc.password")));
t.start();
}
break;
@@ -624,15 +624,15 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
// Start SDNC thread
Thread t = new Thread(new SdncManager(new mySdncCallback(),
(SdncRequest)request,
- PolicyEngine.manager.getEnvironmentProperty("sdnc.url"),
- PolicyEngine.manager.getEnvironmentProperty("sdnc.username"),
- PolicyEngine.manager.getEnvironmentProperty("sdnc.password")));
+ PolicyEngineConstants.getManager().getEnvironmentProperty("sdnc.url"),
+ PolicyEngineConstants.getManager().getEnvironmentProperty("sdnc.username"),
+ PolicyEngineConstants.getManager().getEnvironmentProperty("sdnc.password")));
t.start();
}
break;
case "SDNR":
if (request instanceof PciRequestWrapper) {
- PolicyEngine.manager.deliver("SDNR-CL", request);
+ PolicyEngineConstants.getManager().deliver("SDNR-CL", request);
}
break;
}
@@ -680,7 +680,7 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
notification.setMessage($operation.getOperationHistory());
notification.setHistory($operation.getHistory());
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
}
retract($opTimer);
@@ -730,7 +730,7 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED"
notification.setPolicyScope("${policyScope}");
notification.setPolicyVersion("${policyVersion}");
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Now send Guard Request to XACML Guard. In order to bypass the call to Guard,
@@ -742,7 +742,7 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED"
//
// NOTE: The environment properties uses "guard.disabled" but the boolean is guardEnabled
- boolean guardEnabled = "false".equalsIgnoreCase(PolicyEngine.manager.getEnvironmentProperty("guard.disabled"));
+ boolean guardEnabled = "false".equalsIgnoreCase(PolicyEngineConstants.getManager().getEnvironmentProperty("guard.disabled"));
if(guardEnabled){
@@ -808,7 +808,7 @@ rule "${policyName}.GUARD.RESPONSE"
notification.setPolicyScope("${policyScope}");
notification.setPolicyVersion("${policyVersion}");
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
if("Permit".equalsIgnoreCase($guardResponse.getResult())){
@@ -881,13 +881,13 @@ rule "${policyName}.APPC.RESPONSE"
//
// Let interested parties know
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
} else {
notification.setNotification(ControlLoopNotificationType.OPERATION_FAILURE);
//
// Let interested parties know
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
}
//
// Ensure the operation is complete
@@ -1001,7 +1001,7 @@ rule "${policyName}.APPC.LCM.RESPONSE"
} else {
notification.setNotification(ControlLoopNotificationType.OPERATION_FAILURE);
}
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Ensure the operation is complete
//
@@ -1110,7 +1110,7 @@ rule "${policyName}.SDNR.RESPONSE"
} else {
notification.setNotification(ControlLoopNotificationType.OPERATION_FAILURE);
}
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Ensure the operation is complete
//
@@ -1219,7 +1219,7 @@ rule "${policyName}.SO.RESPONSE"
notification.setNotification(ControlLoopNotificationType.OPERATION_FAILURE);
}
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Ensure the operation is complete
//
@@ -1468,7 +1468,7 @@ rule "${policyName}.EVENT.MANAGER.OPERATION.TIMEOUT"
//
// Let interested parties know
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Get rid of the timer
//
@@ -1526,7 +1526,7 @@ rule "${policyName}.EVENT.MANAGER.TIMEOUT"
//
// Let interested parties know
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
}
//
// Retract the event
diff --git a/controlloop/templates/archetype-cl-usecases/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl b/controlloop/templates/archetype-cl-usecases/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
index a9e17c3c4..37d7b6936 100644
--- a/controlloop/templates/archetype-cl-usecases/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
+++ b/controlloop/templates/archetype-cl-usecases/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
@@ -77,7 +77,7 @@ import java.time.Instant;
import java.util.LinkedList;
import java.util.Iterator;
-import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.drools.system.PolicyEngineConstants;
/*
* This object is to provide support for timeouts
@@ -180,7 +180,7 @@ rule "EVENT"
//
// Let interested parties know
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Retract it from memory
@@ -213,7 +213,7 @@ rule "EVENT"
//
// Let interested parties know
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Setup the Overall Control Loop timer
//
@@ -230,7 +230,7 @@ rule "EVENT"
//
// Let interested parties know
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Retract it from memory
//
@@ -255,7 +255,7 @@ rule "EVENT"
//
//
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Retract the event
//
@@ -348,7 +348,7 @@ rule "EVENT.MANAGER"
//
// In this case, we are done
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Unlock the target
//
@@ -393,7 +393,7 @@ rule "EVENT.MANAGER"
//
// In this case, we are done
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Unlock the target
//
@@ -461,7 +461,7 @@ rule "EVENT.MANAGER"
notification.setPolicyScope($params.getPolicyScope());
notification.setPolicyVersion($params.getPolicyVersion());
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
retract($event);
@@ -495,7 +495,7 @@ rule "EVENT.MANAGER"
notification.setPolicyScope($params.getPolicyScope());
notification.setPolicyVersion($params.getPolicyVersion());
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
retract($event);
@@ -549,17 +549,17 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
notification.setPolicyScope($params.getPolicyScope());
notification.setPolicyVersion($params.getPolicyVersion());
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
switch ($operation.policy.getActor()){
case "APPC":
if (request instanceof Request) {
- PolicyEngine.manager.deliver("APPC-CL", request);
+ PolicyEngineConstants.getManager().deliver("APPC-CL", request);
}
else if (request instanceof LcmRequestWrapper) {
- PolicyEngine.manager.deliver("APPC-LCM-READ", request);
+ PolicyEngineConstants.getManager().deliver("APPC-LCM-READ", request);
}
break;
case "SO":
@@ -576,9 +576,9 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
SoActorServiceProvider.sendRequest($event.getRequestId().toString(),
new mySoCallback(),
request,
- PolicyEngine.manager.getEnvironmentProperty("so.url"),
- PolicyEngine.manager.getEnvironmentProperty("so.username"),
- PolicyEngine.manager.getEnvironmentProperty("so.password"));
+ PolicyEngineConstants.getManager().getEnvironmentProperty("so.url"),
+ PolicyEngineConstants.getManager().getEnvironmentProperty("so.username"),
+ PolicyEngineConstants.getManager().getEnvironmentProperty("so.password"));
}
break;
case "VFC":
@@ -592,15 +592,15 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
// Start VFC thread
Thread t = new Thread(new VfcManager(new myVfcCallback(),
(VfcRequest)request,
- PolicyEngine.manager.getEnvironmentProperty("vfc.url"),
- PolicyEngine.manager.getEnvironmentProperty("vfc.username"),
- PolicyEngine.manager.getEnvironmentProperty("vfc.password")));
+ PolicyEngineConstants.getManager().getEnvironmentProperty("vfc.url"),
+ PolicyEngineConstants.getManager().getEnvironmentProperty("vfc.username"),
+ PolicyEngineConstants.getManager().getEnvironmentProperty("vfc.password")));
t.start();
}
break;
case "SDNR":
if (request instanceof PciRequestWrapper) {
- PolicyEngine.manager.deliver("SDNR-CL", request);
+ PolicyEngineConstants.getManager().deliver("SDNR-CL", request);
}
break;
@@ -614,9 +614,9 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
// Start SDNC thread
Thread t = new Thread(new SdncManager(new mySdncCallback(),
(SdncRequest)request,
- PolicyEngine.manager.getEnvironmentProperty("sdnc.url"),
- PolicyEngine.manager.getEnvironmentProperty("sdnc.username"),
- PolicyEngine.manager.getEnvironmentProperty("sdnc.password")));
+ PolicyEngineConstants.getManager().getEnvironmentProperty("sdnc.url"),
+ PolicyEngineConstants.getManager().getEnvironmentProperty("sdnc.username"),
+ PolicyEngineConstants.getManager().getEnvironmentProperty("sdnc.password")));
t.start();
}
break;
@@ -666,7 +666,7 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_PERMITTED"
notification.setMessage($operation.getOperationHistory());
notification.setHistory($operation.getHistory());
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
}
retract($opTimer);
@@ -716,7 +716,7 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED"
notification.setPolicyScope($params.getPolicyScope());
notification.setPolicyVersion($params.getPolicyVersion());
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Now send Guard Request to XACML Guard. In order to bypass the call to Guard,
@@ -728,7 +728,7 @@ rule "EVENT.MANAGER.OPERATION.LOCKED.GUARD_NOT_YET_QUERIED"
//
// NOTE: The environment properties uses "guard.disabled" but the boolean is guardEnabled
- boolean guardEnabled = "false".equalsIgnoreCase(PolicyEngine.manager.getEnvironmentProperty("guard.disabled"));
+ boolean guardEnabled = "false".equalsIgnoreCase(PolicyEngineConstants.getManager().getEnvironmentProperty("guard.disabled"));
if(guardEnabled){
@@ -794,7 +794,7 @@ rule "GUARD.RESPONSE"
notification.setPolicyScope($params.getPolicyScope());
notification.setPolicyVersion($params.getPolicyVersion());
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
if("Permit".equalsIgnoreCase($guardResponse.getResult())){
@@ -867,13 +867,13 @@ rule "APPC.RESPONSE"
//
// Let interested parties know
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
} else {
notification.setNotification(ControlLoopNotificationType.OPERATION_FAILURE);
//
// Let interested parties know
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
}
//
// Ensure the operation is complete
@@ -987,7 +987,7 @@ rule "APPC.LCM.RESPONSE"
} else {
notification.setNotification(ControlLoopNotificationType.OPERATION_FAILURE);
}
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Ensure the operation is complete
//
@@ -1096,7 +1096,7 @@ rule "SO.RESPONSE"
notification.setNotification(ControlLoopNotificationType.OPERATION_FAILURE);
}
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Ensure the operation is complete
//
@@ -1341,7 +1341,7 @@ rule "EVENT.MANAGER.OPERATION.TIMEOUT"
//
// Let interested parties know
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
//
// Get rid of the timer
//
@@ -1399,7 +1399,7 @@ rule "EVENT.MANAGER.TIMEOUT"
//
// Let interested parties know
//
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
}
//
// Retract the event
@@ -1525,10 +1525,10 @@ rule "SDNR.RESPONSE"
} else {
notification.setNotification(ControlLoopNotificationType.OPERATION_FAILURE);
}
- PolicyEngine.manager.deliver("POLICY-CL-MGT", notification);
+ PolicyEngineConstants.getManager().deliver("POLICY-CL-MGT", notification);
ControlLoopResponse clResponse = $operation.getControlLoopResponse($response, $event);
- PolicyEngine.manager.deliver("DCAE_CL_RSP", clResponse);
+ PolicyEngineConstants.getManager().deliver("DCAE_CL_RSP", clResponse);
//
// Ensure the operation is complete
//
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);
- }
- }
-
}