replace grizzly server with policy common endpoint 91/96991/4
authorHenry.Sun <henry.a.sun@est.tech>
Wed, 9 Oct 2019 10:02:56 +0000 (18:02 +0800)
committerHenry.Sun <henry.a.sun@est.tech>
Wed, 16 Oct 2019 10:02:51 +0000 (18:02 +0800)
Issue-ID: POLICY-1915
Change-Id: I8702a8b54e158dfd0ac08140ca083f14f23963a2
Signed-off-by: Henry.Sun <henry.a.sun@est.tech>
examples/examples-onap-vcpe/pom.xml
examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSim.java
plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/pom.xml
plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java
pom.xml
testsuites/integration/integration-uservice-test/pom.xml
testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestExecutionPropertyRest.java
testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java
testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java

index fd59094..b9a992e 100644 (file)
             <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.glassfish.jersey.containers</groupId>
-            <artifactId>jersey-container-grizzly2-http</artifactId>
-            <version>${version.jersey}</version>
-            <scope>test</scope>
-        </dependency>
         <dependency>
             <groupId>org.glassfish.jersey.inject</groupId>
             <artifactId>jersey-hk2</artifactId>
             <artifactId>events</artifactId>
             <version>${version.policy.models}</version>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.common</groupId>
+            <artifactId>policy-endpoints</artifactId>
+            <version>${version.policy.common}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
index 671f333..2a6a2e8 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ *  Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.apex.domains.onap.vcpe;
 
-import java.net.URI;
-
-import org.glassfish.grizzly.http.server.HttpServer;
-import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
-import org.glassfish.jersey.server.ResourceConfig;
 import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
+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;
 
 /**
- * The Class AaiAndGuardSim.
+ * The Class OnapVCpeSim.
  */
 public class OnapVCpeSim {
     private static final int MAX_LOOPS = 100000;
-    private HttpServer server;
+    private static HttpServletServer server;
 
     /**
      * Instantiates a new aai and guard sim.
      */
-    public OnapVCpeSim(final String[] args) {
-        final String baseUri = "http://" + args[0] + ':' + args[1] + "/OnapVCpeSim";
+    public OnapVCpeSim(final String[] args) throws Exception {
+        server = HttpServletServerFactoryInstance.getServerFactory().build(
+            "OnapVCpeSimEndpoint", false, args[0], Integer.valueOf(args[1]).intValue(), "/OnapVCpeSim", false, false);
+
+        server.addServletClass(null, OnapVCpeSimEndpoint.class.getName());
+        server.setSerializationProvider(GsonMessageBodyHandler.class.getName());
 
-        final ResourceConfig rc = new ResourceConfig(OnapVCpeSimEndpoint.class);
-        server = GrizzlyHttpServerFactory.createHttpServer(URI.create(baseUri), rc);
+        server.start();
 
-        while (!server.isStarted()) {
-            ThreadUtilities.sleep(50);
+        if (!NetworkUtil.isTcpPortOpen(args[0], Integer.valueOf(args[1]).intValue(), 2000, 1L)) {
+            throw new IllegalStateException("port " + args[1] + " is still not in use");
         }
     }
 
@@ -54,7 +57,9 @@ public class OnapVCpeSim {
      * @throws Exception the exception
      */
     public void tearDown() throws Exception {
-        server.shutdown();
+        if (server != null) {
+            server.stop();
+        }
     }
 
     /**
index f56cfd2..47aa8d4 100644 (file)
@@ -1,6 +1,7 @@
 <!--
   ============LICENSE_START=======================================================
    Copyright (C) 2018 Ericsson. All rights reserved.
+   Modifications Copyright (C) 2019 Nordix Foundation.
   ================================================================================
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
             <scope>test</scope>
             <version>${version.jersey}</version>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.common</groupId>
+            <artifactId>policy-endpoints</artifactId>
+            <version>${version.policy.common}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jersey.containers</groupId>
+            <artifactId>jersey-container-servlet-core</artifactId>
+            <version>${version.jersey}</version>
+        </dependency>
     </dependencies>
 
     <profiles>
index a9dfd8d..85027cc 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ *  Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.apex.plugins.event.carrier.restrequestor;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
 import com.google.gson.Gson;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.net.URI;
-import java.util.Map;
-
-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;
@@ -47,13 +30,30 @@ import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
 import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
 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 javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.core.Response;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 /**
  * The Class TestRestRequestor.
  */
 public class RestRequestorTest {
     private static final String BASE_URI = "http://localhost:32801/TestRESTRequestor";
-    private static HttpServer server;
+    private static final int PORT = 32801;
+    private static HttpServletServer server;
 
     private ByteArrayOutputStream outContent = new ByteArrayOutputStream();
     private ByteArrayOutputStream errContent = new ByteArrayOutputStream();
@@ -68,11 +68,16 @@ public class RestRequestorTest {
      */
     @BeforeClass
     public static void setUp() throws Exception {
-        final ResourceConfig rc = new ResourceConfig(SupportRestRequestorEndpoint.class);
-        server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
+        server = HttpServletServerFactoryInstance.getServerFactory().build(
+            null, false, null, PORT, "/TestRESTRequestor", false, false);
 
-        while (!server.isStarted()) {
-            ThreadUtilities.sleep(50);
+        server.addServletClass(null, SupportRestRequestorEndpoint.class.getName());
+        server.setSerializationProvider(GsonMessageBodyHandler.class.getName());
+
+        server.start();
+
+        if (!NetworkUtil.isTcpPortOpen("localHost", PORT, 2000, 1L)) {
+            throw new IllegalStateException("port " + PORT + " is still not in use");
         }
     }
 
@@ -83,7 +88,9 @@ public class RestRequestorTest {
      */
     @AfterClass
     public static void tearDown() throws Exception {
-        server.shutdownNow();
+        if (server != null) {
+            server.stop();
+        }
 
         new File("src/test/resources/events/EventsOut.json").delete();
         new File("src/test/resources/events/EventsOutMulti0.json").delete();
diff --git a/pom.xml b/pom.xml
index 54b370b..802421b 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                 <artifactId>common-parameters</artifactId>
                 <version>${version.policy.common}</version>
             </dependency>
+            <dependency>
+                <groupId>org.onap.policy.common</groupId>
+                <artifactId>policy-endpoints</artifactId>
+                <version>${version.policy.common}</version>
+            </dependency>
            <dependency>
                 <groupId>com.fasterxml.jackson.core</groupId>
                 <artifactId>jackson-core</artifactId>
index 7381430..b1ab550 100644 (file)
             <artifactId>jersey-client</artifactId>
             <version>${version.jersey}</version>
         </dependency>
-        <dependency>
-            <groupId>org.glassfish.jersey.containers</groupId>
-            <artifactId>jersey-container-grizzly2-http</artifactId>
-            <version>${version.jersey}</version>
-            <scope>test</scope>
-        </dependency>
         <dependency>
             <groupId>org.awaitility</groupId>
             <artifactId>awaitility</artifactId>
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();
+        }
     }
 
     /**
index 69bcf87..534d4bc 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ *  Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.apex.testsuites.integration.uservice.adapt.restclient;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
 import com.google.gson.Gson;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.net.URI;
-import java.util.Map;
-
-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;
@@ -46,9 +30,24 @@ import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
 import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
 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.IOException;
+import java.io.PrintStream;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 /**
  * The Class TestFile2Rest.
  */
@@ -56,7 +55,8 @@ public class TestFile2Rest {
     private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestFile2Rest.class);
 
     private static final String BASE_URI = "http://localhost:32801/TestFile2Rest";
-    private static HttpServer server;
+    private static final int PORT = 32801;
+    private static HttpServletServer server;
 
     private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
     private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
@@ -71,11 +71,16 @@ public class TestFile2Rest {
      */
     @BeforeClass
     public static void setUp() throws Exception {
-        final ResourceConfig rc = new ResourceConfig(TestRestClientEndpoint.class);
-        server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
+        server = HttpServletServerFactoryInstance.getServerFactory().build(
+            "TestFile2Rest", false, null, PORT, "/TestFile2Rest", false, false);
 
-        while (!server.isStarted()) {
-            ThreadUtilities.sleep(50);
+        server.addServletClass(null, TestRestClientEndpoint.class.getName());
+        server.setSerializationProvider(GsonMessageBodyHandler.class.getName());
+
+        server.start();
+
+        if (!NetworkUtil.isTcpPortOpen("localHost", PORT, 2000, 1L)) {
+            throw new IllegalStateException("port " + PORT + " is still not in use");
         }
     }
 
@@ -86,7 +91,9 @@ public class TestFile2Rest {
      */
     @AfterClass
     public static void tearDown() throws Exception {
-        server.shutdown();
+        if (server != null) {
+            server.stop();
+        }
     }
 
     /**
index 216b566..c44950b 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ *  Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.apex.testsuites.integration.uservice.adapt.restclient;
 
-import static org.junit.Assert.fail;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.net.URI;
-
-import org.glassfish.grizzly.http.server.HttpServer;
-import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
-import org.glassfish.jersey.server.ResourceConfig;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -40,9 +30,20 @@ import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
 import org.onap.policy.apex.model.utilities.TextFileUtils;
 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 java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
+
+import static org.junit.Assert.fail;
+
 /**
  * The Class TestRest2File.
  */
@@ -50,7 +51,8 @@ public class TestRest2File {
     private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestRest2File.class);
 
     private static final String BASE_URI = "http://localhost:32801/TestRest2File";
-    private HttpServer server;
+    private static final int PORT = 32801;
+    private static HttpServletServer server;
 
     private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
     private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
@@ -73,11 +75,16 @@ public class TestRest2File {
      */
     @Before
     public void setUp() throws Exception {
-        final ResourceConfig rc = new ResourceConfig(TestRestClientEndpoint.class);
-        server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
+        server = HttpServletServerFactoryInstance.getServerFactory().build(
+            "TestRest2File", false, null, PORT, "/TestRest2File", false, false);
+
+        server.addServletClass(null, TestRestClientEndpoint.class.getName());
+        server.setSerializationProvider(GsonMessageBodyHandler.class.getName());
 
-        while (!server.isStarted()) {
-            ThreadUtilities.sleep(50);
+        server.start();
+
+        if (!NetworkUtil.isTcpPortOpen("localHost", PORT, 2000, 1L)) {
+            throw new IllegalStateException("port " + PORT + " is still not in use");
         }
     }
 
@@ -88,7 +95,9 @@ public class TestRest2File {
      */
     @After
     public void tearDown() throws Exception {
-        server.shutdown();
+        if (server != null) {
+            server.stop();
+        }
     }
 
     /**
@@ -254,7 +263,7 @@ public class TestRest2File {
 
         checkRequiredString(outString,
             "reception of event from URL " + "\"http://localhost:32801/TestRest2File/apex/event/GetEventBadResponse\" "
-                + "failed with status code 400 and message \"\"");
+                + "failed with status code 400 and message \"");
     }
 
     /**
@@ -263,9 +272,9 @@ public class TestRest2File {
      * @param outputEventText the text to examine
      * @param requiredString the string to search for
      */
-    private void checkRequiredString(String outputText, String requiredString) {
-        if (!outputText.contains(requiredString)) {
-            LOGGER.error("\n***output text:\n" + outputText + "\n***");
+    private void checkRequiredString(String outputEventText, String requiredString) {
+        if (!outputEventText.contains(requiredString)) {
+            LOGGER.error("\n***output text:\n" + outputEventText + "\n***");
             fail("\n***test output did not contain required string:\n" + requiredString + "\n***");
         }
     }