diff options
author | Jorge Hernandez <jh1730@att.com> | 2017-07-20 13:58:25 -0500 |
---|---|---|
committer | Jorge Hernandez <jh1730@att.com> | 2017-07-20 14:53:08 -0500 |
commit | 76ec9035351877aa5993bbefef63fcc73941d2f2 (patch) | |
tree | 006b45cb59f24c810e1d3b0add6161a18c82c15f /policy-endpoints/src | |
parent | e10845684c65f2a1e99d31615df141cd318562bc (diff) |
[POLICY-52] enabled properties http junit test
will also take care of some race conditions seen in gerrit
triggered jenkin jobs as it brings up / tears down
http servers per junit test method.
Change-Id: I0b18073ebfaab3a6f0d08efee1edacd8d5d9e3ca
Signed-off-by: Jorge Hernandez <jh1730@att.com>
Diffstat (limited to 'policy-endpoints/src')
3 files changed, 44 insertions, 57 deletions
diff --git a/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpClientTest.java b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpClientTest.java index df57fcfc..a7d309a1 100644 --- a/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpClientTest.java +++ b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpClientTest.java @@ -27,6 +27,8 @@ import java.util.Properties; import javax.ws.rs.core.Response; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; import org.openecomp.policy.drools.http.client.HttpClient; import org.openecomp.policy.drools.http.server.HttpServletServer; @@ -38,14 +40,36 @@ public class HttpClientTest { private static Logger logger = LoggerFactory.getLogger(HttpClientTest.class); + @BeforeClass + public static void setUp() { + logger.info("-- setup() --"); + + /* echo server */ + + HttpServletServer echoServerNoAuth = HttpServletServer.factory.build("echo", "localhost", 6666, "/", false, true); + echoServerNoAuth.addServletPackage("/*", HttpClientTest.class.getPackage().getName()); + echoServerNoAuth.waitedStart(5000); + + /* no auth echo server */ + + HttpServletServer echoServerAuth = HttpServletServer.factory.build("echo", "localhost", 6667, "/", false, true); + echoServerAuth.setBasicAuthentication("x", "y", null); + echoServerAuth.addServletPackage("/*", HttpClientTest.class.getPackage().getName()); + echoServerAuth.waitedStart(5000); + } + + @AfterClass + public static void tearDown() { + logger.info("-- tearDown() --"); + + HttpServletServer.factory.destroy(); + HttpClient.factory.destroy(); + } + @Test public void testHttpNoAuthClient() throws Exception { logger.info("-- testHttpNoAuthClient() --"); - HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", 6666, "/", false, true); - server.addServletPackage("/*", this.getClass().getPackage().getName()); - server.waitedStart(5000); - HttpClient client = HttpClient.factory.build("testHttpNoAuthClient", false, false, "localhost", 6666, "junit/echo", null, null, true); @@ -54,71 +78,34 @@ public class HttpClientTest { assertTrue(response.getStatus() == 200); assertTrue(body.equals("hello")); - - HttpServletServer.factory.destroy(); - HttpClient.factory.destroy(); } @Test public void testHttpAuthClient() throws Exception { logger.info("-- testHttpAuthClient() --"); - - HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", 6666, "/", false, true); - server.setBasicAuthentication("x", "y", null); - server.addServletPackage("/*", this.getClass().getPackage().getName()); - server.waitedStart(5000); HttpClient client = HttpClient.factory.build("testHttpAuthClient",false, false, - "localhost", 6666, "junit/echo", + "localhost", 6667, "junit/echo", "x", "y", true); Response response = client.get("hello"); String body = HttpClient.getBody(response, String.class); assertTrue(response.getStatus() == 200); assertTrue(body.equals("hello")); - - HttpServletServer.factory.destroy(); - HttpClient.factory.destroy(); } @Test public void testHttpAuthClient401() throws Exception { logger.info("-- testHttpAuthClient401() --"); - - HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", 6666, "/", false, true); - server.setBasicAuthentication("x", "y", null); - server.addServletPackage("/*", this.getClass().getPackage().getName()); - server.waitedStart(5000); HttpClient client = HttpClient.factory.build("testHttpAuthClient401",false, false, - "localhost", 6666, "junit/echo", + "localhost", 6667, "junit/echo", null, null, true); Response response = client.get("hello"); assertTrue(response.getStatus() == 401); - - HttpServletServer.factory.destroy(); - HttpClient.factory.destroy(); } - - //@Test - public void testHttpAuthClientHttps() throws Exception { - logger.info("-- testHttpAuthClientHttps() --"); - - HttpClient client = HttpClient.factory.build("testHttpAuthClientHttps", true, true, "somehost.somewhere.com", - 9091, "pap/test", "testpap", "alpha123", true); - Response response = client.get(); - assertTrue(response.getStatus() == 200); - - HttpClient client2 = HttpClient.factory.build("testHttpAuthClientHttps2", true, true, "somehost.somewhere.com", - 8081, "pdp", "testpdp", "alpha123", true); - Response response2 = client2.get("test"); - assertTrue(response2.getStatus() == 500); - - HttpServletServer.factory.destroy(); - HttpClient.factory.destroy(); - } - //@Test + @Test public void testHttpAuthClientProps() throws Exception { logger.info("-- testHttpAuthClientProps() --"); @@ -130,7 +117,7 @@ public class HttpClientTest { "localhost"); httpProperties.setProperty (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_HTTP_PORT_SUFFIX, - "9091"); + "7777"); httpProperties.setProperty (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, "testpap"); @@ -139,7 +126,7 @@ public class HttpClientTest { "alpha123"); httpProperties.setProperty (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX, - "org.openecomp.policy.drools.http.server.test.RestMockHealthCheck"); + RestMockHealthCheck.class.getName()); httpProperties.setProperty (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_MANAGED_SUFFIX, "true"); @@ -149,7 +136,7 @@ public class HttpClientTest { "localhost"); httpProperties.setProperty (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PDP" + PolicyProperties.PROPERTY_HTTP_PORT_SUFFIX, - "8081"); + "7778"); httpProperties.setProperty (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PDP" + PolicyProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, "testpdp"); @@ -158,7 +145,7 @@ public class HttpClientTest { "alpha123"); httpProperties.setProperty (PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PDP" + PolicyProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX, - "org.openecomp.policy.drools.http.server.test.RestMockHealthCheck"); + RestMockHealthCheck.class.getName()); httpProperties.setProperty (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_MANAGED_SUFFIX, "true"); @@ -169,7 +156,7 @@ public class HttpClientTest { "localhost"); httpProperties.setProperty (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_HTTP_PORT_SUFFIX, - "9091"); + "7777"); httpProperties.setProperty (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PAP" + PolicyProperties.PROPERTY_HTTP_URL_SUFFIX, "pap/test"); @@ -191,7 +178,7 @@ public class HttpClientTest { "localhost"); httpProperties.setProperty (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP" + PolicyProperties.PROPERTY_HTTP_PORT_SUFFIX, - "8081"); + "7778"); httpProperties.setProperty (PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "PDP" + PolicyProperties.PROPERTY_HTTP_URL_SUFFIX, "pdp"); @@ -224,10 +211,7 @@ public class HttpClientTest { HttpClient clientPDP = HttpClient.factory.get("PDP"); Response response2 = clientPDP.get("test"); - assertTrue(response2.getStatus() == 500); - - HttpServletServer.factory.destroy(); - HttpClient.factory.destroy(); + assertTrue(response2.getStatus() == 500); } diff --git a/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpServerTest.java b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpServerTest.java index 931d968b..02047008 100644 --- a/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpServerTest.java +++ b/policy-endpoints/src/test/java/org/openecomp/policy/drools/http/server/test/HttpServerTest.java @@ -62,9 +62,12 @@ public class HttpServerTest { // Expected } - assertTrue(responseSwagger == null); + assertTrue(responseSwagger == null); - HttpServletServer.factory.destroy(); + assertTrue(HttpServletServer.factory.get(5678).isAlive()); + assertTrue(HttpServletServer.factory.inventory().size() == 1); + + HttpServletServer.factory.destroy(5678); assertTrue(HttpServletServer.factory.inventory().size() == 0); } diff --git a/policy-endpoints/src/test/resources/logback-test.xml b/policy-endpoints/src/test/resources/logback-test.xml index 9e0dd9ba..bc813ef7 100644 --- a/policy-endpoints/src/test/resources/logback-test.xml +++ b/policy-endpoints/src/test/resources/logback-test.xml @@ -8,7 +8,7 @@ </encoder> </appender> - <root level="warn"> + <root level="info"> <appender-ref ref="STDOUT"/> </root> |