aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/templates
diff options
context:
space:
mode:
authorTemoc Rodriguez <cr056n@att.com>2017-09-01 08:52:02 -0700
committerTemoc Rodriguez <cr056n@att.com>2017-09-07 09:48:49 -0700
commita91cb6c62a217238bbfccf16fb1440e3fec174de (patch)
treee74ca6d86d5811da0be4ccaf75141e40042cf20a /controlloop/templates
parent37b497d346a65ee9de077fdb24bee73cfe19b50e (diff)
Add in-mem db to ControlLoopXacmlGuardTest
Add in-mem specification in test/resources/META-INF/persistence.xml for junit. Use system properties to choose which db to use. Removed named parameters in PIPEngineHistory.java. Change 6.3.0 versions of drools-core to 6.5.0 in pom. Make PIPEngineGetHistory query more general. Increased sleep times in junit. Issue-ID: POLICY-55 Change-Id: I6bc65fd88c43c4e7143f27a7e6d8666c2c4df060 Signed-off-by: Temoc Rodriguez <cr056n@att.com>
Diffstat (limited to 'controlloop/templates')
-rw-r--r--controlloop/templates/template.demo/pom.xml12
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/AaiSimulatorTest.java10
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopXacmlGuardTest.java169
-rw-r--r--controlloop/templates/template.demo/src/test/resources/META-INF/persistence.xml22
4 files changed, 125 insertions, 88 deletions
diff --git a/controlloop/templates/template.demo/pom.xml b/controlloop/templates/template.demo/pom.xml
index 5436b5ebd..eb85f7fdc 100644
--- a/controlloop/templates/template.demo/pom.xml
+++ b/controlloop/templates/template.demo/pom.xml
@@ -7,9 +7,9 @@
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.
@@ -197,5 +197,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>[1.4.186,)</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
-</project> \ No newline at end of file
+</project>
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/AaiSimulatorTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/AaiSimulatorTest.java
index 71c6e3a29..3bddbc50d 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/AaiSimulatorTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/AaiSimulatorTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -35,7 +35,7 @@ import org.onap.policy.aai.AAINQF199.AAINQF199Response;
import org.onap.policy.drools.http.server.HttpServletServer;
public class AaiSimulatorTest {
-
+
@BeforeClass
public static void setUpSimulator() {
try {
@@ -44,12 +44,12 @@ public class AaiSimulatorTest {
fail(e.getMessage());
}
}
-
+
@AfterClass
public static void tearDownSimulator() {
HttpServletServer.factory.destroy();
}
-
+
@Test
public void testGet() {
AAIGETResponse response = AAINQF199Manager.getQuery("http://localhost:6666", "testUser", "testPass", UUID.randomUUID(), "5e49ca06-2972-4532-9ed4-6d071588d792");
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopXacmlGuardTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopXacmlGuardTest.java
index 8c0b99462..d1fa4fc10 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopXacmlGuardTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/ControlLoopXacmlGuardTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -34,7 +34,6 @@ import java.util.UUID;
import org.junit.AfterClass;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.FactHandle;
@@ -44,7 +43,6 @@ import org.onap.policy.appclcm.LCMResponse;
import org.onap.policy.appclcm.LCMResponseWrapper;
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;
@@ -54,7 +52,7 @@ import org.onap.policy.drools.impl.PolicyEngineJUnitImpl;
import org.onap.policy.guard.PolicyGuard;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-//import org.onap.policy.controlloop.policy.guard.ControlLoopGuard;
+
public class ControlLoopXacmlGuardTest {
@@ -66,32 +64,42 @@ public class ControlLoopXacmlGuardTest {
fail(e.getMessage());
}
}
-
+
@AfterClass
public static void tearDownSimulator() {
HttpServletServer.factory.destroy();
}
-
+
private static final Logger logger = LoggerFactory.getLogger(ControlLoopXacmlGuardTest.class);
+ private static final String OPSHISTPUPROP = "OperationsHistoryPU";
+ @BeforeClass
+ public static void setPUProp(){
+ System.setProperty(OPSHISTPUPROP, "TestOperationsHistoryPU");
+ }
+ @AfterClass
+ public static void restorePUProp(){
+ System.setProperty(OPSHISTPUPROP, OPSHISTPUPROP);
+ }
+
@Test
public void test() {
try {
- this.runTest("src/main/resources/ControlLoop_Template_xacml_guard.drl",
+ this.runTest("src/main/resources/ControlLoop_Template_xacml_guard.drl",
"src/test/resources/yaml/policy_ControlLoop_Service123.yaml",
- "service=Service123;resource=Res123;type=operational",
- "CL_SERV123_8888",
+ "service=Service123;resource=Res123;type=operational",
+ "CL_SERV123_8888",
"org.onap.closed_loop.Service123:VNFS:0.0.1");
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
-
- public void runTest(String droolsTemplate,
- String yamlFile,
- String policyScope,
- String policyName,
+
+ public void runTest(String droolsTemplate,
+ String yamlFile,
+ String policyScope,
+ String policyName,
String policyVersion) throws IOException {
//
// Pull info from the yaml
@@ -105,20 +113,21 @@ public class ControlLoopXacmlGuardTest {
//
// Build a container
//
- final KieSession kieSession = Util.buildContainer(droolsTemplate,
- pair.a.getControlLoop().getControlLoopName(),
- policyScope,
- policyName,
- policyVersion,
+ final KieSession kieSession = Util.buildContainer(droolsTemplate,
+ pair.a.getControlLoop().getControlLoopName(),
+ policyScope,
+ policyName,
+ policyVersion,
URLEncoder.encode(pair.b, "UTF-8"));
-
-
+
+
+
logger.debug("============");
logger.debug(URLEncoder.encode(pair.b, "UTF-8"));
logger.debug("============");
-
+
final PolicyEngineJUnitImpl engine = (PolicyEngineJUnitImpl) kieSession.getGlobal("Engine");
-
+
//
// Initial fire of rules
//
@@ -132,17 +141,17 @@ public class ControlLoopXacmlGuardTest {
@Override
public void run() {
try {
-
-
+
+
//
// Let's use a unique ID for the request and
// a unique trigger source.
//
UUID requestID = UUID.randomUUID();
String triggerSourceName = "foobartriggersource36";
-
+
Object obj = null;
-
+
sendGoodEvents(kieSession, pair.a, requestID, triggerSourceName);
obj = engine.subscribe("UEB", "POLICY-CL-MGT");
assertNotNull(obj);
@@ -151,9 +160,9 @@ public class ControlLoopXacmlGuardTest {
//
// Give the control loop a little time to acquire the lock and publish the request
//
- Thread.sleep(2000);
-
-
+ Thread.sleep(4000);
+
+
// "About to query Guard" notification (Querying about Restart)
obj = engine.subscribe("UEB", "POLICY-CL-MGT");
assertNotNull(obj);
@@ -161,18 +170,18 @@ public class ControlLoopXacmlGuardTest {
logger.debug("Rule: {} Message {}", ((VirtualControlLoopNotification)obj).policyName, ((VirtualControlLoopNotification)obj).message);
assertTrue(obj instanceof VirtualControlLoopNotification);
assertTrue(((VirtualControlLoopNotification)obj).notification.equals(ControlLoopNotificationType.OPERATION));
-
- Thread.sleep(2000);
+
+ Thread.sleep(4000);
// "Response from Guard" notification
obj = engine.subscribe("UEB", "POLICY-CL-MGT");
assertNotNull(obj);
logger.debug("Rule: {} Message {}", ((VirtualControlLoopNotification)obj).policyName, ((VirtualControlLoopNotification)obj).message);
assertTrue(obj instanceof VirtualControlLoopNotification);
assertTrue(((VirtualControlLoopNotification)obj).notification.equals(ControlLoopNotificationType.OPERATION));
-
-
+
+
if(true == ((VirtualControlLoopNotification)obj).message.contains("Guard result: Deny")){
-
+
// "About to query Guard" notification (Querying about Rebuild)
obj = engine.subscribe("UEB", "POLICY-CL-MGT");
assertNotNull(obj);
@@ -180,19 +189,19 @@ public class ControlLoopXacmlGuardTest {
logger.debug("Rule: {} Message", ((VirtualControlLoopNotification)obj).policyName, ((VirtualControlLoopNotification)obj).message);
assertTrue(obj instanceof VirtualControlLoopNotification);
assertTrue(((VirtualControlLoopNotification)obj).notification.equals(ControlLoopNotificationType.OPERATION));
-
- Thread.sleep(2000);
-
+
+ Thread.sleep(4000);
+
// "Response from Guard" notification
obj = engine.subscribe("UEB", "POLICY-CL-MGT");
assertNotNull(obj);
logger.debug("Rule: {} Message {}", ((VirtualControlLoopNotification)obj).policyName, ((VirtualControlLoopNotification)obj).message);
assertTrue(obj instanceof VirtualControlLoopNotification);
assertTrue(((VirtualControlLoopNotification)obj).notification.equals(ControlLoopNotificationType.OPERATION));
-
-
+
+
if(true == ((VirtualControlLoopNotification)obj).message.contains("Guard result: Deny")){
-
+
// "About to query Guard" notification (Querying about Migrate)
obj = engine.subscribe("UEB", "POLICY-CL-MGT");
assertNotNull(obj);
@@ -200,25 +209,25 @@ public class ControlLoopXacmlGuardTest {
logger.debug("Rule: {} Message {}", ((VirtualControlLoopNotification)obj).policyName, ((VirtualControlLoopNotification)obj).message);
assertTrue(obj instanceof VirtualControlLoopNotification);
assertTrue(((VirtualControlLoopNotification)obj).notification.equals(ControlLoopNotificationType.OPERATION));
-
- Thread.sleep(2000);
-
+
+ Thread.sleep(4000);
+
// "Response from Guard" notification
obj = engine.subscribe("UEB", "POLICY-CL-MGT");
assertNotNull(obj);
logger.debug("Rule: " + ((VirtualControlLoopNotification)obj).policyName +" Message: " + ((VirtualControlLoopNotification)obj).message);
assertTrue(obj instanceof VirtualControlLoopNotification);
assertTrue(((VirtualControlLoopNotification)obj).notification.equals(ControlLoopNotificationType.OPERATION));
-
-
+
+
if(true == ((VirtualControlLoopNotification)obj).message.contains("Guard result: Deny")){
//All the 3 operations were Denied by Guard
- Thread.sleep(30000);
-
- }
+ Thread.sleep(60000);
+
+ }
}
}
-
+
//
// In case one of the operations was permitted by Guard
//
@@ -228,16 +237,16 @@ public class ControlLoopXacmlGuardTest {
logger.debug("Rule: {} Message {}", ((VirtualControlLoopNotification)obj).policyName, ((VirtualControlLoopNotification)obj).message);
assertTrue(obj instanceof VirtualControlLoopNotification);
assertTrue(((VirtualControlLoopNotification)obj).notification.equals(ControlLoopNotificationType.OPERATION));
-
- Thread.sleep(500);
-
+
+ Thread.sleep(1000);
+
obj = engine.subscribe("UEB", "APPC-CL");
assertNotNull(obj);
assertTrue(obj instanceof LCMRequestWrapper);
LCMRequestWrapper dmaapRequest = (LCMRequestWrapper) obj;
LCMRequest appcRequest = dmaapRequest.getBody();
assertTrue(appcRequest.getCommonHeader().getSubRequestId().equals("1"));
-
+
logger.debug("\n============ APP-C Got request!!! ===========\n");
//
// Ok - let's simulate ACCEPT
@@ -246,8 +255,8 @@ public class ControlLoopXacmlGuardTest {
//
// now wait for it to finish
//
- Thread.sleep(500);
-
+ Thread.sleep(1000);
+
//
// Now we are going to success it
//
@@ -260,7 +269,7 @@ public class ControlLoopXacmlGuardTest {
//
// Give it some time to process
//
- Thread.sleep(2000);
+ Thread.sleep(4000);
//
// Insert the abatement event
//
@@ -268,16 +277,16 @@ public class ControlLoopXacmlGuardTest {
//
// now wait for it to finish
//
- Thread.sleep(15000);
+ Thread.sleep(15000);
//
// Ensure they released the lock
//
assertFalse(PolicyGuard.isLocked(TargetType.VM, triggerSourceName, requestID));
-
+
}
-
-
-
+
+
+
} catch (InterruptedException e) {
logger.error("Test thread got InterruptedException ", e.getLocalizedMessage());
} catch (AssertionError e) {
@@ -289,7 +298,7 @@ public class ControlLoopXacmlGuardTest {
}
kieSession.halt();
}
-
+
}).start();
//
// Start firing rules
@@ -303,17 +312,17 @@ public class ControlLoopXacmlGuardTest {
// See if there is anything left in memory
//
assertEquals(1, kieSession.getFactCount());
-
+
for (FactHandle handle : kieSession.getFactHandles()) {
Object fact = kieSession.getObject(handle);
assertEquals("", "org.onap.policy.controlloop.Params", fact.getClass().getName());
}
kieSession.dispose();
}
-
-
-
+
+
+
public static void dumpFacts(KieSession kieSession) {
logger.debug("Fact Count: {}", kieSession.getFactCount());
for (FactHandle handle : kieSession.getFactHandles()) {
@@ -336,7 +345,7 @@ public class ControlLoopXacmlGuardTest {
event.closedLoopEventStatus = ControlLoopEventStatus.ABATED;
kieSession.insert(event);
}
-
+
protected void sendGoodEvents(KieSession kieSession, ControlLoopPolicy policy, UUID requestID, String triggerSourceName) throws InterruptedException {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.closedLoopControlName = policy.getControlLoop().getControlLoopName();
@@ -350,10 +359,10 @@ public class ControlLoopXacmlGuardTest {
event.AAI.put("vserver.vserver-name", "testGenericVnfName");
event.closedLoopEventStatus = ControlLoopEventStatus.ONSET;
kieSession.insert(event);
- Thread.sleep(1000);
-
+ Thread.sleep(2000);
+
}
-
+
protected void sendBadEvents(KieSession kieSession, ControlLoopPolicy policy, UUID requestID, String triggerSourceName) throws InterruptedException {
//
// Insert a bad Event
@@ -361,13 +370,13 @@ public class ControlLoopXacmlGuardTest {
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.closedLoopControlName = policy.getControlLoop().getControlLoopName();
kieSession.insert(event);
- Thread.sleep(250);
+ Thread.sleep(500);
//
// add the request id
//
event.requestID = requestID;
kieSession.insert(event);
- Thread.sleep(250);
+ Thread.sleep(500);
//
// add some aai
//
@@ -376,35 +385,35 @@ public class ControlLoopXacmlGuardTest {
event.AAI.put("vserver.selflink", "bar");
event.AAI.put("vserver.vserver-name", "vmfoo");
kieSession.insert(event);
- Thread.sleep(250);
+ Thread.sleep(500);
//
// set a valid status
//
event.closedLoopEventStatus = ControlLoopEventStatus.ONSET;
kieSession.insert(event);
- Thread.sleep(250);
+ Thread.sleep(500);
//
// add a trigger sourcename
//
kieSession.insert(event);
- Thread.sleep(250);
+ Thread.sleep(500);
//
// add is closed-loop-disabled
//
event.AAI.put("vserver.is-closed-loop-disabled", "true");
kieSession.insert(event);
- Thread.sleep(250);
+ Thread.sleep(500);
//
// now enable
//
event.AAI.put("vserver.is-closed-loop-disabled", "false");
kieSession.insert(event);
- Thread.sleep(250);
+ Thread.sleep(500);
//
// Add target, but bad.
//
event.target = "VM_BLAH";
kieSession.insert(event);
- Thread.sleep(250);
+ Thread.sleep(500);
}
}
diff --git a/controlloop/templates/template.demo/src/test/resources/META-INF/persistence.xml b/controlloop/templates/template.demo/src/test/resources/META-INF/persistence.xml
new file mode 100644
index 000000000..c3740d0b2
--- /dev/null
+++ b/controlloop/templates/template.demo/src/test/resources/META-INF/persistence.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence version="2.1"
+ xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
+
+ <!-- In-mem DB for junit -->
+ <persistence-unit name="TestOperationsHistoryPU"
+ transaction-type="RESOURCE_LOCAL">
+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+ <class>org.onap.policy.controlloop.eventmanager.OperationsHistoryDbEntry</class>
+ <properties>
+ <property name="eclipselink.ddl-generation" value="create-tables" />
+ <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
+ <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test" />
+ <property name="javax.persistence.jdbc.user" value="sa" />
+ <property name="javax.persistence.jdbc.password" value="" />
+ <property name="eclipselink.logging.level" value="ALL" />
+ </properties>
+ </persistence-unit>
+
+
+</persistence>