aboutsummaryrefslogtreecommitdiffstats
path: root/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/RESTfulPAPEngineTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'POLICY-SDK-APP/src/test/java/org/onap/policy/admin/RESTfulPAPEngineTest.java')
-rw-r--r--POLICY-SDK-APP/src/test/java/org/onap/policy/admin/RESTfulPAPEngineTest.java38
1 files changed, 30 insertions, 8 deletions
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)
);
}
+
}