From ea262e6da52fd4da0733f02998f87aebaf502ddb Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 12 Jun 2019 14:32:25 -0400 Subject: Apply simple sonar fixes Note: A number of these were identified, by SonarLint, in the Test classes, which are not typically scanned by Sonar. Removed unnecessary imports. Removed unneeded "throws Xxx". Replaced lambda with method references. Replaced duplicate strings with constants. Replaced try-fail-catch with assert-j methods to eliminate sonar complaints about duplicate failure messages. Added missing @Override annotations. Use map.computeIfAbsent() where appropriate. Also fixed some minor checkstyle issues. Removed unneeded "volatile" declarations. Replaced some if-else constructs with "?:" construct, per sonar. Replaced Object.wait() with CountDownLatch.await(); according to sonar (and javadocs), Object.wait() can return due to "spurious wakeups". Fixed issue whereby CryptoUtilsTest wouldn't run in my Eclipse. Change-Id: Ib6b71ed65662cfd6209400dac57ed69279bf29ec Issue-ID: POLICY-1791 Signed-off-by: Jim Hahn --- .../event/comm/bus/BusTopicFactoryTestBase.java | 6 +- .../event/comm/bus/DmaapTopicSinkFactoryTest.java | 8 +- .../comm/bus/DmaapTopicSourceFactoryTest.java | 10 +- .../event/comm/bus/internal/BusConsumerTest.java | 11 +- .../event/comm/bus/internal/BusPublisherTest.java | 9 +- .../event/comm/bus/internal/BusTopicBaseTest.java | 1 + .../comm/bus/internal/BusTopicParamsTest.java | 3 +- .../comm/bus/internal/InlineBusTopicSinkTest.java | 1 + .../bus/internal/InlineDmaapTopicSinkTest.java | 1 + .../comm/bus/internal/InlineUebTopicSinkTest.java | 1 + .../endpoints/http/server/test/HttpClientTest.java | 260 +++++++++++---------- .../endpoints/http/server/test/HttpServerTest.java | 104 +++++---- 12 files changed, 229 insertions(+), 186 deletions(-) (limited to 'policy-endpoints/src/test') diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/BusTopicFactoryTestBase.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/BusTopicFactoryTestBase.java index 919397d9..b5c9e614 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/BusTopicFactoryTestBase.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/BusTopicFactoryTestBase.java @@ -34,7 +34,7 @@ import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperti import java.util.Arrays; import java.util.List; import java.util.Properties; -import java.util.function.Function; +import java.util.function.Predicate; import org.onap.policy.common.endpoints.event.comm.Topic; import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; @@ -192,7 +192,7 @@ public abstract class BusTopicFactoryTestBase extends TopicFact * @param values the values to which the property should be set, defaults to * {@code null} and "" */ - protected void checkDefault(String builderName, Function validate, Object... values) { + protected void checkDefault(String builderName, Predicate validate, Object... values) { Object[] values2 = (values.length > 0 ? values : new Object[] {null, ""}); for (Object value : values2) { @@ -209,7 +209,7 @@ public abstract class BusTopicFactoryTestBase extends TopicFact } assertEquals("size for default " + value, 1, buildTopics(builder.build()).size()); - assertTrue("default for " + value, validate.apply(getLastParams())); + assertTrue("default for " + value, validate.test(getLastParams())); } } diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSinkFactoryTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSinkFactoryTest.java index b4c7fff8..6c9dfcbd 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSinkFactoryTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSinkFactoryTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-endpoints * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019 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. @@ -41,6 +41,7 @@ public class DmaapTopicSinkFactoryTest extends DmaapTopicFactoryTestBase params2.getFetchLimit() == DmaapTopicSource.DEFAULT_LIMIT_FETCH, null, "", "invalid-limit-number"); - + checkDefault(PROPERTY_TOPIC_SOURCE_FETCH_TIMEOUT_SUFFIX, params2 -> params2.getFetchTimeout() == DmaapTopicSource.DEFAULT_TIMEOUT_MS_FETCH, null, "", "invalid-timeout-number"); @@ -99,6 +102,7 @@ public class DmaapTopicSourceFactoryTest extends DmaapTopicFactoryTestBase savedValuesMap = new HashMap<>(); /** @@ -60,11 +74,11 @@ public class HttpClientTest { /* echo server - http + no auth */ final HttpServletServer echoServerNoAuth = - HttpServletServer.factory.build("echo", "localhost", 6666, "/", false, true); + HttpServletServer.factory.build("echo", LOCALHOST, 6666, "/", false, true); echoServerNoAuth.addServletPackage("/*", HttpClientTest.class.getPackage().getName()); echoServerNoAuth.waitedStart(5000); - if (!NetworkUtil.isTcpPortOpen("localhost", echoServerNoAuth.getPort(), 5, 10000L)) { + if (!NetworkUtil.isTcpPortOpen(LOCALHOST, echoServerNoAuth.getPort(), 5, 10000L)) { throw new IllegalStateException("cannot connect to port " + echoServerNoAuth.getPort()); } @@ -101,7 +115,7 @@ public class HttpClientTest { /* echo server - https + basic auth */ final HttpServletServer echoServerAuth = - HttpServletServer.factory.build("echo", true, "localhost", 6667, "/", false, true); + HttpServletServer.factory.build("echo", true, LOCALHOST, 6667, "/", false, true); echoServerAuth.setBasicAuthentication("x", "y", null); echoServerAuth.addServletPackage("/*", HttpClientTest.class.getPackage().getName()); echoServerAuth.addFilterClass("/*", TestFilter.class.getCanonicalName()); @@ -110,7 +124,7 @@ public class HttpClientTest { echoServerAuth.addFilterClass("/*", TestAafGranularAuthFilter.class.getCanonicalName()); echoServerAuth.waitedStart(5000); - if (!NetworkUtil.isTcpPortOpen("localhost", echoServerAuth.getPort(), 5, 10000L)) { + if (!NetworkUtil.isTcpPortOpen(LOCALHOST, echoServerAuth.getPort(), 5, 10000L)) { throw new IllegalStateException("cannot connect to port " + echoServerAuth.getPort()); } } @@ -171,34 +185,34 @@ public class HttpClientTest { @Test public void testHttpGetNoAuthClient() throws Exception { - final HttpClient client = getNoAuthHttpClient("testHttpNoAuthClient", false, + final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false, 6666); - final Response response = client.get("hello"); + final Response response = client.get(HELLO); final String body = HttpClient.getBody(response, String.class); assertEquals(200, response.getStatus()); - assertEquals("hello", body); + assertEquals(HELLO, body); } @Test public void testHttpPutNoAuthClient() throws Exception { - final HttpClient client = getNoAuthHttpClient("testHttpNoAuthClient", false, 6666); + final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false, 6666); - Entity entity = Entity.entity(new MyEntity("myValue"), MediaType.APPLICATION_JSON); - final Response response = client.put("hello", entity, Collections.emptyMap()); + Entity entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON); + final Response response = client.put(HELLO, entity, Collections.emptyMap()); final String body = HttpClient.getBody(response, String.class); assertEquals(200, response.getStatus()); - assertEquals("PUT:hello:{myParameter=myValue}", body); + assertEquals(PUT_HELLO, body); } @Test public void testHttpPostNoAuthClient() throws Exception { - final HttpClient client = getNoAuthHttpClient("testHttpNoAuthClient", false, + final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false, 6666); - Entity entity = Entity.entity(new MyEntity("myValue"), MediaType.APPLICATION_JSON); - final Response response = client.post("hello", entity, Collections.emptyMap()); + Entity entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON); + final Response response = client.post(HELLO, entity, Collections.emptyMap()); final String body = HttpClient.getBody(response, String.class); assertEquals(200, response.getStatus()); @@ -207,10 +221,10 @@ public class HttpClientTest { @Test public void testHttpDeletetNoAuthClient() throws Exception { - final HttpClient client = getNoAuthHttpClient("testHttpNoAuthClient", false, + final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false, 6666); - final Response response = client.delete("hello", Collections.emptyMap()); + final Response response = client.delete(HELLO, Collections.emptyMap()); final String body = HttpClient.getBody(response, String.class); assertEquals(200, response.getStatus()); @@ -221,38 +235,38 @@ public class HttpClientTest { public void testHttpGetAuthClient() throws Exception { final HttpClient client = getAuthHttpClient(); - final Response response = client.get("hello"); + final Response response = client.get(HELLO); final String body = HttpClient.getBody(response, String.class); assertEquals(200, response.getStatus()); - assertEquals("hello", body); + assertEquals(HELLO, body); } @Test public void testHttpPutAuthClient() throws Exception { final HttpClient client = getAuthHttpClient(); - Entity entity = Entity.entity(new MyEntity("myValue"), MediaType.APPLICATION_JSON); - final Response response = client.put("hello", entity, Collections.emptyMap()); + Entity entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON); + final Response response = client.put(HELLO, entity, Collections.emptyMap()); final String body = HttpClient.getBody(response, String.class); assertEquals(200, response.getStatus()); - assertEquals("PUT:hello:{myParameter=myValue}", body); + assertEquals(PUT_HELLO, body); } @Test public void testHttpPutAuthClient_JacksonProvider() throws Exception { - final HttpClient client = HttpClient.factory.build(BusTopicParams.builder().clientName("testHttpAuthClient") - .useHttps(true).allowSelfSignedCerts(true).hostname("localhost").port(6667) - .basePath("junit/echo").userName("x").password("y").managed(true) + final HttpClient client = HttpClient.factory.build(BusTopicParams.builder().clientName(TEST_HTTP_AUTH_CLIENT) + .useHttps(true).allowSelfSignedCerts(true).hostname(LOCALHOST).port(6667) + .basePath(JUNIT_ECHO).userName("x").password("y").managed(true) .serializationProvider(MyJacksonProvider.class.getCanonicalName()).build()); - Entity entity = Entity.entity(new MyEntity("myValue"), MediaType.APPLICATION_JSON); - final Response response = client.put("hello", entity, Collections.emptyMap()); + Entity entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON); + final Response response = client.put(HELLO, entity, Collections.emptyMap()); final String body = HttpClient.getBody(response, String.class); assertEquals(200, response.getStatus()); - assertEquals("PUT:hello:{myParameter=myValue}", body); + assertEquals(PUT_HELLO, body); assertTrue(MyJacksonProvider.hasWrittenSome()); @@ -261,17 +275,17 @@ public class HttpClientTest { @Test public void testHttpPutAuthClient_GsonProvider() throws Exception { - final HttpClient client = HttpClient.factory.build(BusTopicParams.builder().clientName("testHttpAuthClient") - .useHttps(true).allowSelfSignedCerts(true).hostname("localhost").port(6667) - .basePath("junit/echo").userName("x").password("y").managed(true) + final HttpClient client = HttpClient.factory.build(BusTopicParams.builder().clientName(TEST_HTTP_AUTH_CLIENT) + .useHttps(true).allowSelfSignedCerts(true).hostname(LOCALHOST).port(6667) + .basePath(JUNIT_ECHO).userName("x").password("y").managed(true) .serializationProvider(MyGsonProvider.class.getCanonicalName()).build()); - Entity entity = Entity.entity(new MyEntity("myValue"), MediaType.APPLICATION_JSON); - final Response response = client.put("hello", entity, Collections.emptyMap()); + Entity entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON); + final Response response = client.put(HELLO, entity, Collections.emptyMap()); final String body = HttpClient.getBody(response, String.class); assertEquals(200, response.getStatus()); - assertEquals("PUT:hello:{myParameter=myValue}", body); + assertEquals(PUT_HELLO, body); assertTrue(MyGsonProvider.hasWrittenSome()); @@ -282,7 +296,7 @@ public class HttpClientTest { public void testHttpAuthClient401() throws Exception { final HttpClient client = getNoAuthHttpClient("testHttpAuthClient401", true, 6667); - final Response response = client.get("hello"); + final Response response = client.get(HELLO); assertEquals(401, response.getStatus()); } @@ -291,70 +305,70 @@ public class HttpClientTest { 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 + DOT_PAP + + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, LOCALHOST); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_PAP + + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "7777"); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_PAP + + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, "testpap"); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_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()); + PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_PAP + + PolicyEndPointProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX, + RestMockHealthCheck.class.getName()); httpProperties.setProperty( - PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "." + "PAP" - + PolicyEndPointProperties.PROPERTY_HTTP_FILTER_CLASSES_SUFFIX, - TestFilter.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"); + PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_PAP + + PolicyEndPointProperties.PROPERTY_HTTP_FILTER_CLASSES_SUFFIX, + TestFilter.class.getName()); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PAP + + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true"); + + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_PDP + + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, LOCALHOST); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_PDP + + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "7778"); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_PDP + + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, "testpdp"); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_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 + DOT_PDP + + PolicyEndPointProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX, + RestMockHealthCheck.class.getName()); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_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"); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PAP + + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, LOCALHOST); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PAP + + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "7777"); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PAP + + PolicyEndPointProperties.PROPERTY_HTTP_URL_SUFFIX, "pap/test"); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PAP + + PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX, FALSE_STRING); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PAP + + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, "testpap"); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PAP + + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX, ALPHA123); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PAP + + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true"); + + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PDP + + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, LOCALHOST); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PDP + + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "7778"); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PDP + + PolicyEndPointProperties.PROPERTY_HTTP_URL_SUFFIX, "pdp"); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PDP + + PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX, FALSE_STRING); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PDP + + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, "testpdp"); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PDP + + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX, ALPHA123); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PDP + + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true"); final List servers = HttpServletServer.factory.build(httpProperties); assertEquals(2, servers.size()); @@ -383,51 +397,51 @@ public class HttpClientTest { final Properties httpProperties = new Properties(); httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES, "GSON,JACKSON"); - httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "GSON" - + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, "localhost"); - httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "GSON" - + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "6666"); - httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "GSON" - + PolicyEndPointProperties.PROPERTY_HTTP_URL_SUFFIX, "junit/echo"); - httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "GSON" - + PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX, "false"); - httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "GSON" - + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true"); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_GSON + + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, LOCALHOST); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_GSON + + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "6666"); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_GSON + + PolicyEndPointProperties.PROPERTY_HTTP_URL_SUFFIX, JUNIT_ECHO); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_GSON + + PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX, FALSE_STRING); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_GSON + + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true"); httpProperties.setProperty( - PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "GSON" + PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_GSON + PolicyEndPointProperties.PROPERTY_HTTP_SERIALIZATION_PROVIDER, MyGsonProvider.class.getCanonicalName()); - httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "JACKSON" - + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, "localhost"); - httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "JACKSON" - + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "6666"); - httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "JACKSON" - + PolicyEndPointProperties.PROPERTY_HTTP_URL_SUFFIX, "junit/echo"); - httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "JACKSON" - + PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX, "false"); - httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "JACKSON" - + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true"); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_JACKSON + + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, LOCALHOST); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_JACKSON + + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "6666"); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_JACKSON + + PolicyEndPointProperties.PROPERTY_HTTP_URL_SUFFIX, JUNIT_ECHO); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_JACKSON + + PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX, FALSE_STRING); + httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_JACKSON + + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true"); httpProperties.setProperty( - PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + "." + "JACKSON" + PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_JACKSON + PolicyEndPointProperties.PROPERTY_HTTP_SERIALIZATION_PROVIDER, MyJacksonProvider.class.getCanonicalName()); final List clients = HttpClient.factory.build(httpProperties); assertEquals(2, clients.size()); - Entity entity = Entity.entity(new MyEntity("myValue"), MediaType.APPLICATION_JSON); + Entity entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON); // use gson client MyGsonProvider.resetSome(); MyJacksonProvider.resetSome(); HttpClient client = HttpClient.factory.get("GSON"); - Response response = client.put("hello", entity, Collections.emptyMap()); + Response response = client.put(HELLO, entity, Collections.emptyMap()); String body = HttpClient.getBody(response, String.class); assertEquals(200, response.getStatus()); - assertEquals("PUT:hello:{myParameter=myValue}", body); + assertEquals(PUT_HELLO, body); assertTrue(MyGsonProvider.hasWrittenSome()); assertFalse(MyJacksonProvider.hasWrittenSome()); @@ -437,11 +451,11 @@ public class HttpClientTest { MyJacksonProvider.resetSome(); client = HttpClient.factory.get("JACKSON"); - response = client.put("hello", entity, Collections.emptyMap()); + response = client.put(HELLO, entity, Collections.emptyMap()); body = HttpClient.getBody(response, String.class); assertEquals(200, response.getStatus()); - assertEquals("PUT:hello:{myParameter=myValue}", body); + assertEquals(PUT_HELLO, body); assertTrue(MyJacksonProvider.hasWrittenSome()); assertFalse(MyGsonProvider.hasWrittenSome()); @@ -449,15 +463,15 @@ public class HttpClientTest { private HttpClient getAuthHttpClient() throws KeyManagementException, NoSuchAlgorithmException, ClassNotFoundException { - return HttpClient.factory.build(BusTopicParams.builder().clientName("testHttpAuthClient") - .useHttps(true).allowSelfSignedCerts(true).hostname("localhost").port(6667).basePath("junit/echo") + return HttpClient.factory.build(BusTopicParams.builder().clientName(TEST_HTTP_AUTH_CLIENT) + .useHttps(true).allowSelfSignedCerts(true).hostname(LOCALHOST).port(6667).basePath(JUNIT_ECHO) .userName("x").password("y").managed(true).build()); } private HttpClient getNoAuthHttpClient(String clientName, boolean https, int port) throws KeyManagementException, NoSuchAlgorithmException, ClassNotFoundException { return HttpClient.factory.build(BusTopicParams.builder().clientName(clientName) - .useHttps(https).allowSelfSignedCerts(https).hostname("localhost").port(port).basePath("junit/echo") + .useHttps(https).allowSelfSignedCerts(https).hostname(LOCALHOST).port(port).basePath(JUNIT_ECHO) .userName(null).password(null).managed(true).build()); } 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 972fc666..3ae39ebd 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 @@ -47,6 +47,12 @@ import org.slf4j.LoggerFactory; * HttpServletServer JUNIT tests. */ public class HttpServerTest { + private static final String LOCALHOST = "localhost"; + private static final String SWAGGER_JSON = "/swagger.json"; + private static final String JUNIT_ECHO_HELLO = "/junit/echo/hello"; + private static final String JUNIT_ECHO_FULL_REQUEST = "/junit/echo/full/request"; + private static final String SOME_TEXT = "some text"; + private static final String HELLO = "hello"; /** * Logger. @@ -87,7 +93,7 @@ public class HttpServerTest { public void testDefaultPackageServer() throws Exception { logger.info("-- testDefaultPackageServer() --"); - HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", port, "/", false, true); + HttpServletServer server = HttpServletServer.factory.build("echo", LOCALHOST, port, "/", false, true); server.addServletPackage("/*", this.getClass().getPackage().getName()); server.addFilterClass("/*", TestFilter.class.getCanonicalName()); server.waitedStart(5000); @@ -96,10 +102,10 @@ public class HttpServerTest { RestEchoReqResp request = new RestEchoReqResp(); request.setRequestId(100); - request.setText("some text"); + request.setText(SOME_TEXT); String reqText = gson.toJson(request); - String response = http(HttpServletServer.factory.get(port), portUrl + "/junit/echo/full/request", reqText); + String response = http(HttpServletServer.factory.get(port), portUrl + JUNIT_ECHO_FULL_REQUEST, reqText); assertEquals(reqText, response); } @@ -107,7 +113,7 @@ public class HttpServerTest { public void testJacksonPackageServer() throws Exception { logger.info("-- testJacksonPackageServer() --"); - HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", port, "/", false, true); + HttpServletServer server = HttpServletServer.factory.build("echo", LOCALHOST, port, "/", false, true); server.setSerializationProvider(MyJacksonProvider.class.getCanonicalName()); server.addServletPackage("/*", this.getClass().getPackage().getName()); @@ -118,10 +124,10 @@ public class HttpServerTest { RestEchoReqResp request = new RestEchoReqResp(); request.setRequestId(100); - request.setText("some text"); + request.setText(SOME_TEXT); String reqText = gson.toJson(request); - String response = http(HttpServletServer.factory.get(port), portUrl + "/junit/echo/full/request", reqText); + String response = http(HttpServletServer.factory.get(port), portUrl + JUNIT_ECHO_FULL_REQUEST, reqText); assertEquals(reqText, response); assertTrue(MyJacksonProvider.hasReadSome()); @@ -135,7 +141,7 @@ public class HttpServerTest { public void testGsonPackageServer() throws Exception { logger.info("-- testGsonPackageServer() --"); - HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", port, "/", false, true); + HttpServletServer server = HttpServletServer.factory.build("echo", LOCALHOST, port, "/", false, true); server.setSerializationProvider(MyGsonProvider.class.getCanonicalName()); server.addServletPackage("/*", this.getClass().getPackage().getName()); @@ -146,10 +152,10 @@ public class HttpServerTest { RestEchoReqResp request = new RestEchoReqResp(); request.setRequestId(100); - request.setText("some text"); + request.setText(SOME_TEXT); String reqText = gson.toJson(request); - String response = http(HttpServletServer.factory.get(port), portUrl + "/junit/echo/full/request", reqText); + String response = http(HttpServletServer.factory.get(port), portUrl + JUNIT_ECHO_FULL_REQUEST, reqText); assertEquals(reqText, response); assertTrue(MyGsonProvider.hasReadSome()); @@ -163,7 +169,7 @@ public class HttpServerTest { public void testDefaultClassServer() throws Exception { logger.info("-- testDefaultClassServer() --"); - HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", port, "/", false, true); + HttpServletServer server = HttpServletServer.factory.build("echo", LOCALHOST, port, "/", false, true); server.addServletClass("/*", RestEchoService.class.getCanonicalName()); server.addFilterClass("/*", TestFilter.class.getCanonicalName()); server.waitedStart(5000); @@ -172,10 +178,10 @@ public class HttpServerTest { RestEchoReqResp request = new RestEchoReqResp(); request.setRequestId(100); - request.setText("some text"); + request.setText(SOME_TEXT); String reqText = gson.toJson(request); - String response = http(HttpServletServer.factory.get(port), portUrl + "/junit/echo/full/request", reqText); + String response = http(HttpServletServer.factory.get(port), portUrl + JUNIT_ECHO_FULL_REQUEST, reqText); assertEquals(reqText, response); } @@ -183,7 +189,7 @@ public class HttpServerTest { public void testJacksonClassServer() throws Exception { logger.info("-- testJacksonClassServer() --"); - HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", port, "/", false, true); + HttpServletServer server = HttpServletServer.factory.build("echo", LOCALHOST, port, "/", false, true); server.setSerializationProvider(MyJacksonProvider.class.getCanonicalName()); server.addServletClass("/*", RestEchoService.class.getCanonicalName()); server.addFilterClass("/*", TestFilter.class.getCanonicalName()); @@ -193,10 +199,10 @@ public class HttpServerTest { RestEchoReqResp request = new RestEchoReqResp(); request.setRequestId(100); - request.setText("some text"); + request.setText(SOME_TEXT); String reqText = gson.toJson(request); - String response = http(HttpServletServer.factory.get(port), portUrl + "/junit/echo/full/request", reqText); + String response = http(HttpServletServer.factory.get(port), portUrl + JUNIT_ECHO_FULL_REQUEST, reqText); assertEquals(reqText, response); assertTrue(MyJacksonProvider.hasReadSome()); @@ -210,7 +216,7 @@ public class HttpServerTest { public void testGsonClassServer() throws Exception { logger.info("-- testGsonClassServer() --"); - HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", port, "/", false, true); + HttpServletServer server = HttpServletServer.factory.build("echo", LOCALHOST, port, "/", false, true); server.setSerializationProvider(MyGsonProvider.class.getCanonicalName()); server.addServletClass("/*", RestEchoService.class.getCanonicalName()); server.addFilterClass("/*", TestFilter.class.getCanonicalName()); @@ -220,10 +226,10 @@ public class HttpServerTest { RestEchoReqResp request = new RestEchoReqResp(); request.setRequestId(100); - request.setText("some text"); + request.setText(SOME_TEXT); String reqText = gson.toJson(request); - String response = http(HttpServletServer.factory.get(port), portUrl + "/junit/echo/full/request", reqText); + String response = http(HttpServletServer.factory.get(port), portUrl + JUNIT_ECHO_FULL_REQUEST, reqText); assertEquals(reqText, response); assertTrue(MyGsonProvider.hasReadSome()); @@ -235,7 +241,7 @@ public class HttpServerTest { @Test public void testSerialize() { - HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", port, "/", false, true); + HttpServletServer server = HttpServletServer.factory.build("echo", LOCALHOST, port, "/", false, true); server.addServletPackage("/*", this.getClass().getPackage().getName()); server.addFilterClass("/*", TestFilter.class.getCanonicalName()); @@ -247,7 +253,7 @@ public class HttpServerTest { public void testSingleServer() throws Exception { logger.info("-- testSingleServer() --"); - HttpServletServer server = HttpServletServer.factory.build("echo", "localhost", port, "/", false, true); + HttpServletServer server = HttpServletServer.factory.build("echo", LOCALHOST, port, "/", false, true); server.addServletPackage("/*", this.getClass().getPackage().getName()); server.addFilterClass("/*", TestFilter.class.getCanonicalName()); server.waitedStart(5000); @@ -255,12 +261,12 @@ public class HttpServerTest { assertTrue(HttpServletServer.factory.get(port).isAlive()); assertFalse(HttpServletServer.factory.get(port).isAaf()); - String response = http(HttpServletServer.factory.get(port), portUrl + "/junit/echo/hello"); - assertTrue("hello".equals(response)); + String response = http(HttpServletServer.factory.get(port), portUrl + JUNIT_ECHO_HELLO); + assertEquals(HELLO, response); response = null; try { - response = http(HttpServletServer.factory.get(port), portUrl + "/swagger.json"); + response = http(HttpServletServer.factory.get(port), portUrl + SWAGGER_JSON); } catch (IOException e) { // Expected } @@ -283,38 +289,38 @@ public class HttpServerTest { public void testMultipleServers() throws Exception { logger.info("-- testMultipleServers() --"); - HttpServletServer server1 = HttpServletServer.factory.build("echo-1", false,"localhost", port, "/", true, true); + HttpServletServer server1 = HttpServletServer.factory.build("echo-1", false,LOCALHOST, port, "/", true, true); server1.addServletPackage("/*", this.getClass().getPackage().getName()); server1.waitedStart(5000); int port2 = port + 1; - HttpServletServer server2 = HttpServletServer.factory.build("echo-2", "localhost", port2, "/", false, true); + HttpServletServer server2 = HttpServletServer.factory.build("echo-2", LOCALHOST, port2, "/", false, true); server2.addServletPackage("/*", this.getClass().getPackage().getName()); server2.waitedStart(5000); assertTrue(HttpServletServer.factory.get(port).isAlive()); assertTrue(HttpServletServer.factory.get(port2).isAlive()); - String response = http(HttpServletServer.factory.get(port), portUrl + "/junit/echo/hello"); - assertTrue("hello".equals(response)); + String response = http(HttpServletServer.factory.get(port), portUrl + JUNIT_ECHO_HELLO); + assertTrue(HELLO.equals(response)); - response = http(HttpServletServer.factory.get(port), portUrl + "/swagger.json"); + response = http(HttpServletServer.factory.get(port), portUrl + SWAGGER_JSON); assertTrue(response != null); - response = http(HttpServletServer.factory.get(port2), LOCALHOST_PREFIX + port2 + "/junit/echo/hello"); - assertTrue("hello".equals(response)); + response = http(HttpServletServer.factory.get(port2), LOCALHOST_PREFIX + port2 + JUNIT_ECHO_HELLO); + assertTrue(HELLO.equals(response)); response = null; try { - response = http(HttpServletServer.factory.get(port2), LOCALHOST_PREFIX + port2 + "/swagger.json"); + response = http(HttpServletServer.factory.get(port2), LOCALHOST_PREFIX + port2 + SWAGGER_JSON); } catch (IOException e) { // Expected } assertTrue(response == null); HttpServletServer.factory.destroy(); - assertTrue(HttpServletServer.factory.inventory().size() == 0); + assertTrue(HttpServletServer.factory.inventory().isEmpty()); } @Test @@ -323,20 +329,20 @@ public class HttpServerTest { String randomName = UUID.randomUUID().toString(); - HttpServletServer server = HttpServletServer.factory.build(randomName, "localhost", port, "/", false, true); + HttpServletServer server = HttpServletServer.factory.build(randomName, LOCALHOST, port, "/", false, true); server.addServletPackage("/*", this.getClass().getPackage().getName()); server.waitedStart(5000); assertTrue(HttpServletServer.factory.get(port).isAlive()); - String response = http(HttpServletServer.factory.get(port), portUrl + "/junit/echo/hello"); - assertTrue("hello".equals(response)); + String response = http(HttpServletServer.factory.get(port), portUrl + JUNIT_ECHO_HELLO); + assertTrue(HELLO.equals(response)); response = http(HttpServletServer.factory.get(port), portUrl + "/junit/endpoints/http/servers"); assertTrue(response.contains(randomName)); HttpServletServer.factory.destroy(); - assertTrue(HttpServletServer.factory.inventory().size() == 0); + assertTrue(HttpServletServer.factory.inventory().isEmpty()); } @Test @@ -344,17 +350,17 @@ public class HttpServerTest { logger.info("-- testServiceClass() --"); String randomName = UUID.randomUUID().toString(); - HttpServletServer server = HttpServletServer.factory.build(randomName, "localhost", port, "/", false, true); + HttpServletServer server = HttpServletServer.factory.build(randomName, LOCALHOST, port, "/", false, true); server.addServletClass("/*", RestEchoService.class.getCanonicalName()); server.waitedStart(5000); assertTrue(HttpServletServer.factory.get(port).isAlive()); - String response = http(HttpServletServer.factory.get(port), portUrl + "/junit/echo/hello"); - assertTrue("hello".equals(response)); + String response = http(HttpServletServer.factory.get(port), portUrl + JUNIT_ECHO_HELLO); + assertTrue(HELLO.equals(response)); HttpServletServer.factory.destroy(); - assertTrue(HttpServletServer.factory.inventory().size() == 0); + assertTrue(HttpServletServer.factory.inventory().isEmpty()); } @Test @@ -363,21 +369,21 @@ public class HttpServerTest { String randomName = UUID.randomUUID().toString(); - HttpServletServer server = HttpServletServer.factory.build(randomName, "localhost", port, "/", false, true); + HttpServletServer server = HttpServletServer.factory.build(randomName, LOCALHOST, port, "/", false, true); server.addServletClass("/*", RestEchoService.class.getCanonicalName()); server.addServletClass("/*", RestEndpoints.class.getCanonicalName()); server.waitedStart(5000); assertTrue(HttpServletServer.factory.get(port).isAlive()); - String response = http(HttpServletServer.factory.get(port), portUrl + "/junit/echo/hello"); - assertTrue("hello".equals(response)); + String response = http(HttpServletServer.factory.get(port), portUrl + JUNIT_ECHO_HELLO); + assertTrue(HELLO.equals(response)); response = http(HttpServletServer.factory.get(port), portUrl + "/junit/endpoints/http/servers"); assertTrue(response.contains(randomName)); HttpServletServer.factory.destroy(); - assertTrue(HttpServletServer.factory.inventory().size() == 0); + assertTrue(HttpServletServer.factory.inventory().isEmpty()); } /** @@ -388,7 +394,7 @@ public class HttpServerTest { * @throws InterruptedException thrown if thread interrupted occurs */ protected String http(HttpServletServer server, String urlString) - throws MalformedURLException, IOException, InterruptedException { + throws IOException, InterruptedException { URL url = new URL(urlString); String response = null; int numRetries = 1; @@ -418,7 +424,7 @@ public class HttpServerTest { * @throws InterruptedException thrown if thread interrupted occurs */ protected String http(HttpServletServer server, String urlString, String post) - throws MalformedURLException, IOException, InterruptedException { + throws IOException, InterruptedException { URL url = new URL(urlString); String response = null; int numRetries = 1; @@ -453,14 +459,14 @@ public class HttpServerTest { * @throws IOException if an I/O error occurs */ protected String response(URLConnection conn) throws IOException { - String response = ""; + StringBuilder response = new StringBuilder(); try (BufferedReader ioReader = new BufferedReader(new InputStreamReader(conn.getInputStream()))) { String line; while ((line = ioReader.readLine()) != null) { - response += line; + response.append(line); } } - return response; + return response.toString(); } } -- cgit 1.2.3-korg