X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fpolicy%2Fadmin%2FRESTfulPAPEngineTest.java;h=ec2643fed2f56c86a267061d281fa775e9504663;hp=993c322d55d96b894e8ad3d5d1da9a826ca88eb1;hb=796004c50a61b8b9d8353f4597a590cf81155ba5;hpb=6c6f1ee4a70d21df62d6db855a83adb50ec24ff4 diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/RESTfulPAPEngineTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/RESTfulPAPEngineTest.java index 993c322d5..ec2643fed 100644 --- a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/RESTfulPAPEngineTest.java +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/RESTfulPAPEngineTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Engine * ================================================================================ - * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Modifications Copyright (C) 2019 Samsung * ================================================================================ @@ -28,15 +28,12 @@ import static org.junit.Assert.assertNull; import com.att.research.xacml.api.pap.PAPException; import com.att.research.xacml.api.pap.PDPPolicy; import com.att.research.xacml.util.XACMLProperties; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URLConnection; - import javax.servlet.http.HttpServletResponse; - import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -79,11 +76,15 @@ public class RESTfulPAPEngineTest { XACMLProperties.reloadProperties(); } - private void setupConnection(int responseCode) throws Exception { + private void setupConnection(int responseCode, String location) throws Exception { // Mock connection HttpURLConnection connection = Mockito.mock(HttpURLConnection.class); + Mockito.when(connection.getResponseCode()).thenReturn(responseCode); - Mockito.when(connection.getHeaderField("Location")).thenReturn("localhost:5678"); + Mockito.when(connection.getHeaderField("Location")).thenReturn(location); + + InputStream mockInputStream = Mockito.mock(InputStream.class); + Mockito.when(connection.getInputStream()).thenReturn(mockInputStream); // Set the system property temporarily String systemKey = "xacml.properties"; @@ -112,7 +113,7 @@ public class RESTfulPAPEngineTest { @Test public void testAllTheExceptions() throws Exception { - setupConnection(HttpServletResponse.SC_NO_CONTENT); + setupConnection(HttpServletResponse.SC_NO_CONTENT, "localhost:5678"); engine.setDefaultGroup(group); assertNull(engine.getDefaultGroup()); @@ -131,6 +132,10 @@ public class RESTfulPAPEngineTest { engine.updateGroup(group) ); + assertThatExceptionOfType(PAPException.class).isThrownBy(() -> + engine.updateGroup(group, "testUserName") + ); + assertNull(engine.getGroup(name)); engine.movePDP(pdp, newGroup); @@ -172,7 +177,24 @@ public class RESTfulPAPEngineTest { // Change the mockito to take a different path // assertThatExceptionOfType(PAPException.class).isThrownBy(() -> - setupConnection(HttpServletResponse.SC_FOUND) + setupConnection(HttpServletResponse.SC_FOUND, "localhost:5678") + ); + + assertThatExceptionOfType(PAPException.class).isThrownBy(() -> + setupConnection(200, "localhost:5678") + ); + + assertThatExceptionOfType(PAPException.class).isThrownBy(() -> + setupConnection(350, "localhost:5678") + ); + + assertThatExceptionOfType(PAPException.class).isThrownBy(() -> + setupConnection(500, "localhost:5678") + ); + + assertThatExceptionOfType(PAPException.class).isThrownBy(() -> + setupConnection(350, null) ); } + }