summaryrefslogtreecommitdiffstats
path: root/main/src/test/java/org
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-04-12 21:02:53 -0400
committerJim Hahn <jrh3@att.com>2019-04-12 22:58:07 -0400
commitfb057952d747a91139bce6e259b775bf57fc158f (patch)
tree1e27e7b5c70b2f81232dea8abff70c8306d3626c /main/src/test/java/org
parente5e24d606ecdaa1fca547969d56c890764f26e45 (diff)
Update PDP with null group/subgroup when disabled
Modified the code so that, when a PDP is unable to fulfill a request, an UPDATE is sent to the PDP with group=null and subgroup=null. Also made updates to eliminate group version due to changes in policy/models. Change-Id: I9400ef5f8c365f492113a5b592b9ee6b7218756e Issue-ID: POLICY-1542 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main/src/test/java/org')
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java50
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupStateChangeControllerV1.java4
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeployControllerV1.java1
3 files changed, 45 insertions, 10 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java b/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java
index a92ff95b..92f5c5f3 100644
--- a/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java
@@ -23,6 +23,7 @@ package org.onap.policy.pap.main.comm;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
@@ -60,7 +61,6 @@ import org.powermock.reflect.Whitebox;
public class PdpModifyRequestMapTest extends CommonRequestBase {
private static final String MY_REASON = "my reason";
- private static final String MY_VERSION = "1.2.3";
/**
* Used to capture input to dao.createPdpGroups().
@@ -290,7 +290,44 @@ public class PdpModifyRequestMapTest extends CommonRequestBase {
}
@Test
- public void testDisablePdp() {
+ public void testDisablePdp() throws Exception {
+ map.addRequest(update);
+
+ // put the PDP in a group
+ PdpGroup group = makeGroup(MY_GROUP);
+ group.setPdpSubgroups(Arrays.asList(makeSubGroup(MY_SUBGROUP, PDP1)));
+
+ when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group));
+
+ // indicate failure
+ invokeFailureHandler(1);
+
+ // should have stopped publishing
+ verify(requests).stopPublishing();
+
+ // should have published a new update
+ PdpMessage msg2 = getSingletons(3).get(1).getMessage();
+ assertNotNull(msg2);
+ assertTrue(msg2 instanceof PdpUpdate);
+
+ // update should have null group & subgroup
+ update = (PdpUpdate) msg2;
+ assertEquals(PDP1, update.getName());
+ assertNull(update.getPdpGroup());
+ assertNull(update.getPdpSubgroup());
+
+ // should have published a state-change
+ msg2 = getSingletons(3).get(2).getMessage();
+ assertNotNull(msg2);
+ assertTrue(msg2 instanceof PdpStateChange);
+
+ change = (PdpStateChange) msg2;
+ assertEquals(PDP1, change.getName());
+ assertEquals(PdpState.PASSIVE, change.getState());
+ }
+
+ @Test
+ public void testDisablePdp_NotInGroup() {
map.addRequest(update);
// indicate failure
@@ -334,7 +371,7 @@ public class PdpModifyRequestMapTest extends CommonRequestBase {
public void testRemoveFromGroup() throws Exception {
map.addRequest(change);
- PdpGroup group = makeGroup(MY_GROUP, MY_VERSION);
+ PdpGroup group = makeGroup(MY_GROUP);
group.setPdpSubgroups(Arrays.asList(makeSubGroup(MY_SUBGROUP + "a", PDP1 + "a"),
makeSubGroup(MY_SUBGROUP, PDP1), makeSubGroup(MY_SUBGROUP + "c", PDP1 + "c")));
@@ -383,7 +420,7 @@ public class PdpModifyRequestMapTest extends CommonRequestBase {
public void testRemoveFromGroup_NoMatchingSubgroup() throws Exception {
map.addRequest(change);
- PdpGroup group = makeGroup(MY_GROUP, MY_VERSION);
+ PdpGroup group = makeGroup(MY_GROUP);
group.setPdpSubgroups(Arrays.asList(makeSubGroup(MY_SUBGROUP, DIFFERENT)));
when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group));
@@ -397,7 +434,7 @@ public class PdpModifyRequestMapTest extends CommonRequestBase {
public void testRemoveFromSubgroup() throws Exception {
map.addRequest(change);
- PdpGroup group = makeGroup(MY_GROUP, MY_VERSION);
+ PdpGroup group = makeGroup(MY_GROUP);
group.setPdpSubgroups(Arrays.asList(makeSubGroup(MY_SUBGROUP, PDP1, PDP1 + "x", PDP1 + "y")));
when(dao.getFilteredPdpGroups(any())).thenReturn(Arrays.asList(group));
@@ -556,11 +593,10 @@ public class PdpModifyRequestMapTest extends CommonRequestBase {
return Whitebox.getInternalState(request, "listener");
}
- private PdpGroup makeGroup(String name, String version) {
+ private PdpGroup makeGroup(String name) {
PdpGroup group = new PdpGroup();
group.setName(name);
- group.setVersion(version);
return group;
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupStateChangeControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupStateChangeControllerV1.java
index d824b8b9..3220475e 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupStateChangeControllerV1.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupStateChangeControllerV1.java
@@ -41,12 +41,12 @@ public class TestPdpGroupStateChangeControllerV1 extends CommonPapRestServer {
@Test
public void testSwagger() throws Exception {
- super.testSwagger(GROUP_ENDPOINT + "/{name}/versions/{version}");
+ super.testSwagger(GROUP_ENDPOINT + "/{name}");
}
@Test
public void testchangeGroupState() throws Exception {
- final String uri = GROUP_ENDPOINT + "/my-name/versions/1.2.3?state=ACTIVE";
+ final String uri = GROUP_ENDPOINT + "/my-name?state=ACTIVE";
final Invocation.Builder invocationBuilder = sendRequest(uri);
Response rawresp = invocationBuilder.put(Entity.json(""));
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeployControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeployControllerV1.java
index 73a4f0e5..6ebad5ff 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeployControllerV1.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeployControllerV1.java
@@ -93,7 +93,6 @@ public class TestPdpGroupDeployControllerV1 extends CommonPapRestServer {
PdpGroup group = new PdpGroup();
group.setName("drools-group");
group.setDescription("my description");
- group.setVersion("my-version");
group.setPdpSubgroups(Arrays.asList(subgrp));
return Entity.entity(group, MediaType.APPLICATION_JSON);