diff options
author | Jim Hahn <jrh3@att.com> | 2019-05-09 11:28:28 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-05-09 11:50:28 -0400 |
commit | 54cc5c118de45023692c72388b6389d184a658f7 (patch) | |
tree | 16f4881402a3d2ed4f6bdc03cc82fa06635ed653 /main/src/test/java | |
parent | 9bc1d7291d579e80fcb9723ae3400902abb49063 (diff) |
Return error when deleting non-existent policy
When undeploying a policy, if a policy's type is found in
a group, but the policy is not, then PAP returns 200. It
should return an error instead.
Change-Id: I88273fdbd5d49095e8248ab9267cccc529af0ae0
Issue-ID: POLICY-1758
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main/src/test/java')
4 files changed, 27 insertions, 16 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeleteProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeleteProvider.java index 72765ce6..8ef9b653 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeleteProvider.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestPdpGroupDeleteProvider.java @@ -113,10 +113,9 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper { @Test public void testDeleteGroup_NotFound() throws Exception { assertThatThrownBy(() -> prov.deleteGroup(GROUP1_NAME)).isInstanceOf(PfModelException.class) - .hasMessage("group not found").matches(thr -> { - PfModelException ex = (PfModelException) thr; - return (ex.getErrorResponse().getResponseCode() == Status.NOT_FOUND); - }); + .hasMessage("group not found") + .extracting(ex -> ((PfModelException) ex).getErrorResponse().getResponseCode()) + .isEqualTo(Status.NOT_FOUND); } @Test @@ -146,7 +145,7 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper { } @Test - public void testUndeploy_testDeletePolicy() throws Exception { + public void testUndeploy_testUndeployPolicy() throws Exception { prov.undeploy(optIdent); } @@ -186,7 +185,15 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper { } @Test - public void testDeletePolicy_DaoEx() throws Exception { + public void testUndeployPolicy_NotFound() throws Exception { + when(session.isUnchanged()).thenReturn(true); + + assertThatThrownBy(() -> prov.undeploy(optIdent)).isInstanceOf(PfModelException.class) + .hasMessage("policy does not appear in any PDP group: policyA null"); + } + + @Test + public void testUndeployPolicy_DaoEx() throws Exception { PfModelException exc = new PfModelException(Status.BAD_REQUEST, EXPECTED_EXCEPTION); prov = spy(prov); @@ -196,7 +203,7 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper { } @Test - public void testDeletePolicy_RtEx() throws Exception { + public void testUndeployPolicy_RtEx() throws Exception { RuntimeException exc = new RuntimeException(EXPECTED_EXCEPTION); prov = spy(prov); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestProviderBase.java b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestProviderBase.java index 55c6f3d4..c171e946 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestProviderBase.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestProviderBase.java @@ -155,10 +155,9 @@ public class TestProviderBase extends ProviderSuper { when(dao.getFilteredPolicyList(any())).thenReturn(Collections.emptyList()); assertThatThrownBy(() -> prov.process(loadRequest(), this::handle)).isInstanceOf(PfModelRuntimeException.class) - .hasMessage("cannot find policy: policyA 1.2.3").matches(thr -> { - PfModelRuntimeException exc = (PfModelRuntimeException) thr; - return (exc.getErrorResponse().getResponseCode() == Status.NOT_FOUND); - }); + .hasMessage("cannot find policy: policyA 1.2.3") + .extracting(ex -> ((PfModelRuntimeException) ex).getErrorResponse().getResponseCode()) + .isEqualTo(Status.NOT_FOUND); } @Test diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestSessionData.java b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestSessionData.java index f586d167..e7027c51 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestSessionData.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/depundep/TestSessionData.java @@ -24,8 +24,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -187,7 +189,9 @@ public class TestSessionData extends ProviderSuper { } @Test - public void testAddRequests_testGetPdpStateChanges_testGetPdpUpdates() { + public void testIsUnchanged_testAddRequests_testGetPdpStateChanges_testGetPdpUpdates() { + assertTrue(session.isUnchanged()); + // pre-load with a update and state-change for other PDPs PdpUpdate update2 = makeUpdate(PDP2); session.addUpdate(update2); @@ -199,6 +203,7 @@ public class TestSessionData extends ProviderSuper { PdpUpdate update = makeUpdate(PDP1); PdpStateChange change = makeStateChange(PDP1); session.addRequests(update, change); + assertFalse(session.isUnchanged()); verifyRequests(update, update2, change, change3); /* 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 463e8d6e..68e70287 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 @@ -124,8 +124,8 @@ public class PdpGroupDeleteTest extends End2EndBase { rawresp = invocationBuilder.delete(); resp = rawresp.readEntity(PdpGroupDeleteResponse.class); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); - assertNull(resp.getErrorDetails()); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawresp.getStatus()); + assertEquals("policy does not appear in any PDP group: onap.restart.tcaB null", resp.getErrorDetails()); } @Test @@ -162,7 +162,7 @@ public class PdpGroupDeleteTest extends End2EndBase { rawresp = invocationBuilder.delete(); resp = rawresp.readEntity(PdpGroupDeleteResponse.class); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); - assertNull(resp.getErrorDetails()); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawresp.getStatus()); + assertEquals("policy does not appear in any PDP group: onap.restart.tcaC 1.0.0", resp.getErrorDetails()); } } |