X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ecomp-portal-BE-common%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fportalapp%2Fportal%2Fcontroller%2FPolicyControllerTest.java;h=98292c66f1dec668c9c555e0a0524cdf8c01abb6;hb=6f03ccd5a4ad90296f4dc3567531848fce1d8ad5;hp=bddcde65b8b27ec0ee1e75e0936693096a7693c9;hpb=7235549c9a028b494cb21f3ed9c1087dd07f0036;p=portal.git diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PolicyControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PolicyControllerTest.java index bddcde65..98292c66 100644 --- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PolicyControllerTest.java +++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/PolicyControllerTest.java @@ -143,6 +143,56 @@ public class PolicyControllerTest { } + @SuppressWarnings("unchecked") + @Test + public void getPolicyInfoTestException() throws Exception { + + JSONObject jsonObject = Mockito.mock(JSONObject.class); + PowerMockito.mockStatic(SchedulerAuxRestInterfaceFactory.class); + PowerMockito.mockStatic(SchedulerProperties.class); + SchedulerAuxRestInterfaceIfc policyRestInterface = Mockito.mock(SchedulerAuxRestInterfaceIfc.class); + PowerMockito.mockStatic(SchedulerAuxUtil.class); + // RestObject restObj=Mockito.mock(RestObject.class); + SchedulerAuxResponseWrapper policyWrapper = Mockito.mock(SchedulerAuxResponseWrapper.class); + PowerMockito.when(SchedulerAuxUtil.wrapResponse(Matchers.any(RestObject.class))).thenReturn(policyWrapper); + Mockito.when(policyWrapper.getResponse()).thenReturn("Success"); + Mockito.when(policyWrapper.getStatus()).thenReturn(200); + + PowerMockito.when(SchedulerAuxRestInterfaceFactory.getInstance()).thenReturn(policyRestInterface); + /*Mockito.doNothing().when(policyRestInterface).Post(Matchers.anyString(), Matchers.anyObject(), + Matchers.anyString(), Matchers.anyString(), Matchers.anyObject());*/ + Mockito.doThrow(new NullPointerException()).when(policyRestInterface).Post(Matchers.anyString(), Matchers.anyObject(), + Matchers.anyString(), Matchers.anyString(), Matchers.anyObject()); + + + ResponseEntity responsePolicy = policyController.getPolicyInfo(mockedRequest); + Assert.assertEquals(responsePolicy.getStatusCode(), HttpStatus.INTERNAL_SERVER_ERROR); + } + + @SuppressWarnings("unchecked") + @Test + public void getPolicyInfoTestException1() throws Exception { + + JSONObject jsonObject = Mockito.mock(JSONObject.class); + PowerMockito.mockStatic(SchedulerAuxRestInterfaceFactory.class); + PowerMockito.mockStatic(SchedulerProperties.class); + SchedulerAuxRestInterfaceIfc policyRestInterface = Mockito.mock(SchedulerAuxRestInterfaceIfc.class); + PowerMockito.mockStatic(SchedulerAuxUtil.class); + // RestObject restObj=Mockito.mock(RestObject.class); + SchedulerAuxResponseWrapper policyWrapper = Mockito.mock(SchedulerAuxResponseWrapper.class); + PowerMockito.when(SchedulerAuxUtil.wrapResponse(Matchers.any(RestObject.class))).thenReturn(policyWrapper); + Mockito.when(policyWrapper.getResponse()).thenReturn("Bad Request"); + Mockito.when(policyWrapper.getStatus()).thenReturn(400); + + PowerMockito.when(SchedulerAuxRestInterfaceFactory.getInstance()).thenReturn(policyRestInterface); + Mockito.doNothing().when(policyRestInterface).Post(Matchers.anyString(), Matchers.anyObject(), + Matchers.anyString(), Matchers.anyString(), Matchers.anyObject()); + /*Mockito.doThrow(new NullPointerException()).when(policyRestInterface).Post(Matchers.anyString(), Matchers.anyObject(), + Matchers.anyString(), Matchers.anyString(), Matchers.anyObject());*/ + + ResponseEntity responsePolicy = policyController.getPolicyInfo(mockedRequest); + Assert.assertEquals(responsePolicy.getStatusCode(), HttpStatus.BAD_REQUEST); + } }