aboutsummaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/test
diff options
context:
space:
mode:
authorKrishnajinka <kris.jinka@samsung.com>2018-08-16 18:14:51 +0900
committerKrishnajinka <kris.jinka@samsung.com>2018-08-20 14:27:28 +0900
commitb655b67e38d98c3478a3a47407ee90410d4442bb (patch)
tree017c9782827708b77a87abf8ff0666a8e6fea6b2 /policy-endpoints/src/test
parent011cdf2d4fa47ab078061d3700a95c3d3764e5e0 (diff)
Use builder for http and jersey client
Sonar issue with more than 7 params in a method. Use builder object instead of params. Rework2 for fixing review comments. Add modifications copyright Issue-ID: POLICY-1017 Change-Id: Ib0fa692f8da770dcba06158d6e6cafbed2969c27 Signed-off-by: Krishnajinka <kris.jinka@samsung.com>
Diffstat (limited to 'policy-endpoints/src/test')
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java67
1 files changed, 43 insertions, 24 deletions
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java
index 4ffa4273..1248744d 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
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,6 +33,7 @@ import javax.ws.rs.core.Response;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.endpoints.http.client.HttpClient;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.common.endpoints.http.server.internal.JettyJerseyServer;
@@ -47,9 +49,9 @@ public class HttpClientTest {
/**
* Setup before class method.
- *
+ *
* @throws InterruptedException can be interrupted
- * @throws IOException can have an IO exception
+ * @throws IOException can have an IO exception
*/
@BeforeClass
public static void setUp() throws InterruptedException, IOException {
@@ -71,24 +73,24 @@ public class HttpClientTest {
savedValuesMap.put(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME, keyStoreSystemProperty);
}
- String keyStorePasswordSystemProperty =
- System.getProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME);
+ String keyStorePasswordSystemProperty =
+ System.getProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME);
if (keyStorePasswordSystemProperty != null) {
savedValuesMap.put(
- JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME, keyStorePasswordSystemProperty);
+ JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME, keyStorePasswordSystemProperty);
}
String trustStoreSystemProperty = System.getProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME);
if (trustStoreSystemProperty != null) {
savedValuesMap
- .put(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME, trustStoreSystemProperty);
+ .put(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME, trustStoreSystemProperty);
}
- String trustStorePasswordSystemProperty =
- System.getProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME);
+ String trustStorePasswordSystemProperty =
+ System.getProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME);
if (trustStorePasswordSystemProperty != null) {
savedValuesMap
- .put(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME, trustStorePasswordSystemProperty);
+ .put(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME, trustStorePasswordSystemProperty);
}
System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME, "src/test/resources/keystore-test");
@@ -112,7 +114,6 @@ public class HttpClientTest {
/**
* After the class is created method.
- *
*/
@AfterClass
public static void tearDown() {
@@ -122,32 +123,32 @@ public class HttpClientTest {
HttpClient.factory.destroy();
if (savedValuesMap.containsKey(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME)) {
- System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME,
- savedValuesMap.get(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME));
+ System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME,
+ savedValuesMap.get(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME));
savedValuesMap.remove(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME);
} else {
System.clearProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME);
}
if (savedValuesMap.containsKey(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME)) {
- System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME,
- savedValuesMap.get(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME));
+ System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME,
+ savedValuesMap.get(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME));
savedValuesMap.remove(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME);
} else {
System.clearProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME);
}
if (savedValuesMap.containsKey(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME)) {
- System.setProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME,
- savedValuesMap.get(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME));
+ System.setProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME,
+ savedValuesMap.get(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME));
savedValuesMap.remove(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME);
} else {
System.clearProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME);
}
if (savedValuesMap.containsKey(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME)) {
- System.setProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME,
- savedValuesMap.get(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME));
+ System.setProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME,
+ savedValuesMap.get(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME));
savedValuesMap.remove(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME);
} else {
System.clearProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME);
@@ -160,8 +161,11 @@ public class HttpClientTest {
public void testHttpNoAuthClient() throws Exception {
logger.info("-- testHttpNoAuthClient() --");
- final HttpClient client = HttpClient.factory.build("testHttpNoAuthClient", false, false, "localhost", 6666,
- "junit/echo", null, null, true);
+ final HttpClient client = HttpClient.factory.build(BusTopicParams.builder().clientName("testHttpNoAuthClient")
+ .useHttps(false)
+ .allowSelfSignedCerts(false)
+ .hostname("localhost")
+ .port(6666).basePath("junit/echo").userName(null).password(null).managed(true).build());
final Response response = client.get("hello");
final String body = HttpClient.getBody(response, String.class);
@@ -173,8 +177,16 @@ public class HttpClientTest {
public void testHttpAuthClient() throws Exception {
logger.info("-- testHttpAuthClient() --");
- final HttpClient client = HttpClient.factory.build("testHttpAuthClient", true, true,"localhost", 6667,
- "junit/echo", "x", "y", true);
+ 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).build());
+
final Response response = client.get("hello");
final String body = HttpClient.getBody(response, String.class);
@@ -186,8 +198,15 @@ public class HttpClientTest {
public void testHttpAuthClient401() throws Exception {
logger.info("-- testHttpAuthClient401() --");
- final HttpClient client = HttpClient.factory.build("testHttpAuthClient401", true, true, "localhost", 6667,
- "junit/echo", null, null, true);
+ final HttpClient client = HttpClient.factory.build(BusTopicParams.builder().clientName("testHttpAuthClient401")
+ .useHttps(true)
+ .allowSelfSignedCerts(true)
+ .hostname("localhost")
+ .port(6667)
+ .basePath("junit/echo")
+ .userName(null)
+ .password(null)
+ .managed(true).build());
final Response response = client.get("hello");
assertTrue(response.getStatus() == 401);
}