summaryrefslogtreecommitdiffstats
path: root/main/src/test/java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-02-03 21:45:35 -0500
committerJim Hahn <jrh3@att.com>2020-02-03 22:11:29 -0500
commit96f3a97fe849c657c4afc7b0ba199a08cc0646c2 (patch)
tree3bd17de6e6b8e410facb2030251ead28cc29eb10 /main/src/test/java
parented9690a42e5fd7007a91275a6ad208d1a7dafcaa (diff)
Policy notifications appear to be reversed
Modified the code as follows: Until all PDPs have responded (or been removed), no notifications for their associated policies will be generated. However, once a response has been received for every PDP, then a notification is generated. For deployed policies, the notifications will continue to be generated as PDPs move back and forth between the success and failed states, as long as the policy is not undeployed. For undeployed policies, on the other hand, no additional notifications will be generated once all PDPs have successfully undeployed the policy. However, until that point, like with deployed policies, notifications will continue to be generated as PDPs move back and forth between the success and failed states. Added notification verifications in deploy and undeploy end-to-end tests. Issue-ID: POLICY-2347 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: I7d18dad1a7500e1efb7074e89ddaca4b1d368965
Diffstat (limited to 'main/src/test/java')
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/notification/PolicyDeployTrackerTest.java138
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/notification/PolicyTrackerDataTest.java112
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/notification/PolicyUndeployTrackerTest.java159
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java34
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java63
5 files changed, 466 insertions, 40 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/notification/PolicyDeployTrackerTest.java b/main/src/test/java/org/onap/policy/pap/main/notification/PolicyDeployTrackerTest.java
index 832fddc9..742d87d5 100644
--- a/main/src/test/java/org/onap/policy/pap/main/notification/PolicyDeployTrackerTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/notification/PolicyDeployTrackerTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP PAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -58,15 +58,122 @@ public class PolicyDeployTrackerTest extends PolicyCommonSupport {
tracker = new PolicyDeployTracker();
}
+ /**
+ * Simple test with one PDP that immediately responds with success.
+ */
@Test
- public void test() {
+ public void testSimpleImmediateSuccess() {
+ tracker.addData(makeData(policy1, PDP1));
+
+ // indicate that PDP1 has succeeded
+ List<PolicyStatus> statusList = new ArrayList<>();
+ tracker.processResponse(PDP1, Arrays.asList(policy1), statusList);
+
+ assertEquals(1, statusList.size());
+ assertEquals(policy1, statusList.get(0).getPolicy());
+ assertEquals(type, statusList.get(0).getPolicyType());
+ assertEquals("[1, 0, 0]", getCounts(statusList.get(0)).toString());
+
+ // indicate that PDP1 has succeeded again - should be no output
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(policy1), statusList);
+ assertEquals(0, statusList.size());
+
+ // indicate failure
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(), statusList);
+ assertEquals(1, statusList.size());
+ assertEquals("[0, 1, 0]", getCounts(statusList.get(0)).toString());
+
+ // indicate that PDP1 has failed again - should be no output
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(), statusList);
+ assertEquals(0, statusList.size());
+
+ // indicate that PDP1 has succeeded again
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(policy1), statusList);
+ assertEquals("[1, 0, 0]", getCounts(statusList.get(0)).toString());
+ }
+
+ /**
+ * Simple test with one PDP that immediately responds with success.
+ */
+ @Test
+ public void testSimpleImmediateFail() {
+ tracker.addData(makeData(policy1, PDP1));
+
+ // indicate that PDP1 has failed
+ List<PolicyStatus> statusList = new ArrayList<>();
+ tracker.processResponse(PDP1, Arrays.asList(), statusList);
+ assertEquals(1, statusList.size());
+ assertEquals("[0, 1, 0]", getCounts(statusList.get(0)).toString());
+
+ // indicate that PDP1 has failed again - should be no output
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(), statusList);
+ assertEquals(0, statusList.size());
+
+ // indicate success
+ tracker.processResponse(PDP1, Arrays.asList(policy1), statusList);
+
+ assertEquals(1, statusList.size());
+ assertEquals(policy1, statusList.get(0).getPolicy());
+ assertEquals(type, statusList.get(0).getPolicyType());
+ assertEquals("[1, 0, 0]", getCounts(statusList.get(0)).toString());
+
+ // indicate that PDP1 has succeeded again - should be no output
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(policy1), statusList);
+ assertEquals(0, statusList.size());
+ }
+
+ /**
+ * Simple test where PDP is removed and then it responds.
+ */
+ @Test
+ public void testSimpleRemove() {
+ tracker.addData(makeData(policy1, PDP1));
+
+ // remove the PDP
+ List<PolicyStatus> statusList = new ArrayList<>();
+ tracker.removePdp(PDP1, statusList);
+ assertEquals(1, statusList.size());
+ assertEquals(policy1, statusList.get(0).getPolicy());
+ assertEquals(type, statusList.get(0).getPolicyType());
+ assertEquals("[0, 0, 0]", getCounts(statusList.get(0)).toString());
+
+ /*
+ * indicate that PDP1 has succeeded - should be no message since PDP was removed
+ * from the policy
+ */
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(policy1), statusList);
+ assertEquals(0, statusList.size());
+
+ /*
+ * indicate that PDP1 has failed - should be no message since PDP was removed
+ * from the policy
+ */
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(), statusList);
+ assertEquals(0, statusList.size());
+ }
+
+ /**
+ * Test with multiple PDPs.
+ */
+ @Test
+ public void testMulti() {
tracker.addData(makeData(policy1, PDP1, PDP2));
// indicate that PDP2 has succeeded
- tracker.processResponse(PDP2, Arrays.asList(policy1), new ArrayList<>(0));
+ List<PolicyStatus> statusList = new ArrayList<>();
+ tracker.processResponse(PDP2, Arrays.asList(policy1), statusList);
+ assertEquals(0, statusList.size());
// indicate that PDP1 has succeeded
- List<PolicyStatus> statusList = new ArrayList<>();
+ statusList.clear();
tracker.processResponse(PDP1, Arrays.asList(policy1), statusList);
assertEquals(1, statusList.size());
@@ -74,13 +181,34 @@ public class PolicyDeployTrackerTest extends PolicyCommonSupport {
assertEquals(type, statusList.get(0).getPolicyType());
assertEquals("[2, 0, 0]", getCounts(statusList.get(0)).toString());
- // indicate that PDP1 has failed - should get a notification, if still in the map
+ // indicate that PDP1 has failed - should get a notification
statusList.clear();
tracker.processResponse(PDP1, Collections.emptyList(), statusList);
assertEquals(1, statusList.size());
assertEquals(policy1, statusList.get(0).getPolicy());
assertEquals(type, statusList.get(0).getPolicyType());
assertEquals("[1, 1, 0]", getCounts(statusList.get(0)).toString());
+
+ // indicate that PDP1 has succeeded
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(policy1), statusList);
+ assertEquals(1, statusList.size());
+ assertEquals("[2, 0, 0]", getCounts(statusList.get(0)).toString());
+
+ // remove PDP2 - expect message
+ statusList.clear();
+ tracker.removePdp(PDP2, statusList);
+ assertEquals(1, statusList.size());
+ assertEquals("[1, 0, 0]", getCounts(statusList.get(0)).toString());
+
+ // re-add PDP2
+ tracker.addData(makeData(policy1, PDP2));
+
+ // indicate that PDP2 has succeeded; PDP1 should still be ok
+ statusList.clear();
+ tracker.processResponse(PDP2, Arrays.asList(policy1), statusList);
+ assertEquals(1, statusList.size());
+ assertEquals("[2, 0, 0]", getCounts(statusList.get(0)).toString());
}
@Test
diff --git a/main/src/test/java/org/onap/policy/pap/main/notification/PolicyTrackerDataTest.java b/main/src/test/java/org/onap/policy/pap/main/notification/PolicyTrackerDataTest.java
index a727e057..ff797809 100644
--- a/main/src/test/java/org/onap/policy/pap/main/notification/PolicyTrackerDataTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/notification/PolicyTrackerDataTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP PAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -72,6 +72,29 @@ public class PolicyTrackerDataTest {
}
@Test
+ public void testAllSucceeded() {
+ assertTrue(data.allSucceeded());
+
+ data.addPdps(Arrays.asList(PDP1, PDP2));
+ assertFalse(data.allSucceeded());
+
+ data.success(PDP1);
+ assertFalse(data.allSucceeded());
+
+ data.fail(PDP2);
+ assertFalse(data.allSucceeded());
+
+ data.success(PDP2);
+ assertTrue(data.allSucceeded());
+
+ data.fail(PDP2);
+ assertFalse(data.allSucceeded());
+
+ data.success(PDP2);
+ assertTrue(data.allSucceeded());
+ }
+
+ @Test
public void testIsEmpty() {
assertTrue(data.isEmpty());
@@ -143,6 +166,9 @@ public class PolicyTrackerDataTest {
data.fail(PDP4);
assertFalse(data.removePdps(Arrays.asList(PDP1, PDP3, PDP5)));
assertEquals("[1, 1, 1]", getCounts().toString());
+
+ assertTrue(data.removePdps(Arrays.asList(PDP6)));
+ assertEquals("[1, 1, 0]", getCounts().toString());
}
/**
@@ -167,6 +193,48 @@ public class PolicyTrackerDataTest {
assertTrue(data.removePdps(Arrays.asList(PDP2, PDP3)));
}
+ /**
+ * Tests removePdps() with more variations.
+ */
+ @Test
+ public void testRemovePdpsVariations() {
+ data.addPdps(Arrays.asList(PDP1, PDP2, PDP3));
+ data.success(PDP1);
+ data.fail(PDP2);
+ assertEquals("[1, 1, 1]", getCounts().toString());
+
+ // remove PDP1, which checks removal from "success" set, while incomplete
+ assertFalse(data.removePdps(Arrays.asList(PDP1)));
+ assertEquals("[0, 1, 1]", getCounts().toString());
+
+ // remove PDP2, which checks removal from "failure" set, while incomplete
+ assertFalse(data.removePdps(Arrays.asList(PDP2)));
+ assertEquals("[0, 0, 1]", getCounts().toString());
+
+ // re-add 1 & 2
+ data.addPdps(Arrays.asList(PDP1, PDP2));
+ data.success(PDP1);
+ data.fail(PDP2);
+ assertEquals("[1, 1, 1]", getCounts().toString());
+
+ // remove PDP3, which checks removal from "incomplete" set
+ assertTrue(data.removePdps(Arrays.asList(PDP3)));
+ assertEquals("[1, 1, 0]", getCounts().toString());
+
+ // remove PDP1, which checks removal from "success" set, while complete
+ assertTrue(data.removePdps(Arrays.asList(PDP1)));
+ assertEquals("[0, 1, 0]", getCounts().toString());
+
+ // remove PDP2, which checks removal from "failure" set, while complete
+ assertTrue(data.removePdps(Arrays.asList(PDP2)));
+ assertEquals("[0, 0, 0]", getCounts().toString());
+
+ // re-add 1 and then remove it again
+ data.addPdps(Arrays.asList(PDP1));
+ assertTrue(data.removePdps(Arrays.asList(PDP1)));
+ assertEquals("[0, 0, 0]", getCounts().toString());
+ }
+
@Test
public void testRemovePdp() {
data.addPdps(Arrays.asList(PDP1, PDP2, PDP3, PDP4, PDP5, PDP6));
@@ -214,6 +282,48 @@ public class PolicyTrackerDataTest {
assertTrue(data.removePdp(PDP2));
}
+ /**
+ * Tests removePdp() with more variations.
+ */
+ @Test
+ public void testRemovePdpVariations() {
+ data.addPdps(Arrays.asList(PDP1, PDP2, PDP3));
+ data.success(PDP1);
+ data.fail(PDP2);
+ assertEquals("[1, 1, 1]", getCounts().toString());
+
+ // remove PDP1, which checks removal from "success" set, while incomplete
+ assertFalse(data.removePdp(PDP1));
+ assertEquals("[0, 1, 1]", getCounts().toString());
+
+ // remove PDP2, which checks removal from "failure" set, while incomplete
+ assertFalse(data.removePdp(PDP2));
+ assertEquals("[0, 0, 1]", getCounts().toString());
+
+ // re-add 1 & 2
+ data.addPdps(Arrays.asList(PDP1, PDP2));
+ data.success(PDP1);
+ data.fail(PDP2);
+ assertEquals("[1, 1, 1]", getCounts().toString());
+
+ // remove PDP3, which checks removal from "incomplete" set
+ assertTrue(data.removePdp(PDP3));
+ assertEquals("[1, 1, 0]", getCounts().toString());
+
+ // remove PDP1, which checks removal from "success" set, while complete
+ assertTrue(data.removePdp(PDP1));
+ assertEquals("[0, 1, 0]", getCounts().toString());
+
+ // remove PDP2, which checks removal from "failure" set, while complete
+ assertTrue(data.removePdp(PDP2));
+ assertEquals("[0, 0, 0]", getCounts().toString());
+
+ // re-add 1 and then remove it again
+ data.addPdps(Arrays.asList(PDP1));
+ assertTrue(data.removePdp(PDP1));
+ assertEquals("[0, 0, 0]", getCounts().toString());
+ }
+
@Test
public void testComplete() {
// attempt to remove a PDP that isn't in the data
diff --git a/main/src/test/java/org/onap/policy/pap/main/notification/PolicyUndeployTrackerTest.java b/main/src/test/java/org/onap/policy/pap/main/notification/PolicyUndeployTrackerTest.java
index ba85c489..7d3f54fb 100644
--- a/main/src/test/java/org/onap/policy/pap/main/notification/PolicyUndeployTrackerTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/notification/PolicyUndeployTrackerTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP PAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -58,8 +58,117 @@ public class PolicyUndeployTrackerTest extends PolicyCommonSupport {
tracker = new PolicyUndeployTracker();
}
+ /**
+ * Simple test with one PDP that immediately responds with success.
+ */
+ @Test
+ public void testSimpleImmediateSuccess() {
+ tracker.addData(makeData(policy1, PDP1));
+
+ // indicate that PDP1 has succeeded (i.e., undeployed)
+ List<PolicyStatus> statusList = new ArrayList<>();
+ tracker.processResponse(PDP1, Arrays.asList(), statusList);
+
+ assertEquals(1, statusList.size());
+ assertEquals(policy1, statusList.get(0).getPolicy());
+ assertEquals(type, statusList.get(0).getPolicyType());
+ assertEquals("[1, 0, 0]", getCounts(statusList.get(0)).toString());
+
+ // indicate that PDP1 has succeeded again - should be no output
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(), statusList);
+ assertEquals(0, statusList.size());
+
+ // indicate failure (i.e., still deployed) - no output, because no longer tracked
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(policy1), statusList);
+ assertEquals(0, statusList.size());
+
+ // indicate that PDP1 has failed again - still no output
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(policy1), statusList);
+ assertEquals(0, statusList.size());
+
+ // indicate that PDP1 has succeeded again - still no output
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(), statusList);
+ assertEquals(0, statusList.size());
+ }
+
+ /**
+ * Simple test with one PDP that immediately responds with success.
+ */
@Test
- public void test() {
+ public void testSimpleImmediateFail() {
+ tracker.addData(makeData(policy1, PDP1));
+
+ // indicate that PDP1 has failed (i.e., still deployed)
+ List<PolicyStatus> statusList = new ArrayList<>();
+ tracker.processResponse(PDP1, Arrays.asList(policy1), statusList);
+ assertEquals(1, statusList.size());
+ assertEquals("[0, 1, 0]", getCounts(statusList.get(0)).toString());
+
+ // indicate that PDP1 has failed again - should be no output
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(policy1), statusList);
+ assertEquals(0, statusList.size());
+
+ // indicate success (i.e., undeployed)
+ tracker.processResponse(PDP1, Arrays.asList(), statusList);
+
+ assertEquals(1, statusList.size());
+ assertEquals(policy1, statusList.get(0).getPolicy());
+ assertEquals(type, statusList.get(0).getPolicyType());
+ assertEquals("[1, 0, 0]", getCounts(statusList.get(0)).toString());
+
+ // indicate that PDP1 has succeeded again - should be no output
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(), statusList);
+ assertEquals(0, statusList.size());
+
+ // indicate that PDP1 has failed again - still no output
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(policy1), statusList);
+ assertEquals(0, statusList.size());
+ }
+
+ /**
+ * Simple test where PDP is removed and then it responds.
+ */
+ @Test
+ public void testSimpleRemove() {
+ tracker.addData(makeData(policy1, PDP1));
+
+ // remove the PDP
+ List<PolicyStatus> statusList = new ArrayList<>();
+ tracker.removePdp(PDP1, statusList);
+ assertEquals(1, statusList.size());
+ assertEquals(policy1, statusList.get(0).getPolicy());
+ assertEquals(type, statusList.get(0).getPolicyType());
+ assertEquals("[0, 0, 0]", getCounts(statusList.get(0)).toString());
+
+ /*
+ * indicate that PDP1 has succeeded (i.e., undeployed) - should be no message
+ * since PDP was removed from the policy
+ */
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(), statusList);
+ assertEquals(0, statusList.size());
+
+ /*
+ * indicate that PDP1 has failed (i.e., still deployed) - should be no message
+ * since PDP was removed from the policy
+ */
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(policy1), statusList);
+ assertEquals(0, statusList.size());
+ }
+
+ /**
+ * Test with multiple PDPs.
+ */
+ @Test
+ public void testMulti() {
tracker.addData(makeData(policy1, PDP1, PDP2));
// indicate that PDP2 has been undeployed
@@ -74,14 +183,50 @@ public class PolicyUndeployTrackerTest extends PolicyCommonSupport {
assertEquals(type, statusList.get(0).getPolicyType());
assertEquals("[2, 0, 0]", getCounts(statusList.get(0)).toString());
- // indicate that PDP1 has been re-deployed - should not get a notification,
- // because policy
- // is gone
+ /*
+ * indicate that PDP1 has been re-deployed - should not get a notification,
+ * because policy is gone
+ */
statusList.clear();
tracker.processResponse(PDP1, Arrays.asList(policy1), statusList);
assertTrue(statusList.isEmpty());
}
+ /**
+ * Test with multiple PDPs, and one is removed while it is in a failure state.
+ */
+ @Test
+ public void testMultiRemove() {
+ tracker.addData(makeData(policy1, PDP1, PDP2));
+
+ // indicate that PDP2 has been undeployed
+ tracker.processResponse(PDP2, Collections.emptyList(), new ArrayList<>(0));
+
+ // indicate that PDP1 has failed (i.e., still deployed)
+ List<PolicyStatus> statusList = new ArrayList<>();
+ tracker.processResponse(PDP1, Arrays.asList(policy1), statusList);
+
+ assertEquals(1, statusList.size());
+ assertEquals(policy1, statusList.get(0).getPolicy());
+ assertEquals(type, statusList.get(0).getPolicyType());
+ assertEquals("[1, 1, 0]", getCounts(statusList.get(0)).toString());
+
+ // remove PDP1 - expect message AND policy should be removed
+ statusList.clear();
+ tracker.removePdp(PDP1, statusList);
+ assertEquals(1, statusList.size());
+ assertEquals("[1, 0, 0]", getCounts(statusList.get(0)).toString());
+
+ // re-add PDP1
+ tracker.addData(makeData(policy1, PDP1));
+
+ // indicate that PDP1 has succeeded; policy is now new, so doesn't include PDP2
+ statusList.clear();
+ tracker.processResponse(PDP1, Arrays.asList(), statusList);
+ assertEquals(1, statusList.size());
+ assertEquals("[1, 0, 0]", getCounts(statusList.get(0)).toString());
+ }
+
@Test
public void testUpdateData() {
// when success returns false
@@ -112,8 +257,8 @@ public class PolicyUndeployTrackerTest extends PolicyCommonSupport {
// when data is not complete
assertFalse(tracker.shouldRemove(data));
- // when data is complete
- when(data.isComplete()).thenReturn(true);
+ // when data has succeeded
+ when(data.allSucceeded()).thenReturn(true);
assertTrue(tracker.shouldRemove(data));
}
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java
index 68e70287..d9fc66ad 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP PAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -21,16 +21,27 @@
package org.onap.policy.pap.main.rest.e2e;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.util.Collections;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.core.Response;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicFactories;
+import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicSink;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse;
+import org.onap.policy.models.pap.concepts.PolicyNotification;
+import org.onap.policy.models.pap.concepts.PolicyStatus;
import org.onap.policy.models.pdp.concepts.PdpStatus;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
+import org.onap.policy.pap.main.PapConstants;
public class PdpGroupDeleteTest extends End2EndBase {
private static final String DELETE_GROUP_ENDPOINT = "pdps/groups";
@@ -112,6 +123,13 @@ public class PdpGroupDeleteTest extends End2EndBase {
context.startThreads();
+ // arrange to catch notifications
+ LinkedBlockingQueue<String> notifications = new LinkedBlockingQueue<>();
+ NoopTopicSink notifier = NoopTopicFactories.getSinkFactory().get(PapConstants.TOPIC_POLICY_NOTIFICATION);
+ notifier.register((infra, topic, msg) -> {
+ notifications.add(msg);
+ });
+
String uri = DELETE_POLICIES_ENDPOINT + "/onap.restart.tcaB";
Invocation.Builder invocationBuilder = sendRequest(uri);
@@ -122,6 +140,20 @@ public class PdpGroupDeleteTest extends End2EndBase {
context.await();
+ // wait for the notification
+ String json = notifications.poll(5, TimeUnit.SECONDS);
+ PolicyNotification notify = new StandardCoder().decode(json, PolicyNotification.class);
+ assertNotNull(notify.getAdded());
+ assertNotNull(notify.getDeleted());
+ assertTrue(notify.getAdded().isEmpty());
+ assertEquals(1, notify.getDeleted().size());
+
+ PolicyStatus deleted = notify.getDeleted().get(0);
+ assertEquals(2, deleted.getSuccessCount());
+ assertEquals(0, deleted.getFailureCount());
+ assertEquals(0, deleted.getIncompleteCount());
+ assertEquals(new ToscaPolicyIdentifier("onap.restart.tcaB", "1.0.0"), deleted.getPolicy());
+
rawresp = invocationBuilder.delete();
resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawresp.getStatus());
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java
index 1f049709..549ae206 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP PAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -21,35 +21,38 @@
package org.onap.policy.pap.main.rest.e2e;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicFactories;
+import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicSink;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.pap.concepts.PdpDeployPolicies;
import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
+import org.onap.policy.models.pap.concepts.PolicyNotification;
+import org.onap.policy.models.pap.concepts.PolicyStatus;
import org.onap.policy.models.pdp.concepts.DeploymentGroup;
import org.onap.policy.models.pdp.concepts.DeploymentGroups;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.onap.policy.pap.main.PapConstants;
public class PdpGroupDeployTest extends End2EndBase {
- private static final Logger logger = LoggerFactory.getLogger(PdpGroupDeployTest.class);
-
private static final String DEPLOY_GROUP_ENDPOINT = "pdps/deployments/batch";
private static final String DEPLOY_POLICIES_ENDPOINT = "pdps/policies";
- private static final String DELETE_GROUP_ENDPOINT = "pdps/groups";
private static final String DEPLOY_SUBGROUP = "pdpTypeA";
/**
@@ -75,21 +78,6 @@ public class PdpGroupDeployTest extends End2EndBase {
context = new End2EndContext();
}
- /**
- * Deletes the deployed group.
- */
- @After
- public void tearDown() {
- // delete the group that was inserted
- try {
- sendRequest(DELETE_GROUP_ENDPOINT + "/deployGroups").delete();
- } catch (Exception e) {
- logger.warn("cannot delete group: deployGroups", e);
- }
-
- super.tearDown();
- }
-
@Test
public void testUpdateGroupPolicies() throws Exception {
@@ -98,7 +86,7 @@ public class PdpGroupDeployTest extends End2EndBase {
PdpStatus status11 = new PdpStatus();
status11.setName("pdpAA_1");
status11.setState(PdpState.ACTIVE);
- status11.setPdpGroup("deployPolicies");
+ status11.setPdpGroup("deployGroups");
status11.setPdpType(DEPLOY_SUBGROUP);
status11.setPdpSubgroup(DEPLOY_SUBGROUP);
@@ -108,7 +96,7 @@ public class PdpGroupDeployTest extends End2EndBase {
PdpStatus status12 = new PdpStatus();
status12.setName("pdpAA_2");
status12.setState(PdpState.ACTIVE);
- status12.setPdpGroup("deployPolicies");
+ status12.setPdpGroup("deployGroups");
status12.setPdpType(DEPLOY_SUBGROUP);
status12.setPdpSubgroup(DEPLOY_SUBGROUP);
status12.setPolicies(idents);
@@ -159,7 +147,9 @@ public class PdpGroupDeployTest extends End2EndBase {
status11.setPdpType(DEPLOY_SUBGROUP);
status11.setPdpSubgroup(DEPLOY_SUBGROUP);
- List<ToscaPolicyIdentifier> idents = Arrays.asList(new ToscaPolicyIdentifier("onap.restart.tca", "1.0.0"));
+ final ToscaPolicyIdentifier ident = new ToscaPolicyIdentifier("onap.restart.tcaB", "1.0.0");
+
+ List<ToscaPolicyIdentifier> idents = Arrays.asList(ident);
status11.setPolicies(idents);
PdpStatus status12 = new PdpStatus();
@@ -176,9 +166,16 @@ public class PdpGroupDeployTest extends End2EndBase {
context.startThreads();
+ // arrange to catch notifications
+ LinkedBlockingQueue<String> notifications = new LinkedBlockingQueue<>();
+ NoopTopicSink notifier = NoopTopicFactories.getSinkFactory().get(PapConstants.TOPIC_POLICY_NOTIFICATION);
+ notifier.register((infra, topic, msg) -> {
+ notifications.add(msg);
+ });
+
Invocation.Builder invocationBuilder = sendRequest(DEPLOY_POLICIES_ENDPOINT);
- PdpDeployPolicies policies = loadJsonFile("deployPoliciesReq.json", PdpDeployPolicies.class);
+ PdpDeployPolicies policies = loadJsonFile("deployPoliciesReq2.json", PdpDeployPolicies.class);
Entity<PdpDeployPolicies> entity = Entity.entity(policies, MediaType.APPLICATION_JSON);
Response rawresp = invocationBuilder.post(entity);
PdpGroupDeployResponse resp = rawresp.readEntity(PdpGroupDeployResponse.class);
@@ -188,6 +185,20 @@ public class PdpGroupDeployTest extends End2EndBase {
context.await();
+ // wait for the notification
+ String json = notifications.poll(5, TimeUnit.SECONDS);
+ PolicyNotification notify = new StandardCoder().decode(json, PolicyNotification.class);
+ assertNotNull(notify.getAdded());
+ assertNotNull(notify.getDeleted());
+ assertTrue(notify.getDeleted().isEmpty());
+ assertEquals(1, notify.getAdded().size());
+
+ PolicyStatus added = notify.getAdded().get(0);
+ assertEquals(2, added.getSuccessCount());
+ assertEquals(0, added.getFailureCount());
+ assertEquals(0, added.getIncompleteCount());
+ assertEquals(ident, added.getPolicy());
+
// one of the PDPs should not have handled any requests
assertEquals(1, context.getPdps().stream().filter(pdp -> pdp.getHandled().isEmpty()).count());