aboutsummaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-06-12 14:32:25 -0400
committerJim Hahn <jrh3@att.com>2019-06-12 17:36:59 -0400
commitea262e6da52fd4da0733f02998f87aebaf502ddb (patch)
treea7cded567521f0141f31d9f8c185eccdaf2a8979 /policy-endpoints/src/test
parente671e9fa5d09ec696cb24aeefaf10ddbc7c705d7 (diff)
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 <jrh3@att.com>
Diffstat (limited to 'policy-endpoints/src/test')
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/BusTopicFactoryTestBase.java6
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSinkFactoryTest.java8
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSourceFactoryTest.java10
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java11
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusPublisherTest.java9
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicBaseTest.java1
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicParamsTest.java3
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSinkTest.java1
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineDmaapTopicSinkTest.java1
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineUebTopicSinkTest.java1
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java260
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java104
12 files changed, 229 insertions, 186 deletions
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<T extends Topic> extends TopicFact
* @param values the values to which the property should be set, defaults to
* {@code null} and ""
*/
- protected void checkDefault(String builderName, Function<BusTopicParams, Boolean> validate, Object... values) {
+ protected void checkDefault(String builderName, Predicate<BusTopicParams> validate, Object... values) {
Object[] values2 = (values.length > 0 ? values : new Object[] {null, ""});
for (Object value : values2) {
@@ -209,7 +209,7 @@ public abstract class BusTopicFactoryTestBase<T extends Topic> 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<DmaapTo
* Creates the object to be tested.
*/
@Before
+ @Override
public void setUp() {
super.setUp();
@@ -53,17 +54,20 @@ public class DmaapTopicSinkFactoryTest extends DmaapTopicFactoryTestBase<DmaapTo
}
@Test
+ @Override
public void testBuildBusTopicParams() {
super.testBuildBusTopicParams();
super.testBuildBusTopicParams_Ex();
}
@Test
+ @Override
public void testBuildListOfStringString() {
super.testBuildListOfStringString();
}
@Test
+ @Override
public void testBuildProperties() {
super.testBuildProperties();
super.testBuildProperties_Variations();
@@ -75,12 +79,14 @@ public class DmaapTopicSinkFactoryTest extends DmaapTopicFactoryTestBase<DmaapTo
}
@Test
+ @Override
public void testDestroyString_testGet_testInventory() {
super.testDestroyString_testGet_testInventory();
super.testDestroyString_Ex();
}
@Test
+ @Override
public void testDestroy() {
super.testDestroy();
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSourceFactoryTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSourceFactoryTest.java
index ec6fcfcc..d6187420 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSourceFactoryTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSourceFactoryTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine - Common Modules
* ================================================================================
- * 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.
@@ -44,6 +44,7 @@ public class DmaapTopicSourceFactoryTest extends DmaapTopicFactoryTestBase<Dmaap
* Creates the object to be tested.
*/
@Before
+ @Override
public void setUp() {
super.setUp();
@@ -56,12 +57,14 @@ public class DmaapTopicSourceFactoryTest extends DmaapTopicFactoryTestBase<Dmaap
}
@Test
+ @Override
public void testBuildBusTopicParams() {
super.testBuildBusTopicParams();
super.testBuildBusTopicParams_Ex();
}
@Test
+ @Override
public void testBuildProperties() {
super.testBuildProperties();
@@ -79,7 +82,7 @@ public class DmaapTopicSourceFactoryTest extends DmaapTopicFactoryTestBase<Dmaap
checkDefault(PROPERTY_TOPIC_SOURCE_FETCH_LIMIT_SUFFIX,
params2 -> 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<Dmaap
}
@Test
+ @Override
public void testBuildListOfStringString() {
super.testBuildListOfStringString();
@@ -111,12 +115,14 @@ public class DmaapTopicSourceFactoryTest extends DmaapTopicFactoryTestBase<Dmaap
}
@Test
+ @Override
public void testDestroyString_testGet_testInventory() {
super.testDestroyString_testGet_testInventory();
super.testDestroyString_Ex();
}
@Test
+ @Override
public void testDestroy() {
super.testDestroy();
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java
index c9064d45..ae07798d 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.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.
@@ -47,6 +47,7 @@ import org.powermock.reflect.Whitebox;
public class BusConsumerTest extends TopicTestBase {
@Before
+ @Override
public void setUp() {
super.setUp();
}
@@ -88,13 +89,17 @@ public class BusConsumerTest extends TopicTestBase {
cons.fetch();
fail("missing exception");
- } catch (IOException | InterruptedException e) {
+ } catch (IOException e) {
+ assertEquals(ex, e);
+
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
assertEquals(ex, e);
}
}
@Test
- public void testCambriaConsumerWrapperClose() throws Exception {
+ public void testCambriaConsumerWrapperClose() {
CambriaConsumerWrapper cons = new CambriaConsumerWrapper(builder.build());
// set filter several times to cause different branches of close() to be executed
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusPublisherTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusPublisherTest.java
index 9c1e4af4..283d44da 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusPublisherTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusPublisherTest.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.
@@ -48,6 +48,7 @@ import org.onap.policy.common.endpoints.event.comm.bus.internal.BusPublisher.Dma
public class BusPublisherTest extends TopicTestBase {
@Before
+ @Override
public void setUp() {
super.setUp();
}
@@ -90,7 +91,7 @@ public class BusPublisherTest extends TopicTestBase {
}
@Test
- public void testCambriaPublisherWrapperClose() throws Exception {
+ public void testCambriaPublisherWrapperClose() {
CambriaBatchingPublisher pub = mock(CambriaBatchingPublisher.class);
CambriaPublisherWrapper cambria = new CambriaPublisherWrapper(makeBuilder().build());
cambria.publisher = pub;
@@ -146,7 +147,7 @@ public class BusPublisherTest extends TopicTestBase {
}
@Test
- public void testDmaapPublisherWrapperSend() throws Exception {
+ public void testDmaapPublisherWrapperSend() {
MRSimplerBatchPublisher pub = mock(MRSimplerBatchPublisher.class);
DmaapPublisherWrapper dmaap = new DmaapAafPublisherWrapper(servers, MY_TOPIC, MY_USERNAME, MY_PASSWD, true);
dmaap.publisher = pub;
@@ -168,7 +169,7 @@ public class BusPublisherTest extends TopicTestBase {
}
@Test(expected = IllegalArgumentException.class)
- public void testDmaapPublisherWrapperSend_NullMessage() throws Exception {
+ public void testDmaapPublisherWrapperSend_NullMessage() {
MRSimplerBatchPublisher pub = mock(MRSimplerBatchPublisher.class);
DmaapPublisherWrapper dmaap = new DmaapAafPublisherWrapper(servers, MY_TOPIC, MY_USERNAME, MY_PASSWD, true);
dmaap.publisher = pub;
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicBaseTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicBaseTest.java
index 5628a239..01028045 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicBaseTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicBaseTest.java
@@ -39,6 +39,7 @@ public class BusTopicBaseTest extends TopicTestBase {
* Initializes the object to be tested.
*/
@Before
+ @Override
public void setUp() {
super.setUp();
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicParamsTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicParamsTest.java
index 8d1c6343..54531c56 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicParamsTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicParamsTest.java
@@ -35,6 +35,7 @@ import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams.T
public class BusTopicParamsTest extends TopicTestBase {
@Before
+ @Override
public void setUp() {
super.setUp();
}
@@ -123,7 +124,7 @@ public class BusTopicParamsTest extends TopicTestBase {
* Tests the boolean methods by applying a function, once with {@code false} and once
* with {@code true}. Verifies that all of the boolean methods return the correct
* value by concatenating them.
- *
+ *
* @param expectedTrue the string that is expected when {@code true} is passed to the
* method
* @param function function to be applied to the builder
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSinkTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSinkTest.java
index cb6eb107..2356746e 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSinkTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineBusTopicSinkTest.java
@@ -47,6 +47,7 @@ public class InlineBusTopicSinkTest extends TopicTestBase {
* Creates the object to be tested.
*/
@Before
+ @Override
public void setUp() {
super.setUp();
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineDmaapTopicSinkTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineDmaapTopicSinkTest.java
index aaab402c..d9bc990b 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineDmaapTopicSinkTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineDmaapTopicSinkTest.java
@@ -37,6 +37,7 @@ public class InlineDmaapTopicSinkTest extends TopicTestBase {
* Creates the object to be tested.
*/
@Before
+ @Override
public void setUp() {
super.setUp();
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineUebTopicSinkTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineUebTopicSinkTest.java
index 2516406f..a45504f2 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineUebTopicSinkTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/InlineUebTopicSinkTest.java
@@ -37,6 +37,7 @@ public class InlineUebTopicSinkTest extends TopicTestBase {
* Creates the object to be tested.
*/
@Before
+ @Override
public void setUp() {
super.setUp();
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 1f1f117e..4f7a5a9f 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
@@ -47,6 +47,20 @@ import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
import org.onap.policy.common.utils.network.NetworkUtil;
public class HttpClientTest {
+ private static final String TEST_HTTP_NO_AUTH_CLIENT = "testHttpNoAuthClient";
+ private static final String TEST_HTTP_AUTH_CLIENT = "testHttpAuthClient";
+ private static final String LOCALHOST = "localhost";
+ private static final String JUNIT_ECHO = "junit/echo";
+ private static final String HELLO = "hello";
+ private static final String MY_VALUE = "myValue";
+ private static final String FALSE_STRING = "false";
+ private static final String ALPHA123 = "alpha123";
+ private static final String PUT_HELLO = "PUT:hello:{myParameter=myValue}";
+ private static final String DOT_GSON = "." + "GSON";
+ private static final String DOT_JACKSON = "." + "JACKSON";
+ private static final String DOT_PDP = "." + "PDP";
+ private static final String DOT_PAP = "." + "PAP";
+
private static final HashMap<String, String> 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<MyEntity> entity = Entity.entity(new MyEntity("myValue"), MediaType.APPLICATION_JSON);
- final Response response = client.put("hello", entity, Collections.emptyMap());
+ Entity<MyEntity> 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<MyEntity> entity = Entity.entity(new MyEntity("myValue"), MediaType.APPLICATION_JSON);
- final Response response = client.post("hello", entity, Collections.emptyMap());
+ Entity<MyEntity> 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<MyEntity> entity = Entity.entity(new MyEntity("myValue"), MediaType.APPLICATION_JSON);
- final Response response = client.put("hello", entity, Collections.emptyMap());
+ Entity<MyEntity> 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<MyEntity> entity = Entity.entity(new MyEntity("myValue"), MediaType.APPLICATION_JSON);
- final Response response = client.put("hello", entity, Collections.emptyMap());
+ Entity<MyEntity> 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<MyEntity> entity = Entity.entity(new MyEntity("myValue"), MediaType.APPLICATION_JSON);
- final Response response = client.put("hello", entity, Collections.emptyMap());
+ Entity<MyEntity> 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<HttpServletServer> 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<HttpClient> clients = HttpClient.factory.build(httpProperties);
assertEquals(2, clients.size());
- Entity<MyEntity> entity = Entity.entity(new MyEntity("myValue"), MediaType.APPLICATION_JSON);
+ Entity<MyEntity> 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();
}
}