summaryrefslogtreecommitdiffstats
path: root/main/src/test/java
diff options
context:
space:
mode:
authorAli Hockla <ah999m@att.com>2019-11-08 12:54:02 -0600
committerAli Hockla <ah999m@att.com>2019-11-12 08:06:23 -0600
commit8d28c6fc936eb4bd95ad1ebd013996cff4787e0e (patch)
treece1a83362e61812de0edadc1e03635f071c07286 /main/src/test/java
parentdd69ccf79236b5268cc8cac2638fcd07f373bd4d (diff)
Added support to return status and error if pdp-x failed to load policy
Issue-ID: POLICY-2175 Change-Id: I32d2fe78846f58d6e700100dd523732817f1f04d Signed-off-by: Ali Hockla <ah999m@att.com>
Diffstat (limited to 'main/src/test/java')
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java8
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpUpdatePublisherTest.java39
2 files changed, 43 insertions, 4 deletions
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java b/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
index eef1f1be..12d832ac 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
@@ -23,6 +23,7 @@ package org.onap.policy.pdpx.main;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -154,17 +155,22 @@ public class XacmlStateTest {
req.setPdpGroup(GROUP);
req.setPdpSubgroup(SUBGROUP);
- PdpStatus status = state.updateInternalState(req);
+ PdpStatus status = state.updateInternalState(req, "");
PdpResponseDetails resp = status.getResponse();
assertNotNull(resp);
assertEquals(req.getRequestId(), resp.getResponseTo());
assertEquals(PdpResponseStatus.SUCCESS, resp.getResponseStatus());
+ assertNull(resp.getResponseMessage());
// ensure info was saved
status = state.genHeartbeat();
assertEquals(GROUP, status.getPdpGroup());
assertEquals(SUBGROUP, status.getPdpSubgroup());
+
+ status = state.updateInternalState(req, "Failed to load policy: failLoadPolicy1: null");
+ assertEquals(status.getResponse().getResponseMessage(), "Failed to load policy: failLoadPolicy1: null");
+ assertEquals(status.getResponse().getResponseStatus(), PdpResponseStatus.FAIL);
}
@Test
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpUpdatePublisherTest.java b/main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpUpdatePublisherTest.java
index 31bec51e..c8c6a816 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpUpdatePublisherTest.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpUpdatePublisherTest.java
@@ -22,6 +22,8 @@ package org.onap.policy.pdpx.main.comm;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.startsWith;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -38,6 +40,7 @@ import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClient;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.pdp.xacml.application.common.XacmlApplicationException;
import org.onap.policy.pdp.xacml.application.common.XacmlApplicationServiceProvider;
import org.onap.policy.pdpx.main.XacmlState;
import org.onap.policy.pdpx.main.rest.XacmlPdpApplicationManager;
@@ -82,8 +85,17 @@ public class XacmlPdpUpdatePublisherTest {
private ToscaPolicy added2;
@Mock
+ private ToscaPolicy failPolicy1;
+
+ @Mock
+ private ToscaPolicy failPolicy2;
+
+ @Mock
private PdpUpdate update;
+ @Mock
+ private PdpUpdate failurePdpUpdate;
+
private XacmlPdpUpdatePublisher publisher;
@@ -105,9 +117,12 @@ public class XacmlPdpUpdatePublisherTest {
List<ToscaPolicy> updatePolicies = Arrays.asList(added1, deployed2, deployed3, added2);
when(update.getPolicies()).thenReturn(updatePolicies);
+ List<ToscaPolicy> failureUpdatePolicies = Arrays.asList(added1, deployed2, deployed3, failPolicy1, failPolicy2);
+ when(failurePdpUpdate.getPolicies()).thenReturn(failureUpdatePolicies);
+
when(appmgr.getPolicyCount()).thenReturn(NEW_COUNT);
- when(state.updateInternalState(update)).thenReturn(status);
+ when(state.updateInternalState(any(), any())).thenReturn(status);
when(client.send(any())).thenReturn(true);
@@ -115,7 +130,7 @@ public class XacmlPdpUpdatePublisherTest {
}
@Test
- public void testHandlePdpUpdate() {
+ public void testHandlePdpUpdate() throws XacmlApplicationException {
XacmlPdpStatisticsManager statmgr = new XacmlPdpStatisticsManager();
XacmlPdpStatisticsManager.setCurrent(statmgr);
@@ -141,7 +156,25 @@ public class XacmlPdpUpdatePublisherTest {
}
@Test
- public void testHandlePdpUpdate_NullPolicies() {
+ public void testHandlePdpUpdate_LoadPolicyFailed() throws XacmlApplicationException {
+ // Set loadPolicy to fail
+ doThrow(new XacmlApplicationException()).when(appmgr).loadDeployedPolicy(failPolicy1);
+ doThrow(new XacmlApplicationException()).when(appmgr).loadDeployedPolicy(failPolicy2);
+
+ publisher.handlePdpUpdate(failurePdpUpdate);
+
+ // two removed
+ verify(appmgr).removeUndeployedPolicy(deployed1);
+ verify(appmgr).removeUndeployedPolicy(deployed4);
+
+ verify(failurePdpUpdate).setPolicies(any());
+
+ verify(state).updateInternalState(any(), startsWith("Failed to load policy"));
+ verify(client).send(status);
+ }
+
+ @Test
+ public void testHandlePdpUpdate_NullPolicies() throws XacmlApplicationException {
when(update.getPolicies()).thenReturn(null);
publisher.handlePdpUpdate(update);