summaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2018-09-12 18:01:03 -0400
committerJim Hahn <jrh3@att.com>2018-09-12 18:01:03 -0400
commit97956f188f4a8d92d734bf491d5e15a78a03459f (patch)
treec3524bbb27e5880b9deaa94e3840991dea7b15cf /controlloop/common/eventmanager/src/test
parentdbecba3a4baffacf9f2da82592b3e3a9e2929f21 (diff)
implement Serializable in additional classes
Change-Id: I5d5acb9d71dc49eaa9fb397da5988ba3d8bd5f1d Issue-ID: POLICY-1106 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop/common/eventmanager/src/test')
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java12
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java63
2 files changed, 71 insertions, 4 deletions
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
index 562a46e4e..1673df3be 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
@@ -54,6 +54,7 @@ import org.onap.policy.aai.RelationshipData;
import org.onap.policy.aai.RelationshipList;
import org.onap.policy.aai.util.AaiException;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.utils.io.Serializer;
import org.onap.policy.controlloop.ControlLoopEventStatus;
import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.ControlLoopNotificationType;
@@ -212,7 +213,7 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void subsequentOnsetTest() {
+ public void subsequentOnsetTest() throws IOException {
UUID requestId = UUID.randomUUID();
VirtualControlLoopEvent event = new VirtualControlLoopEvent();
event.setClosedLoopControlName("TwoOnsetTest");
@@ -555,6 +556,9 @@ public class ControlLoopEventManagerTest {
VirtualControlLoopNotification clfNotification = manager.isControlLoopFinal();
assertNull(clfNotification);
+
+ // serialize and de-serialize manager
+ manager = Serializer.roundTrip(manager);
manager.getProcessor().nextPolicyForResult(PolicyResult.SUCCESS);
clfNotification = manager.isControlLoopFinal();
@@ -626,6 +630,9 @@ public class ControlLoopEventManagerTest {
ControlLoopOperationManager clom = manager.processControlLoop();
assertNotNull(clom);
assertNull(clom.getOperationResult());
+
+ // serialize and de-serialize manager
+ manager = Serializer.roundTrip(manager);
// Test operation in progress
try {
@@ -715,6 +722,9 @@ public class ControlLoopEventManagerTest {
}
assertNull(manager.unlockCurrentOperation());
+
+ // serialize and de-serialize manager
+ manager = Serializer.roundTrip(manager);
ControlLoopOperationManager clom = manager.processControlLoop();
assertNotNull(clom);
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java
index d1763f52c..dae03aa6e 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManagerTest.java
@@ -35,15 +35,12 @@ import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.HashMap;
import java.util.UUID;
-
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException;
import javax.persistence.Persistence;
import javax.persistence.Query;
-
-
import org.apache.commons.io.IOUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -59,6 +56,7 @@ import org.onap.policy.appclcm.LcmRequestWrapper;
import org.onap.policy.appclcm.LcmResponse;
import org.onap.policy.appclcm.LcmResponseWrapper;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.utils.io.Serializer;
import org.onap.policy.controlloop.ControlLoopEventStatus;
import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.ControlLoopNotificationType;
@@ -850,4 +848,63 @@ public class ControlLoopOperationManagerTest {
assertEquals(1, numEventsAfter - numEventsBefore);
}
+
+ @Test
+ public void testSerialization() throws Exception {
+ InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"));
+ final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
+
+ UUID requestId = UUID.randomUUID();
+ VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
+ onsetEvent.setClosedLoopControlName("TwoOnsetTest");
+ onsetEvent.setRequestId(requestId);
+ onsetEvent.setTarget("generic-vnf.vnf-id");
+ onsetEvent.setClosedLoopAlarmStart(Instant.now());
+ onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
+ onsetEvent.setAai(new HashMap<>());
+ onsetEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
+
+ ControlLoopEventManager manager =
+ new ControlLoopEventManager(onsetEvent.getClosedLoopControlName(), onsetEvent.getRequestId());
+ VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent);
+ assertNotNull(notification);
+ assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
+
+ Policy policy = manager.getProcessor().getCurrentPolicy();
+ ControlLoopOperationManager clom = new ControlLoopOperationManager(onsetEvent, policy, manager);
+ assertNotNull(clom);
+
+ clom.startOperation(onsetEvent);
+ assertTrue(clom.isOperationRunning());
+
+ clom = Serializer.roundTrip(clom);
+ assertNotNull(clom);
+ assertTrue(clom.isOperationRunning());
+
+ SOResponse soResponse = new SOResponse();
+ final SOResponseWrapper soRw = new SOResponseWrapper(soResponse, null);
+
+ PolicyEngine.manager.setEnvironmentProperty("guard.disabled", "false");
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_URL,
+ "http://somewhere.over.the.rainbow");
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_USER, "Dorothy");
+ PolicyEngine.manager.setEnvironmentProperty(org.onap.policy.guard.Util.ONAP_KEY_PASS, "Toto");
+
+ assertEquals(PolicyResult.FAILURE, clom.onResponse(soRw));
+ assertFalse(clom.isOperationRunning());
+ assertEquals(1, clom.getHistory().size());
+
+ clom = Serializer.roundTrip(clom);
+ assertNotNull(clom);
+ assertFalse(clom.isOperationRunning());
+ assertEquals(1, clom.getHistory().size());
+
+ System.setProperty("OperationsHistoryPU", "TestOperationsHistoryPU");
+ assertEquals(PolicyResult.FAILURE, clom.onResponse(soRw));
+
+ clom = Serializer.roundTrip(clom);
+ assertNotNull(clom);
+ assertFalse(clom.isOperationRunning());
+ assertEquals(1, clom.getHistory().size());
+ }
}