aboutsummaryrefslogtreecommitdiffstats
path: root/services/services-onappf/src/test
diff options
context:
space:
mode:
authorRam Krishna Verma <ram_krishna.verma@bell.ca>2021-04-28 16:51:38 +0000
committerGerrit Code Review <gerrit@onap.org>2021-04-28 16:51:38 +0000
commit2f5f1dbd3c38dd3915760158a003b04ca69b478b (patch)
tree084a3170c8af676099306605b9b315d20765f27c /services/services-onappf/src/test
parentcb09008c4d252dbc9a62f3a1d0b463a74380aa77 (diff)
parentc28ef7b282ab4378935387314f1a57d18e02fcf4 (diff)
Merge "Support delta policies in apex-pdp"
Diffstat (limited to 'services/services-onappf/src/test')
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestListenerUtils.java12
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java18
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java34
3 files changed, 42 insertions, 22 deletions
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestListenerUtils.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestListenerUtils.java
index 19af43fc8..104977995 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestListenerUtils.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestListenerUtils.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
import org.onap.policy.models.pdp.enums.PdpState;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
public class TestListenerUtils {
@@ -39,18 +40,21 @@ public class TestListenerUtils {
* Method to create PdpUpdate message from the arguments passed.
*
* @param pdpStatus pdp status
- * @param toscaPolicies list of tosca policies
+ * @param toscaPoliciesToBeDeployed list of tosca policies to deploy
+ * @param toscaPoliciesToBeUnDeployed list of tosca policies to undeploy
*
* @return PdpUpdate message
*/
- public static PdpUpdate createPdpUpdateMsg(final PdpStatus pdpStatus, List<ToscaPolicy> toscaPolicies) {
+ public static PdpUpdate createPdpUpdateMsg(final PdpStatus pdpStatus, List<ToscaPolicy> toscaPoliciesToBeDeployed,
+ List<ToscaConceptIdentifier> toscaPoliciesToBeUnDeployed) {
final PdpUpdate pdpUpdateMsg = new PdpUpdate();
pdpUpdateMsg.setDescription("dummy pdp status for test");
pdpUpdateMsg.setPdpGroup("pdpGroup");
pdpUpdateMsg.setPdpSubgroup("pdpSubgroup");
pdpUpdateMsg.setName(pdpStatus.getName());
pdpUpdateMsg.setPdpHeartbeatIntervalMs(Long.valueOf(3000));
- pdpUpdateMsg.setPolicies(toscaPolicies);
+ pdpUpdateMsg.setPoliciesToBeDeployed(toscaPoliciesToBeDeployed);
+ pdpUpdateMsg.setPoliciesToBeUndeployed(toscaPoliciesToBeUnDeployed);
return pdpUpdateMsg;
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java
index b4308b8b9..10f82633f 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java
@@ -22,6 +22,7 @@
package org.onap.policy.apex.services.onappf.comm;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -125,7 +126,8 @@ public class TestPdpStateChangeListener {
public void testPdpStateChangeMessageListener_passivetopassive() {
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null,
- TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<ToscaPolicy>()));
+ TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(),
+ new ArrayList<>()));
PdpStateChange pdpStateChangeMsg =
TestListenerUtils.createPdpStateChangeMsg(PdpState.PASSIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName());
pdpStateChangeListener.onTopicEvent(INFRA, TOPIC, null, pdpStateChangeMsg);
@@ -137,7 +139,8 @@ public class TestPdpStateChangeListener {
public void testPdpStateChangeMessageListener_activetoactive() {
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null,
- TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<ToscaPolicy>()));
+ TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(),
+ new ArrayList<>()));
pdpStatus.setState(PdpState.ACTIVE);
PdpStateChange pdpStateChangeMsg =
TestListenerUtils.createPdpStateChangeMsg(PdpState.ACTIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName());
@@ -152,7 +155,8 @@ public class TestPdpStateChangeListener {
System.setOut(new PrintStream(outContent));
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null,
- TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<ToscaPolicy>()));
+ TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(),
+ new ArrayList<>()));
PdpStateChange pdpStateChangeMsg =
TestListenerUtils.createPdpStateChangeMsg(PdpState.ACTIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName());
pdpStateChangeListener.onTopicEvent(INFRA, TOPIC, null, pdpStateChangeMsg);
@@ -162,9 +166,10 @@ public class TestPdpStateChangeListener {
TestListenerUtils.createToscaPolicy("apex_policy_name", "1.0", "src/test/resources/dummyProperties.json");
final List<ToscaPolicy> toscaPolicies = new ArrayList<ToscaPolicy>();
toscaPolicies.add(toscaPolicy);
- final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies);
+ final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies,
+ new ArrayList<>());
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
- assertTrue(outContent.toString().contains("Apex engine started and policies are running."));
+ assertThat(outContent.toString()).contains("Apex engine started and policies are running.");
assertEquals(PdpState.ACTIVE, pdpStatus.getState());
final ApexPolicyStatisticsManager policyCounterManager = ApexPolicyStatisticsManager.getInstanceFromRegistry();
@@ -185,7 +190,8 @@ public class TestPdpStateChangeListener {
TestListenerUtils.createToscaPolicy("apex_policy_name", "1.0", "src/test/resources/dummyProperties.json");
final List<ToscaPolicy> toscaPolicies = new ArrayList<ToscaPolicy>();
toscaPolicies.add(toscaPolicy);
- final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies);
+ final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies,
+ new ArrayList<>());
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
PdpStateChange pdpStateChangeMsg =
TestListenerUtils.createPdpStateChangeMsg(PdpState.ACTIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName());
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java
index 28e230ebb..ec3da9bc3 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java
@@ -22,6 +22,7 @@
package org.onap.policy.apex.services.onappf.comm;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -31,7 +32,9 @@ import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
+import java.util.stream.Collectors;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -126,12 +129,13 @@ public class TestPdpUpdateListener {
TestListenerUtils.createToscaPolicy("apex policy name", "1.0", "src/test/resources/dummyProperties.json");
final List<ToscaPolicy> toscaPolicies = new ArrayList<ToscaPolicy>();
toscaPolicies.add(toscaPolicy);
- final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies);
+ final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies,
+ new LinkedList<>());
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
assertEquals(pdpStatus.getPdpGroup(), pdpUpdateMsg.getPdpGroup());
assertEquals(pdpStatus.getPdpSubgroup(), pdpUpdateMsg.getPdpSubgroup());
assertEquals(pdpStatus.getPolicies(),
- new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPolicies()));
+ new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPoliciesToBeDeployed()));
}
@Test
@@ -140,7 +144,8 @@ public class TestPdpUpdateListener {
System.setOut(new PrintStream(outContent));
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null,
- TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<ToscaPolicy>()));
+ TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(),
+ new ArrayList<>()));
PdpStateChange pdpStateChangeMsg =
TestListenerUtils.createPdpStateChangeMsg(PdpState.ACTIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName());
pdpStateChangeListener.onTopicEvent(INFRA, TOPIC, null, pdpStateChangeMsg);
@@ -148,21 +153,23 @@ public class TestPdpUpdateListener {
TestListenerUtils.createToscaPolicy("apex_policy_name", "1.0", "src/test/resources/dummyProperties.json");
final List<ToscaPolicy> toscaPolicies = new ArrayList<ToscaPolicy>();
toscaPolicies.add(toscaPolicy);
- final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies);
+ final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies,
+ new LinkedList<>());
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
final String outString = outContent.toString();
assertEquals(pdpStatus.getPdpGroup(), pdpUpdateMsg.getPdpGroup());
assertEquals(pdpStatus.getPdpSubgroup(), pdpUpdateMsg.getPdpSubgroup());
assertEquals(pdpStatus.getPolicies(),
- new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPolicies()));
- assertTrue(outString.contains("Apex engine started and policies are running."));
+ new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPoliciesToBeDeployed()));
+ assertThat(outString).contains("Apex engine started and policies are running.");
}
@Test
public void testPdpUpdateMssageListener_undeploy() throws InterruptedException, CoderException {
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null,
- TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<ToscaPolicy>()));
+ TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(),
+ new ArrayList<>()));
PdpStateChange pdpStateChangeMsg =
TestListenerUtils.createPdpStateChangeMsg(PdpState.ACTIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName());
pdpStateChangeListener.onTopicEvent(INFRA, TOPIC, null, pdpStateChangeMsg);
@@ -170,15 +177,17 @@ public class TestPdpUpdateListener {
TestListenerUtils.createToscaPolicy("apex_policy_name", "1.0", "src/test/resources/dummyProperties.json");
final List<ToscaPolicy> toscaPolicies = new ArrayList<ToscaPolicy>();
toscaPolicies.add(toscaPolicy);
- final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies);
+ final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies,
+ new ArrayList<>());
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
OutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null,
- TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<ToscaPolicy>()));
+ TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(),
+ toscaPolicies.stream().map(ToscaPolicy::getIdentifier)
+ .collect(Collectors.toList())));
final String outString = outContent.toString();
- assertTrue(outString.contains("Pdp update successful. No policies are running."));
-
+ assertThat(outString).contains("Pdp update successful. No policies are running.");
}
@Test
@@ -194,7 +203,8 @@ public class TestPdpUpdateListener {
final List<ToscaPolicy> toscaPolicies = new ArrayList<ToscaPolicy>();
toscaPolicies.add(toscaPolicy);
toscaPolicies.add(toscaPolicy2);
- final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies);
+ final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies,
+ new LinkedList<>());
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
PdpStateChange pdpStateChangeMsg =
TestListenerUtils.createPdpStateChangeMsg(PdpState.ACTIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName());