summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/examples-onap-vcpe/pom.xml12
-rw-r--r--examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSim.java33
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/pom.xml12
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java55
-rw-r--r--pom.xml5
-rw-r--r--testsuites/integration/integration-uservice-test/pom.xml6
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestExecutionPropertyRest.java46
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java53
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java51
9 files changed, 162 insertions, 111 deletions
diff --git a/examples/examples-onap-vcpe/pom.xml b/examples/examples-onap-vcpe/pom.xml
index fd59094b5..b9a992e67 100644
--- a/examples/examples-onap-vcpe/pom.xml
+++ b/examples/examples-onap-vcpe/pom.xml
@@ -50,12 +50,6 @@
<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>
<version>${version.jersey}</version>
@@ -96,6 +90,12 @@
<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>
diff --git a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSim.java b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSim.java
index 671f333d9..2a6a2e8d0 100644
--- a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSim.java
+++ b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSim.java
@@ -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.
@@ -20,31 +21,33 @@
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();
+ }
}
/**
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/pom.xml b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/pom.xml
index f56cfd2ac..47aa8d45f 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/pom.xml
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/pom.xml
@@ -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.
@@ -58,6 +59,17 @@
<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>
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java
index a9dfd8dc5..85027cc5b 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java
@@ -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.
@@ -20,25 +21,7 @@
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 54b370be7..802421b02 100644
--- a/pom.xml
+++ b/pom.xml
@@ -107,6 +107,11 @@
<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>
diff --git a/testsuites/integration/integration-uservice-test/pom.xml b/testsuites/integration/integration-uservice-test/pom.xml
index 73814306c..b1ab55061 100644
--- a/testsuites/integration/integration-uservice-test/pom.xml
+++ b/testsuites/integration/integration-uservice-test/pom.xml
@@ -178,12 +178,6 @@
<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>
<version>3.0.0</version>
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestExecutionPropertyRest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestExecutionPropertyRest.java
index 6adb3b007..b61c70961 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestExecutionPropertyRest.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestExecutionPropertyRest.java
@@ -20,17 +20,6 @@
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();
+ }
}
/**
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java
index 69bcf8706..534d4bcf6 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestFile2Rest.java
@@ -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.
@@ -20,24 +21,7 @@
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();
+ }
}
/**
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java
index 216b566ff..c44950b9e 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restclient/TestRest2File.java
@@ -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.
@@ -20,17 +21,6 @@
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***");
}
}