X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fhandler%2FDeleteHandlerTest.java;h=a9da00d5ac2fcf9b26cfc99867c83dc9495773b5;hb=3948f989c9bb16fe3d5c0e46265ba4f4c7834815;hp=17967a4bbf346d0656ec21a49fd731dc4f447bb3;hpb=1e61676b77dd09659027b8984f050df7e8538526;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/DeleteHandlerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/DeleteHandlerTest.java index 17967a4bb..a9da00d5a 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/DeleteHandlerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/DeleteHandlerTest.java @@ -23,16 +23,15 @@ package org.onap.policy.pap.xacml.rest.handler; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; import com.mockrunner.mock.web.MockHttpServletRequest; import com.mockrunner.mock.web.MockHttpServletResponse; - +import java.io.IOException; import java.util.Collections; import java.util.List; - import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; @@ -44,6 +43,7 @@ import org.onap.policy.common.logging.OnapLoggingContext; import org.onap.policy.pap.xacml.rest.XACMLPapServlet; import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl; import org.onap.policy.pap.xacml.rest.elk.client.PolicyElasticSearchController; +import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.PolicyEntity; import org.onap.policy.xacml.api.pap.PAPPolicyEngine; import org.onap.policy.xacml.std.pap.StdEngine; @@ -98,19 +98,11 @@ public class DeleteHandlerTest { // Test deletion from PAP MockHttpServletResponse response = new MockHttpServletResponse(); - try { - handler.doApiDeleteFromPap(request, response); - } catch (Exception ex) { - fail("Not expecting an exception: " + ex); - } + handler.doApiDeleteFromPap(request, response); // Test deletion from PDP OnapLoggingContext loggingContext = Mockito.mock(OnapLoggingContext.class); - try { - handler.doApiDeleteFromPdp(request, response, loggingContext); - } catch (Exception ex) { - fail("Not expecting an exception: " + ex); - } + handler.doApiDeleteFromPdp(request, response, loggingContext); // Test delete entity PolicyEntity policyEntity = new PolicyEntity(); @@ -122,4 +114,34 @@ public class DeleteHandlerTest { List peResult = Collections.emptyList(); assertEquals(DeleteHandler.checkPolicyGroupEntity(peResult), false); } + + @Test + public void testDoDeletePap() throws IOException { + CommonClassDao dao = Mockito.mock(CommonClassDao.class); + DeleteHandler handler = new DeleteHandler(dao); + + // Mock request + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setBodyContent( + "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Config_name.1.xml\", \"deleteCondition\": \"All Versions\"\n}\n"); + MockHttpServletResponse response = new MockHttpServletResponse(); + + handler.doApiDeleteFromPap(request, response); + assertTrue(response.containsHeader("error")); + } + + @Test(expected = NullPointerException.class) + public void testDoDeletePdp() throws IOException { + CommonClassDao dao = Mockito.mock(CommonClassDao.class); + DeleteHandler handler = new DeleteHandler(dao); + OnapLoggingContext loggingContext = new OnapLoggingContext(); + + // Mock request + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setBodyContent( + "{\n\"PAPPolicyType\": \"StdPAPPolicy\", \"policyName\": \"foo.Config_name.1.xml\", \"deleteCondition\": \"All Versions\"\n}\n"); + MockHttpServletResponse response = new MockHttpServletResponse(); + + handler.doApiDeleteFromPdp(request, response, loggingContext); + } }