aboutsummaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'policy-endpoints/src/test/java')
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java207
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java227
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/NoopTopicTest.java123
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestEchoService.java46
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestEndpoints.java45
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestMockHealthCheck.java48
6 files changed, 696 insertions, 0 deletions
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java
new file mode 100644
index 00000000..d4840e68
--- /dev/null
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java
@@ -0,0 +1,207 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-endpoints
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.endpoints.http.server.test;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+
+import javax.ws.rs.core.Response;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.policy.common.endpoints.http.client.HttpClient;
+import org.onap.policy.common.endpoints.http.client.impl.IndexedHttpClientFactory;
+import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.endpoints.http.server.impl.IndexedHttpServletServerFactory;
+import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
+import org.onap.policy.common.utils.network.NetworkUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HttpClientTest {
+
+ private static Logger logger = LoggerFactory.getLogger(HttpClientTest.class);
+
+ @BeforeClass
+ public static void setUp() throws InterruptedException, IOException {
+ logger.info("-- setup() --");
+
+ /* echo server */
+
+ final HttpServletServer echoServerNoAuth =
+ IndexedHttpServletServerFactory.getInstance().build("echo", "localhost", 6666, "/", false, true);
+ echoServerNoAuth.addServletPackage("/*", HttpClientTest.class.getPackage().getName());
+ echoServerNoAuth.waitedStart(5000);
+
+ if (!NetworkUtil.isTcpPortOpen("localhost", echoServerNoAuth.getPort(), 5, 10000L)) {
+ throw new IllegalStateException("cannot connect to port " + echoServerNoAuth.getPort());
+ }
+
+ /* no auth echo server */
+
+ final HttpServletServer echoServerAuth =
+ IndexedHttpServletServerFactory.getInstance().build("echo", "localhost", 6667, "/", false, true);
+ echoServerAuth.setBasicAuthentication("x", "y", null);
+ echoServerAuth.addServletPackage("/*", HttpClientTest.class.getPackage().getName());
+ echoServerAuth.waitedStart(5000);
+
+ if (!NetworkUtil.isTcpPortOpen("localhost", echoServerAuth.getPort(), 5, 10000L)) {
+ throw new IllegalStateException("cannot connect to port " + echoServerAuth.getPort());
+ }
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ logger.info("-- tearDown() --");
+
+ IndexedHttpServletServerFactory.getInstance().destroy();
+ IndexedHttpClientFactory.getInstance().destroy();
+ }
+
+ @Test
+ public void testHttpNoAuthClient() throws Exception {
+ logger.info("-- testHttpNoAuthClient() --");
+
+ final HttpClient client = IndexedHttpClientFactory.getInstance().build("testHttpNoAuthClient", false, false,
+ "localhost", 6666, "junit/echo", null, null, true);
+ final Response response = client.get("hello");
+ final String body = HttpClient.getBody(response, String.class);
+
+ assertTrue(response.getStatus() == 200);
+ assertTrue(body.equals("hello"));
+ }
+
+ @Test
+ public void testHttpAuthClient() throws Exception {
+ logger.info("-- testHttpAuthClient() --");
+
+ final HttpClient client = IndexedHttpClientFactory.getInstance().build("testHttpAuthClient", false, false,
+ "localhost", 6667, "junit/echo", "x", "y", true);
+ final Response response = client.get("hello");
+ final String body = HttpClient.getBody(response, String.class);
+
+ assertTrue(response.getStatus() == 200);
+ assertTrue(body.equals("hello"));
+ }
+
+ @Test
+ public void testHttpAuthClient401() throws Exception {
+ logger.info("-- testHttpAuthClient401() --");
+
+ final HttpClient client = IndexedHttpClientFactory.getInstance().build("testHttpAuthClient401", false, false,
+ "localhost", 6667, "junit/echo", null, null, true);
+ final Response response = client.get("hello");
+ assertTrue(response.getStatus() == 401);
+ }
+
+ @Test
+ public void testHttpAuthClientProps() throws Exception {
+ logger.info("-- testHttpAuthClientProps() --");
+
+ final Properties httpProperties = new Properties();
+
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES, "PAP,PDP");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PAP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, "localhost");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PAP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "7777");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PAP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, "testpap");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PAP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX, "alpha123");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PAP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX, RestMockHealthCheck.class.getName());
+ httpProperties.setProperty(
+ PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP" + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX,
+ "true");
+
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PDP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, "localhost");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PDP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "7778");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PDP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, "testpdp");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PDP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX, "alpha123");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PDP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX, RestMockHealthCheck.class.getName());
+ httpProperties.setProperty(
+ PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP" + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX,
+ "true");
+
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES, "PAP,PDP");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, "localhost");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "7777");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_URL_SUFFIX, "pap/test");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX, "false");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, "testpap");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX, "alpha123");
+ httpProperties.setProperty(
+ PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP" + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX,
+ "true");
+
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, "localhost");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "7778");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_URL_SUFFIX, "pdp");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX, "false");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, "testpdp");
+ httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP"
+ + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX, "alpha123");
+ httpProperties.setProperty(
+ PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP" + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX,
+ "true");
+
+ final List<HttpServletServer> servers = IndexedHttpServletServerFactory.getInstance().build(httpProperties);
+ assertTrue(servers.size() == 2);
+
+ final List<HttpClient> clients = IndexedHttpClientFactory.getInstance().build(httpProperties);
+ assertTrue(clients.size() == 2);
+
+ for (final HttpServletServer server : servers) {
+ server.waitedStart(10000);
+ }
+
+ final HttpClient clientPAP = IndexedHttpClientFactory.getInstance().get("PAP");
+ final Response response = clientPAP.get();
+ assertTrue(response.getStatus() == 200);
+
+ final HttpClient clientPDP = IndexedHttpClientFactory.getInstance().get("PDP");
+ final Response response2 = clientPDP.get("test");
+ assertTrue(response2.getStatus() == 500);
+ }
+
+
+}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java
new file mode 100644
index 00000000..eba96208
--- /dev/null
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java
@@ -0,0 +1,227 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-endpoints
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.endpoints.http.server.test;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.ConnectException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.UUID;
+
+import org.junit.Test;
+import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.endpoints.http.server.HttpServletServerFactory;
+import org.onap.policy.common.endpoints.http.server.impl.IndexedHttpServletServerFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * HttpServletServer JUNIT tests
+ */
+public class HttpServerTest {
+
+ HttpServletServerFactory httpServletServerFactory = IndexedHttpServletServerFactory.getInstance();
+
+ /**
+ * Logger
+ */
+ private static Logger logger = LoggerFactory.getLogger(HttpServerTest.class);
+
+ @Test
+ public void testSingleServer() throws Exception {
+ logger.info("-- testSingleServer() --");
+
+ HttpServletServer server = httpServletServerFactory.build("echo", "localhost", 5678, "/", false, true);
+ server.addServletPackage("/*", this.getClass().getPackage().getName());
+ server.waitedStart(5000);
+
+ assertTrue(httpServletServerFactory.get(5678).isAlive());
+
+ String response = http(httpServletServerFactory.get(5678), "http://localhost:5678/junit/echo/hello");
+ assertTrue("hello".equals(response));
+
+ response = null;
+ try {
+ response = http(httpServletServerFactory.get(5678), "http://localhost:5678/swagger.json");
+ } catch (IOException e) {
+ // Expected
+ }
+ assertTrue(response == null);
+
+ assertTrue(httpServletServerFactory.get(5678).isAlive());
+ assertTrue(httpServletServerFactory.inventory().size() == 1);
+
+ httpServletServerFactory.destroy(5678);
+ assertTrue(httpServletServerFactory.inventory().size() == 0);
+ }
+
+ @Test
+ public void testMultipleServers() throws Exception {
+ logger.info("-- testMultipleServers() --");
+
+ HttpServletServer server1 = httpServletServerFactory.build("echo-1", "localhost", 5688, "/", true, true);
+ server1.addServletPackage("/*", this.getClass().getPackage().getName());
+ server1.waitedStart(5000);
+
+ HttpServletServer server2 = httpServletServerFactory.build("echo-2", "localhost", 5689, "/", false, true);
+ server2.addServletPackage("/*", this.getClass().getPackage().getName());
+ server2.waitedStart(5000);
+
+ assertTrue(httpServletServerFactory.get(5688).isAlive());
+ assertTrue(httpServletServerFactory.get(5689).isAlive());
+
+ String response = http(httpServletServerFactory.get(5688), "http://localhost:5688/junit/echo/hello");
+ assertTrue("hello".equals(response));
+
+ response = http(httpServletServerFactory.get(5688), "http://localhost:5688/swagger.json");
+ assertTrue(response != null);
+
+ response = http(httpServletServerFactory.get(5689), "http://localhost:5689/junit/echo/hello");
+ assertTrue("hello".equals(response));
+
+ response = null;
+ try {
+ response = http(httpServletServerFactory.get(5689), "http://localhost:5689/swagger.json");
+ } catch (IOException e) {
+ // Expected
+ }
+ assertTrue(response == null);
+
+ httpServletServerFactory.destroy();
+ assertTrue(httpServletServerFactory.inventory().size() == 0);
+ }
+
+ @Test
+ public void testMultiServicePackage() throws Exception {
+ logger.info("-- testMultiServicePackage() --");
+
+ String randomName = UUID.randomUUID().toString();
+
+ HttpServletServer server = httpServletServerFactory.build(randomName, "localhost", 5668, "/", false, true);
+ server.addServletPackage("/*", this.getClass().getPackage().getName());
+ server.waitedStart(5000);
+
+ assertTrue(httpServletServerFactory.get(5668).isAlive());
+
+ String response = http(httpServletServerFactory.get(5668), "http://localhost:5668/junit/echo/hello");
+ assertTrue("hello".equals(response));
+
+ response = http(httpServletServerFactory.get(5668), "http://localhost:5668/junit/endpoints/http/servers");
+ assertTrue(response.contains(randomName));
+
+ httpServletServerFactory.destroy();
+ assertTrue(httpServletServerFactory.inventory().size() == 0);
+ }
+
+ @Test
+ public void testServiceClass() throws Exception {
+ logger.info("-- testServiceClass() --");
+ String randomName = UUID.randomUUID().toString();
+
+ HttpServletServer server = httpServletServerFactory.build(randomName, "localhost", 5658, "/", false, true);
+ server.addServletClass("/*", RestEchoService.class.getCanonicalName());
+ server.waitedStart(5000);
+
+ assertTrue(httpServletServerFactory.get(5658).isAlive());
+
+ String response = http(httpServletServerFactory.get(5658), "http://localhost:5658/junit/echo/hello");
+ assertTrue("hello".equals(response));
+
+ httpServletServerFactory.destroy();
+ assertTrue(httpServletServerFactory.inventory().size() == 0);
+ }
+
+ @Test
+ public void testMultiServiceClass() throws Exception {
+ logger.info("-- testMultiServiceClass() --");
+
+ String randomName = UUID.randomUUID().toString();
+
+ HttpServletServer server = httpServletServerFactory.build(randomName, "localhost", 5648, "/", false, true);
+ server.addServletClass("/*", RestEchoService.class.getCanonicalName());
+ server.addServletClass("/*", RestEndpoints.class.getCanonicalName());
+ server.waitedStart(5000);
+
+ assertTrue(httpServletServerFactory.get(5648).isAlive());
+
+ String response = http(httpServletServerFactory.get(5648), "http://localhost:5648/junit/echo/hello");
+ assertTrue("hello".equals(response));
+
+ response = http(httpServletServerFactory.get(5648), "http://localhost:5648/junit/endpoints/http/servers");
+ assertTrue(response.contains(randomName));
+
+ httpServletServerFactory.destroy();
+ assertTrue(httpServletServerFactory.inventory().size() == 0);
+ }
+
+ /**
+ * performs an http request
+ *
+ * @throws MalformedURLException
+ * @throws IOException
+ * @throws InterruptedException
+ */
+ protected String http(HttpServletServer server, String aUrl)
+ throws MalformedURLException, IOException, InterruptedException {
+ URL url = new URL(aUrl);
+ String response = null;
+ int numRetries = 1, maxNumberRetries = 5;
+ while (numRetries <= maxNumberRetries) {
+ try {
+ response = response(url);
+ break;
+ } catch (ConnectException e) {
+ logger.warn("http server {} @ {} ({}) - cannot connect yet ..", server, aUrl, numRetries, e);
+ numRetries++;
+ Thread.sleep(10000L);
+ } catch (Exception e) {
+ throw e;
+ }
+ }
+
+ return response;
+ }
+
+ /**
+ * gets http response
+ *
+ * @param url url
+ *
+ * @throws IOException
+ */
+ protected String response(URL url) throws IOException {
+ String response = "";
+ try (BufferedReader ioReader = new BufferedReader(new InputStreamReader(url.openStream()))) {
+ String line;
+ while ((line = ioReader.readLine()) != null) {
+ response += line;
+ }
+ }
+ return response;
+ }
+
+
+
+}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/NoopTopicTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/NoopTopicTest.java
new file mode 100644
index 00000000..1f8f56ec
--- /dev/null
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/NoopTopicTest.java
@@ -0,0 +1,123 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-endpoints
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.endpoints.http.server.test;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+import java.util.Properties;
+
+import org.junit.Test;
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.event.comm.TopicListener;
+import org.onap.policy.common.endpoints.event.comm.TopicSink;
+import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicSinkFactory;
+import org.onap.policy.common.endpoints.event.comm.bus.impl.IndexedNoopTopicSinkFactory;
+import org.onap.policy.common.endpoints.event.comm.impl.ProxyTopicEndpointManager;
+import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * NOOP Endpoint Tests
+ */
+public class NoopTopicTest implements TopicListener {
+
+ /**
+ * Logger
+ */
+ private static Logger logger = LoggerFactory.getLogger(NoopTopicTest.class);
+
+ private final String topicName = "junit-noop";
+ private final String outMessage = "blah";
+ private String inMessage = null;
+
+ @Test
+ public void testNoopEndpoint() {
+ logger.info("-- testNoopEndpoint() --");
+
+ Properties noopSinkProperties = new Properties();
+ noopSinkProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS, topicName);
+
+ List<? extends TopicSink> noopTopics =
+ ProxyTopicEndpointManager.getInstance().addTopicSinks(noopSinkProperties);
+
+ NoopTopicSinkFactory noopTopicSinkFactory = IndexedNoopTopicSinkFactory.getInstance();
+ TopicSink sink = noopTopicSinkFactory.get(topicName);
+
+
+ assertTrue(noopTopics.size() == 1);
+ assertTrue(noopTopics.size() == noopTopicSinkFactory.inventory().size());
+ assertTrue(noopTopics.get(0) == sink);
+ assertTrue(sink == noopTopicSinkFactory.inventory().get(0));
+
+ assertTrue(!sink.isAlive());
+
+ boolean badState = false;
+ try {
+ sink.send(outMessage);
+ } catch (IllegalStateException e) {
+ badState = true;
+ }
+ assertTrue(badState);
+
+ sink.start();
+ assertTrue(sink.isAlive());
+
+ sink.send(outMessage);
+ assertTrue(sink.getRecentEvents().length == 1);
+ assertTrue(sink.getRecentEvents()[0].equals(outMessage));
+ assertTrue(this.inMessage == null);
+
+ sink.register(this);
+ sink.send(this.outMessage);
+ assertTrue(outMessage.equals(this.inMessage));
+ this.inMessage = null;
+
+ sink.unregister(this);
+ sink.send(this.outMessage);
+ assertTrue(!outMessage.equals(this.inMessage));
+
+ sink.stop();
+ try {
+ sink.send(outMessage);
+ } catch (IllegalStateException e) {
+ badState = true;
+ }
+ assertTrue(badState);
+
+ noopTopicSinkFactory.destroy(topicName);
+ assertTrue(noopTopicSinkFactory.inventory().size() == 0);
+ }
+
+ @Override
+ public void onTopicEvent(CommInfrastructure commType, String topic, String event) {
+ if (commType != CommInfrastructure.NOOP) {
+ return;
+ }
+
+ if (topic == null || !topic.equals(topicName)) {
+ return;
+ }
+
+ this.inMessage = event;
+ }
+}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestEchoService.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestEchoService.java
new file mode 100644
index 00000000..139d1842
--- /dev/null
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestEchoService.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-endpoints
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.endpoints.http.server.test;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+
+@Api(value="echo")
+@Path("/junit/echo")
+public class RestEchoService {
+
+ @GET
+ @Path("{word}")
+ @Produces(MediaType.TEXT_PLAIN)
+ @ApiOperation(
+ value="echoes back whatever received"
+ )
+ public String echo(@PathParam("word") String word) {
+ return word;
+ }
+
+}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestEndpoints.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestEndpoints.java
new file mode 100644
index 00000000..4733c119
--- /dev/null
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestEndpoints.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-endpoints
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.endpoints.http.server.test;
+
+import java.util.List;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.endpoints.http.server.impl.IndexedHttpServletServerFactory;
+
+@Path("/junit/endpoints")
+public class RestEndpoints {
+
+ @GET
+ @Path("http/servers")
+ @Produces(MediaType.TEXT_PLAIN)
+ public String httpServers() {
+ List<HttpServletServer> servers = IndexedHttpServletServerFactory.getInstance().inventory();
+ return servers.toString();
+ }
+
+
+}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestMockHealthCheck.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestMockHealthCheck.java
new file mode 100644
index 00000000..573a4498
--- /dev/null
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestMockHealthCheck.java
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-endpoints
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.common.endpoints.http.server.test;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+@Path("/")
+public class RestMockHealthCheck {
+
+ @GET
+ @Path("pap/test")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response papHealthCheck() {
+ return Response.status(Status.OK).entity("All Alive").build();
+ }
+
+ @GET
+ @Path("pdp/test")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response pdpHealthCheck() {
+ return Response.status(Status.INTERNAL_SERVER_ERROR).entity("At least some Dead").build();
+ }
+
+
+}