Xacml PDP Register/Unregister Changes
[policy/xacml-pdp.git] / main / src / test / java / org / onap / policy / pdpx / main / rest / TestXacmlPdpRestServer.java
index 1ec649c..0deab9d 100644 (file)
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Modifier;
@@ -42,7 +43,10 @@ import org.glassfish.jersey.client.ClientConfig;
 import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
 import org.junit.After;
 import org.junit.BeforeClass;
+import org.junit.ClassRule;
 import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClientException;
 import org.onap.policy.common.endpoints.report.HealthCheckReport;
 import org.onap.policy.common.utils.network.NetworkUtil;
 import org.onap.policy.pdpx.main.PolicyXacmlPdpException;
@@ -69,15 +73,21 @@ public class TestXacmlPdpRestServer {
     private static String KEYSTORE = System.getProperty("user.dir") + "/src/test/resources/ssl/policy-keystore";
     private Main main;
     private XacmlPdpRestServer restServer;
+    private static File applicationPath;
+
+    @ClassRule
+    public static final TemporaryFolder applicationFolder = new TemporaryFolder();
 
     /**
      * setup.
+     *
+     * @throws IOException exception if cannot create temporary folder
      */
     @BeforeClass
-    public static void setUp() {
+    public static void setUp() throws IOException {
         System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.StdErrLog");
         System.setProperty("org.eclipse.jetty.LEVEL", "OFF");
-
+        applicationPath = applicationFolder.newFolder();
     }
 
     /**
@@ -104,7 +114,7 @@ public class TestXacmlPdpRestServer {
     }
 
     @Test
-    public void testHealthCheckSuccess() throws IOException, InterruptedException {
+    public void testHealthCheckSuccess() throws IOException, InterruptedException, TopicSinkClientException {
         main = startXacmlPdpService(true);
         final Invocation.Builder invocationBuilder = sendHttpRequest(HEALTHCHECK_ENDPOINT);
         final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
@@ -115,7 +125,7 @@ public class TestXacmlPdpRestServer {
     public void testHealthCheckFailure() throws InterruptedException, IOException {
         final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false);
         restServerParams.setName(CommonTestData.PDPX_GROUP_NAME);
-        restServer = new XacmlPdpRestServer(restServerParams);
+        restServer = new XacmlPdpRestServer(restServerParams, applicationPath.getAbsolutePath());
         restServer.start();
         final Invocation.Builder invocationBuilder = sendHttpRequest(HEALTHCHECK_ENDPOINT);
         final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
@@ -133,7 +143,7 @@ public class TestXacmlPdpRestServer {
     }
 
     @Test
-    public void testStatistics_200() throws IOException, InterruptedException {
+    public void testStatistics_200() throws IOException, InterruptedException, TopicSinkClientException {
         main = startXacmlPdpService(true);
         Invocation.Builder invocationBuilder = sendHttpRequest(STATISTICS_ENDPOINT);
         StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
@@ -149,7 +159,7 @@ public class TestXacmlPdpRestServer {
     public void testStatistics_500() throws IOException, InterruptedException {
         final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false);
         restServerParams.setName(CommonTestData.PDPX_GROUP_NAME);
-        restServer = new XacmlPdpRestServer(restServerParams);
+        restServer = new XacmlPdpRestServer(restServerParams, applicationPath.getAbsolutePath());
         restServer.start();
         final Invocation.Builder invocationBuilder = sendHttpRequest(STATISTICS_ENDPOINT);
         final StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
@@ -179,11 +189,13 @@ public class TestXacmlPdpRestServer {
         }
     }
 
-    private Main startXacmlPdpService(final boolean http) {
-        final String[] xacmlPdpConfigParameters = new String[2];
+    private Main startXacmlPdpService(final boolean http) throws TopicSinkClientException {
+        final String[] xacmlPdpConfigParameters = new String[4];
         if (http) {
             xacmlPdpConfigParameters[0] = "-c";
             xacmlPdpConfigParameters[1] = "parameters/XacmlPdpConfigParameters.json";
+            xacmlPdpConfigParameters[2] = "-p";
+            xacmlPdpConfigParameters[3] = "parameters/topic.properties";
         } else {
             final Properties systemProps = System.getProperties();
             systemProps.put("javax.net.ssl.keyStore", KEYSTORE);
@@ -191,6 +203,8 @@ public class TestXacmlPdpRestServer {
             System.setProperties(systemProps);
             xacmlPdpConfigParameters[0] = "-c";
             xacmlPdpConfigParameters[1] = "parameters/XacmlPdpConfigParameters_Https.json";
+            xacmlPdpConfigParameters[2] = "-p";
+            xacmlPdpConfigParameters[3] = "parameters/topic.properties";
         }
         return new Main(xacmlPdpConfigParameters);
     }
@@ -230,7 +244,7 @@ public class TestXacmlPdpRestServer {
 
             @Override
             public void checkServerTrusted(final java.security.cert.X509Certificate[] certs, final String authType) {}
-        }};
+        } };
 
         final SSLContext sc = SSLContext.getInstance("TLSv1.2");
         sc.init(null, noopTrustManager, new SecureRandom());