diff options
Diffstat (limited to 'policy-endpoints/src/test/java')
4 files changed, 77 insertions, 87 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 index d4840e68..08399e91 100644 --- 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 @@ -32,9 +32,7 @@ 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; @@ -51,7 +49,7 @@ public class HttpClientTest { /* echo server */ final HttpServletServer echoServerNoAuth = - IndexedHttpServletServerFactory.getInstance().build("echo", "localhost", 6666, "/", false, true); + HttpServletServer.factory.build("echo", "localhost", 6666, "/", false, true); echoServerNoAuth.addServletPackage("/*", HttpClientTest.class.getPackage().getName()); echoServerNoAuth.waitedStart(5000); @@ -62,7 +60,7 @@ public class HttpClientTest { /* no auth echo server */ final HttpServletServer echoServerAuth = - IndexedHttpServletServerFactory.getInstance().build("echo", "localhost", 6667, "/", false, true); + HttpServletServer.factory.build("echo", "localhost", 6667, "/", false, true); echoServerAuth.setBasicAuthentication("x", "y", null); echoServerAuth.addServletPackage("/*", HttpClientTest.class.getPackage().getName()); echoServerAuth.waitedStart(5000); @@ -76,16 +74,16 @@ public class HttpClientTest { public static void tearDown() { logger.info("-- tearDown() --"); - IndexedHttpServletServerFactory.getInstance().destroy(); - IndexedHttpClientFactory.getInstance().destroy(); + HttpServletServer.factory.destroy(); + HttpClient.factory.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 HttpClient client = HttpClient.factory.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); @@ -97,8 +95,8 @@ public class HttpClientTest { 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 HttpClient client = HttpClient.factory.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); @@ -110,8 +108,8 @@ public class HttpClientTest { 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 HttpClient client = HttpClient.factory.build("testHttpAuthClient401", false, false, "localhost", 6667, + "junit/echo", null, null, true); final Response response = client.get("hello"); assertTrue(response.getStatus() == 401); } @@ -131,11 +129,12 @@ public class HttpClientTest { + 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"); + 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"); @@ -145,11 +144,12 @@ public class HttpClientTest { + 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"); + 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" @@ -164,9 +164,8 @@ public class HttpClientTest { + 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 + "." + "PAP" + + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true"); httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP" + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, "localhost"); @@ -180,25 +179,24 @@ public class HttpClientTest { + 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"); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP" + + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true"); - final List<HttpServletServer> servers = IndexedHttpServletServerFactory.getInstance().build(httpProperties); + final List<HttpServletServer> servers = HttpServletServer.factory.build(httpProperties); assertTrue(servers.size() == 2); - final List<HttpClient> clients = IndexedHttpClientFactory.getInstance().build(httpProperties); + final List<HttpClient> clients = HttpClient.factory.build(httpProperties); assertTrue(clients.size() == 2); for (final HttpServletServer server : servers) { server.waitedStart(10000); } - final HttpClient clientPAP = IndexedHttpClientFactory.getInstance().get("PAP"); + final HttpClient clientPAP = HttpClient.factory.get("PAP"); final Response response = clientPAP.get(); assertTrue(response.getStatus() == 200); - final HttpClient clientPDP = IndexedHttpClientFactory.getInstance().get("PDP"); + final HttpClient clientPDP = HttpClient.factory.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 index eba96208..b6f0c0e8 100644 --- 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 @@ -32,8 +32,6 @@ 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; @@ -42,8 +40,6 @@ import org.slf4j.LoggerFactory; */ public class HttpServerTest { - HttpServletServerFactory httpServletServerFactory = IndexedHttpServletServerFactory.getInstance(); - /** * Logger */ @@ -53,64 +49,64 @@ public class HttpServerTest { public void testSingleServer() throws Exception { logger.info("-- testSingleServer() --"); - HttpServletServer server = httpServletServerFactory.build("echo", "localhost", 5678, "/", false, true); + HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", 5678, "/", false, true); server.addServletPackage("/*", this.getClass().getPackage().getName()); server.waitedStart(5000); - assertTrue(httpServletServerFactory.get(5678).isAlive()); + assertTrue(HttpServletServer.factory.get(5678).isAlive()); - String response = http(httpServletServerFactory.get(5678), "http://localhost:5678/junit/echo/hello"); + String response = http(HttpServletServer.factory.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"); + response = http(HttpServletServer.factory.get(5678), "http://localhost:5678/swagger.json"); } catch (IOException e) { // Expected } assertTrue(response == null); - assertTrue(httpServletServerFactory.get(5678).isAlive()); - assertTrue(httpServletServerFactory.inventory().size() == 1); + assertTrue(HttpServletServer.factory.get(5678).isAlive()); + assertTrue(HttpServletServer.factory.inventory().size() == 1); - httpServletServerFactory.destroy(5678); - assertTrue(httpServletServerFactory.inventory().size() == 0); + HttpServletServer.factory.destroy(5678); + assertTrue(HttpServletServer.factory.inventory().size() == 0); } @Test public void testMultipleServers() throws Exception { logger.info("-- testMultipleServers() --"); - HttpServletServer server1 = httpServletServerFactory.build("echo-1", "localhost", 5688, "/", true, true); + HttpServletServer server1 = HttpServletServer.factory.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); + HttpServletServer server2 = HttpServletServer.factory.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()); + assertTrue(HttpServletServer.factory.get(5688).isAlive()); + assertTrue(HttpServletServer.factory.get(5689).isAlive()); - String response = http(httpServletServerFactory.get(5688), "http://localhost:5688/junit/echo/hello"); + String response = http(HttpServletServer.factory.get(5688), "http://localhost:5688/junit/echo/hello"); assertTrue("hello".equals(response)); - response = http(httpServletServerFactory.get(5688), "http://localhost:5688/swagger.json"); + response = http(HttpServletServer.factory.get(5688), "http://localhost:5688/swagger.json"); assertTrue(response != null); - response = http(httpServletServerFactory.get(5689), "http://localhost:5689/junit/echo/hello"); + response = http(HttpServletServer.factory.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"); + response = http(HttpServletServer.factory.get(5689), "http://localhost:5689/swagger.json"); } catch (IOException e) { // Expected } assertTrue(response == null); - httpServletServerFactory.destroy(); - assertTrue(httpServletServerFactory.inventory().size() == 0); + HttpServletServer.factory.destroy(); + assertTrue(HttpServletServer.factory.inventory().size() == 0); } @Test @@ -119,20 +115,20 @@ public class HttpServerTest { String randomName = UUID.randomUUID().toString(); - HttpServletServer server = httpServletServerFactory.build(randomName, "localhost", 5668, "/", false, true); + HttpServletServer server = HttpServletServer.factory.build(randomName, "localhost", 5668, "/", false, true); server.addServletPackage("/*", this.getClass().getPackage().getName()); server.waitedStart(5000); - assertTrue(httpServletServerFactory.get(5668).isAlive()); + assertTrue(HttpServletServer.factory.get(5668).isAlive()); - String response = http(httpServletServerFactory.get(5668), "http://localhost:5668/junit/echo/hello"); + String response = http(HttpServletServer.factory.get(5668), "http://localhost:5668/junit/echo/hello"); assertTrue("hello".equals(response)); - response = http(httpServletServerFactory.get(5668), "http://localhost:5668/junit/endpoints/http/servers"); + response = http(HttpServletServer.factory.get(5668), "http://localhost:5668/junit/endpoints/http/servers"); assertTrue(response.contains(randomName)); - httpServletServerFactory.destroy(); - assertTrue(httpServletServerFactory.inventory().size() == 0); + HttpServletServer.factory.destroy(); + assertTrue(HttpServletServer.factory.inventory().size() == 0); } @Test @@ -140,17 +136,17 @@ public class HttpServerTest { logger.info("-- testServiceClass() --"); String randomName = UUID.randomUUID().toString(); - HttpServletServer server = httpServletServerFactory.build(randomName, "localhost", 5658, "/", false, true); + HttpServletServer server = HttpServletServer.factory.build(randomName, "localhost", 5658, "/", false, true); server.addServletClass("/*", RestEchoService.class.getCanonicalName()); server.waitedStart(5000); - assertTrue(httpServletServerFactory.get(5658).isAlive()); + assertTrue(HttpServletServer.factory.get(5658).isAlive()); - String response = http(httpServletServerFactory.get(5658), "http://localhost:5658/junit/echo/hello"); + String response = http(HttpServletServer.factory.get(5658), "http://localhost:5658/junit/echo/hello"); assertTrue("hello".equals(response)); - httpServletServerFactory.destroy(); - assertTrue(httpServletServerFactory.inventory().size() == 0); + HttpServletServer.factory.destroy(); + assertTrue(HttpServletServer.factory.inventory().size() == 0); } @Test @@ -159,21 +155,21 @@ public class HttpServerTest { String randomName = UUID.randomUUID().toString(); - HttpServletServer server = httpServletServerFactory.build(randomName, "localhost", 5648, "/", false, true); + HttpServletServer server = HttpServletServer.factory.build(randomName, "localhost", 5648, "/", false, true); server.addServletClass("/*", RestEchoService.class.getCanonicalName()); server.addServletClass("/*", RestEndpoints.class.getCanonicalName()); server.waitedStart(5000); - assertTrue(httpServletServerFactory.get(5648).isAlive()); + assertTrue(HttpServletServer.factory.get(5648).isAlive()); - String response = http(httpServletServerFactory.get(5648), "http://localhost:5648/junit/echo/hello"); + String response = http(HttpServletServer.factory.get(5648), "http://localhost:5648/junit/echo/hello"); assertTrue("hello".equals(response)); - response = http(httpServletServerFactory.get(5648), "http://localhost:5648/junit/endpoints/http/servers"); + response = http(HttpServletServer.factory.get(5648), "http://localhost:5648/junit/endpoints/http/servers"); assertTrue(response.contains(randomName)); - httpServletServerFactory.destroy(); - assertTrue(httpServletServerFactory.inventory().size() == 0); + HttpServletServer.factory.destroy(); + assertTrue(HttpServletServer.factory.inventory().size() == 0); } /** 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 index 1f8f56ec..849065c1 100644 --- 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 @@ -27,11 +27,10 @@ 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.TopicEndpoint; 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.event.comm.bus.NoopTopicSink; import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,17 +56,14 @@ public class NoopTopicTest implements TopicListener { 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); + List<? extends TopicSink> noopTopics = TopicEndpoint.manager.addTopicSinks(noopSinkProperties); + TopicSink sink = NoopTopicSink.factory.get(topicName); assertTrue(noopTopics.size() == 1); - assertTrue(noopTopics.size() == noopTopicSinkFactory.inventory().size()); + assertTrue(noopTopics.size() == NoopTopicSink.factory.inventory().size()); assertTrue(noopTopics.get(0) == sink); - assertTrue(sink == noopTopicSinkFactory.inventory().get(0)); + assertTrue(sink == NoopTopicSink.factory.inventory().get(0)); assertTrue(!sink.isAlive()); @@ -104,8 +100,8 @@ public class NoopTopicTest implements TopicListener { } assertTrue(badState); - noopTopicSinkFactory.destroy(topicName); - assertTrue(noopTopicSinkFactory.inventory().size() == 0); + NoopTopicSink.factory.destroy(topicName); + assertTrue(NoopTopicSink.factory.inventory().size() == 0); } @Override 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 index 4733c119..9800a9d4 100644 --- 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 @@ -28,7 +28,6 @@ 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 { @@ -36,10 +35,11 @@ public class RestEndpoints { @GET @Path("http/servers") @Produces(MediaType.TEXT_PLAIN) - public String httpServers() { - List<HttpServletServer> servers = IndexedHttpServletServerFactory.getInstance().inventory(); - return servers.toString(); + public String httpServers() { + List<HttpServletServer> servers = + HttpServletServer.factory.inventory(); + return servers.toString(); } - - + + } |