replace grizzly server with policy common endpoint
[policy/apex-pdp.git] / testsuites / integration / integration-uservice-test / src / test / java / org / onap / policy / apex / testsuites / integration / uservice / adapt / restclient / TestExecutionPropertyRest.java
index 6adb3b0..b61c709 100644 (file)
 
 package org.onap.policy.apex.testsuites.integration.uservice.adapt.restclient;
 
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import java.net.URI;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.core.Response;
-import org.glassfish.grizzly.http.server.HttpServer;
-import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
-import org.glassfish.jersey.server.ResourceConfig;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -38,10 +27,21 @@ import org.junit.Test;
 import org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain;
 import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
 import org.onap.policy.apex.service.engine.main.ApexMain;
+import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
+import org.onap.policy.common.gson.GsonMessageBodyHandler;
 import org.onap.policy.common.utils.network.NetworkUtil;
 import org.slf4j.ext.XLogger;
 import org.slf4j.ext.XLoggerFactory;
 
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.core.Response;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import static org.junit.Assert.assertTrue;
+
 /**
  * This class runs integration tests for execution property in restClient.
  */
@@ -50,7 +50,8 @@ public class TestExecutionPropertyRest {
     private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestExecutionPropertyRest.class);
 
     private static final String BASE_URI = "http://localhost:32801/TestExecutionRest";
-    private static HttpServer server;
+    private static HttpServletServer server;
+    private static final int PORT = 32801;
 
     private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
     private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
@@ -84,11 +85,20 @@ public class TestExecutionPropertyRest {
      */
     @BeforeClass
     public static void setUp() throws Exception {
-        final ResourceConfig rc = new ResourceConfig(TestRestClientEndpoint.class);
-        server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
+        if (NetworkUtil.isTcpPortOpen("localHost", PORT, 3, 50L)) {
+            throw new IllegalStateException("port " + PORT + " is still in use");
+        }
+
+        server = HttpServletServerFactoryInstance.getServerFactory().build(
+            "TestExecutionPropertyRest", false, null, PORT, "/TestExecutionRest", false, false);
+
+        server.addServletClass(null, TestRestClientEndpoint.class.getName());
+        server.setSerializationProvider(GsonMessageBodyHandler.class.getName());
 
-        if (NetworkUtil.isTcpPortOpen(BASE_URI, 32801, 1, 1L)) {
-            throw new IllegalStateException("port " + 32801 + " is still in use");
+        server.start();
+
+        if (!NetworkUtil.isTcpPortOpen("localHost", PORT, 2000, 1L)) {
+            throw new IllegalStateException("port " + PORT + " is still not in use");
         }
 
     }
@@ -100,7 +110,9 @@ public class TestExecutionPropertyRest {
      */
     @AfterClass
     public static void tearDown() throws Exception {
-        server.shutdown();
+        if (server != null) {
+            server.stop();
+        }
     }
 
     /**