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=84f36aa63a77f5b9a5ba8afa115648ae5c9ff781;hb=4068da123ee33b532b4b52f15545c76a978f977e;hp=3941593e93b12ae0d61efbc5f363e130fc64cae4;hpb=83fcb4f327512d857c7df91e35d9e1cb81dc4228;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 3941593e9..84f36aa63 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 @@ -47,68 +47,68 @@ import javax.persistence.EntityManager; @RunWith(PowerMockRunner.class) public class DeleteHandlerTest { - @Test - public void testGets() { - DeleteHandler handler = new DeleteHandler(); - assertNotNull(handler); - assertEquals(handler.preSafetyCheck(null), true); - assertNull(handler.getDeletedGroup()); - } - - @Test - public void testGetInstance() { - DeleteHandler handler = DeleteHandler.getInstance(); - assertNotNull(handler); - } - - @PrepareForTest({DeleteHandler.class, XACMLPapServlet.class}) - @Test - public void testDeletes() throws Exception { - // Mock request - DeleteHandler handler = new DeleteHandler(); - MockHttpServletRequest request = new MockHttpServletRequest(); - request.setBodyContent("{\n\"PAPPolicyType\": \"StdPAPPolicy\"\n}\n"); - - // Mock servlet - PAPPolicyEngine engine = Mockito.mock(StdEngine.class); - PowerMockito.mockStatic(XACMLPapServlet.class); - when(XACMLPapServlet.getPAPEngine()).thenReturn(engine); - when(engine.getGroup(any())).thenReturn(null); - - // Mock elastic search - PolicyElasticSearchController controller = Mockito.mock(PolicyElasticSearchController.class); - PowerMockito.whenNew(PolicyElasticSearchController.class).withNoArguments().thenReturn(controller); - - // Mock entity manager - EntityManager em = Mockito.mock(EntityManager.class); - - // Test deletion from PAP - MockHttpServletResponse response = new MockHttpServletResponse(); - try { - handler.doAPIDeleteFromPAP(request, response); - } - catch (Exception ex) { - fail("Not expecting an exception: " + ex); - } - - // 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); - } - - // Test delete entity - PolicyEntity policyEntity = new PolicyEntity(); - policyEntity.setPolicyName("testVal"); - String result = DeleteHandler.deletePolicyEntityData(em, policyEntity); - assertEquals(result, "success"); - - // Test check entity - Connection con = null; - List peResult = Collections.emptyList(); - assertEquals(DeleteHandler.checkPolicyGroupEntity(con, peResult), false); - } + @Test + public void testGets() { + DeleteHandler handler = new DeleteHandler(); + assertNotNull(handler); + assertEquals(handler.preSafetyCheck(null), true); + assertNull(handler.getDeletedGroup()); + } + + @Test + public void testGetInstance() { + DeleteHandler handler = DeleteHandler.getInstance(); + assertNotNull(handler); + } + + @PrepareForTest({DeleteHandler.class, XACMLPapServlet.class}) + @Test + public void testDeletes() throws Exception { + // Mock request + DeleteHandler handler = new DeleteHandler(); + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setBodyContent("{\n\"PAPPolicyType\": \"StdPAPPolicy\"\n}\n"); + + // Mock servlet + PAPPolicyEngine engine = Mockito.mock(StdEngine.class); + PowerMockito.mockStatic(XACMLPapServlet.class); + when(XACMLPapServlet.getPAPEngine()).thenReturn(engine); + when(engine.getGroup(any())).thenReturn(null); + + // Mock elastic search + PolicyElasticSearchController controller = Mockito.mock(PolicyElasticSearchController.class); + PowerMockito.whenNew(PolicyElasticSearchController.class).withNoArguments().thenReturn(controller); + + // Mock entity manager + EntityManager em = Mockito.mock(EntityManager.class); + + // Test deletion from PAP + MockHttpServletResponse response = new MockHttpServletResponse(); + try { + handler.doAPIDeleteFromPAP(request, response); + } + catch (Exception ex) { + fail("Not expecting an exception: " + ex); + } + + // 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); + } + + // Test delete entity + PolicyEntity policyEntity = new PolicyEntity(); + policyEntity.setPolicyName("testVal"); + String result = DeleteHandler.deletePolicyEntityData(em, policyEntity); + assertEquals(result, "success"); + + // Test check entity + Connection con = null; + List peResult = Collections.emptyList(); + assertEquals(DeleteHandler.checkPolicyGroupEntity(con, peResult), false); + } }