2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.common.endpoints.http.server.test;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertSame;
28 import static org.junit.Assert.assertTrue;
30 import java.util.Collections;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Properties;
34 import java.util.TreeMap;
35 import java.util.concurrent.CountDownLatch;
36 import java.util.concurrent.TimeUnit;
37 import javax.ws.rs.client.Entity;
38 import javax.ws.rs.client.InvocationCallback;
39 import javax.ws.rs.core.MediaType;
40 import javax.ws.rs.core.Response;
42 import org.junit.AfterClass;
43 import org.junit.Before;
44 import org.junit.BeforeClass;
45 import org.junit.Test;
46 import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
47 import org.onap.policy.common.endpoints.http.client.HttpClient;
48 import org.onap.policy.common.endpoints.http.client.HttpClientConfigException;
49 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
50 import org.onap.policy.common.endpoints.http.server.HttpServletServer;
51 import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
52 import org.onap.policy.common.endpoints.http.server.internal.JettyJerseyServer;
53 import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
54 import org.onap.policy.common.utils.network.NetworkUtil;
56 public class HttpClientTest {
57 private static final String TEST_HTTP_NO_AUTH_CLIENT = "testHttpNoAuthClient";
58 private static final String TEST_HTTP_AUTH_CLIENT = "testHttpAuthClient";
59 private static final String LOCALHOST = "localhost";
60 private static final String JUNIT_ECHO = "junit/echo";
61 private static final String HELLO = "hello";
62 private static final String MY_VALUE = "myValue";
63 private static final String FALSE_STRING = "false";
64 private static final String ALPHA123 = "alpha123";
65 private static final String PUT_HELLO = "PUT:hello:{myParameter=myValue}";
66 private static final String DOT_PDP = "." + "PDP";
67 private static final String DOT_PAP = "." + "PAP";
69 private static final HashMap<String, String> savedValuesMap = new HashMap<>();
72 * Setup before class method.
74 * @throws InterruptedException can be interrupted
77 public static void setUpBeforeClass() throws InterruptedException {
78 /* echo server - http + no auth */
80 final HttpServletServer echoServerNoAuth =
81 HttpServletServerFactoryInstance.getServerFactory().build("echo", LOCALHOST, 6666, "/", false, true);
82 echoServerNoAuth.addServletPackage("/*", HttpClientTest.class.getPackage().getName());
83 echoServerNoAuth.waitedStart(5000);
85 if (!NetworkUtil.isTcpPortOpen(LOCALHOST, echoServerNoAuth.getPort(), 5, 10000L)) {
86 throw new IllegalStateException("cannot connect to port " + echoServerNoAuth.getPort());
89 String keyStoreSystemProperty = System.getProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME);
90 if (keyStoreSystemProperty != null) {
91 savedValuesMap.put(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME, keyStoreSystemProperty);
94 String keyStorePasswordSystemProperty =
95 System.getProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME);
96 if (keyStorePasswordSystemProperty != null) {
97 savedValuesMap.put(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME,
98 keyStorePasswordSystemProperty);
101 String trustStoreSystemProperty = System.getProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME);
102 if (trustStoreSystemProperty != null) {
103 savedValuesMap.put(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME, trustStoreSystemProperty);
106 String trustStorePasswordSystemProperty =
107 System.getProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME);
108 if (trustStorePasswordSystemProperty != null) {
109 savedValuesMap.put(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME,
110 trustStorePasswordSystemProperty);
113 System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME, "src/test/resources/keystore-test");
114 System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME, "kstest");
116 System.setProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME, "src/test/resources/keystore-test");
117 System.setProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME, "kstest");
119 /* echo server - https + basic auth */
121 final HttpServletServer echoServerAuth = HttpServletServerFactoryInstance.getServerFactory()
122 .build("echo", true, LOCALHOST, 6667, "/", false, true);
123 echoServerAuth.setBasicAuthentication("x", "y", null);
124 echoServerAuth.addServletPackage("/*", HttpClientTest.class.getPackage().getName());
125 echoServerAuth.addFilterClass("/*", TestFilter.class.getName());
126 echoServerAuth.addFilterClass("/*", TestAuthorizationFilter.class.getName());
127 echoServerAuth.addFilterClass("/*", TestAafAuthFilter.class.getName());
128 echoServerAuth.addFilterClass("/*", TestAafGranularAuthFilter.class.getName());
129 echoServerAuth.waitedStart(5000);
131 if (!NetworkUtil.isTcpPortOpen(LOCALHOST, echoServerAuth.getPort(), 5, 10000L)) {
132 throw new IllegalStateException("cannot connect to port " + echoServerAuth.getPort());
137 * Clear https clients and reset providers.
140 public void setUp() {
141 HttpClientFactoryInstance.getClientFactory().destroy();
143 MyGsonProvider.resetSome();
147 * After the class is created method.
150 public static void tearDownAfterClass() {
151 HttpServletServerFactoryInstance.getServerFactory().destroy();
152 HttpClientFactoryInstance.getClientFactory().destroy();
154 if (savedValuesMap.containsKey(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME)) {
155 System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME,
156 savedValuesMap.get(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME));
157 savedValuesMap.remove(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME);
159 System.clearProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME);
162 if (savedValuesMap.containsKey(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME)) {
163 System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME,
164 savedValuesMap.get(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME));
165 savedValuesMap.remove(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME);
167 System.clearProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PASSWORD_PROPERTY_NAME);
170 if (savedValuesMap.containsKey(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME)) {
171 System.setProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME,
172 savedValuesMap.get(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME));
173 savedValuesMap.remove(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME);
175 System.clearProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PROPERTY_NAME);
178 if (savedValuesMap.containsKey(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME)) {
179 System.setProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME,
180 savedValuesMap.get(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME));
181 savedValuesMap.remove(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME);
183 System.clearProperty(JettyJerseyServer.SYSTEM_TRUSTSTORE_PASSWORD_PROPERTY_NAME);
190 public void testHttpGetNoAuthClient() throws Exception {
191 final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
193 final Response response = client.get(HELLO);
194 final String body = HttpClient.getBody(response, String.class);
196 assertEquals(200, response.getStatus());
197 assertEquals(HELLO, body);
201 public void testHttpGetNoAuthClientAsync() throws Exception {
202 final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
204 MyCallback callback = new MyCallback();
205 final Response response = client.get(callback, HELLO, new TreeMap<>()).get();
207 verifyCallback("testHttpGetNoAuthClientAsync", callback, response);
209 final String body = HttpClient.getBody(response, String.class);
211 assertEquals(200, response.getStatus());
212 assertEquals(HELLO, body);
215 private void verifyCallback(String testName, MyCallback callback, final Response response)
216 throws InterruptedException {
217 assertTrue(testName, callback.await());
218 assertNull(testName, callback.getThrowable());
219 assertSame(testName, response, callback.getResponse());
223 public void testHttpPutNoAuthClient() throws Exception {
224 final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false, 6666);
226 Entity<MyEntity> entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON);
227 final Response response = client.put(HELLO, entity, Collections.emptyMap());
228 final String body = HttpClient.getBody(response, String.class);
230 assertEquals(200, response.getStatus());
231 assertEquals(PUT_HELLO, body);
235 public void testHttpPutNoAuthClientAsync() throws Exception {
236 final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false, 6666);
238 Entity<MyEntity> entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON);
239 MyCallback callback = new MyCallback();
240 final Response response = client.put(callback, HELLO, entity, Collections.emptyMap()).get();
242 verifyCallback("testHttpPutNoAuthClientAsync", callback, response);
244 final String body = HttpClient.getBody(response, String.class);
246 assertEquals(200, response.getStatus());
247 assertEquals(PUT_HELLO, body);
251 public void testHttpPostNoAuthClient() throws Exception {
252 final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
255 Entity<MyEntity> entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON);
256 final Response response = client.post(HELLO, entity, Collections.emptyMap());
257 final String body = HttpClient.getBody(response, String.class);
259 assertEquals(200, response.getStatus());
260 assertEquals("POST:hello:{myParameter=myValue}", body);
264 public void testHttpPostNoAuthClientAsync() throws Exception {
265 final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
268 Entity<MyEntity> entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON);
269 MyCallback callback = new MyCallback();
270 final Response response = client.post(callback, HELLO, entity, Collections.emptyMap()).get();
272 verifyCallback("testHttpPostNoAuthClientAsync", callback, response);
274 final String body = HttpClient.getBody(response, String.class);
276 assertEquals(200, response.getStatus());
277 assertEquals("POST:hello:{myParameter=myValue}", body);
281 public void testHttpDeletetNoAuthClient() throws Exception {
282 final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
285 final Response response = client.delete(HELLO, Collections.emptyMap());
286 final String body = HttpClient.getBody(response, String.class);
288 assertEquals(200, response.getStatus());
289 assertEquals("DELETE:hello", body);
293 public void testHttpDeletetNoAuthClientAsync() throws Exception {
294 final HttpClient client = getNoAuthHttpClient(TEST_HTTP_NO_AUTH_CLIENT, false,
297 MyCallback callback = new MyCallback();
298 final Response response = client.delete(callback, HELLO, Collections.emptyMap()).get();
300 verifyCallback("testHttpDeletetNoAuthClientAsync", callback, response);
302 final String body = HttpClient.getBody(response, String.class);
304 assertEquals(200, response.getStatus());
305 assertEquals("DELETE:hello", body);
309 * Perform one asynchronous test with auth client; don't need to test every method.
310 * @throws Exception if an error occurs
313 public void testHttpAsyncAuthClient() throws Exception {
314 final HttpClient client = getAuthHttpClient();
316 MyCallback callback = new MyCallback();
317 final Response response = client.get(callback, HELLO, null).get();
319 verifyCallback("testHttpAsyncAuthClient", callback, response);
321 final String body = HttpClient.getBody(response, String.class);
323 assertEquals(200, response.getStatus());
324 assertEquals(HELLO, body);
328 public void testHttpGetAuthClient() throws Exception {
329 final HttpClient client = getAuthHttpClient();
331 final Response response = client.get(HELLO);
332 final String body = HttpClient.getBody(response, String.class);
334 assertEquals(200, response.getStatus());
335 assertEquals(HELLO, body);
339 public void testHttpPutAuthClient() throws Exception {
340 final HttpClient client = getAuthHttpClient();
342 Entity<MyEntity> entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON);
343 final Response response = client.put(HELLO, entity, Collections.emptyMap());
344 final String body = HttpClient.getBody(response, String.class);
346 assertEquals(200, response.getStatus());
347 assertEquals(PUT_HELLO, body);
351 public void testHttpPutAuthClient_GsonProvider() throws Exception {
352 final HttpClient client = HttpClientFactoryInstance.getClientFactory()
353 .build(BusTopicParams.builder().clientName(TEST_HTTP_AUTH_CLIENT).useHttps(true)
354 .allowSelfSignedCerts(true).hostname(LOCALHOST).port(6667).basePath(JUNIT_ECHO)
355 .userName("x").password("y").managed(true)
356 .serializationProvider(MyGsonProvider.class.getName()).build());
358 Entity<MyEntity> entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON);
359 final Response response = client.put(HELLO, entity, Collections.emptyMap());
360 final String body = HttpClient.getBody(response, String.class);
362 assertEquals(200, response.getStatus());
363 assertEquals(PUT_HELLO, body);
365 assertTrue(MyGsonProvider.hasWrittenSome());
369 public void testHttpAuthClient401() throws Exception {
370 final HttpClient client = getNoAuthHttpClient("testHttpAuthClient401", true,
372 final Response response = client.get(HELLO);
373 assertEquals(401, response.getStatus());
377 public void testHttpAuthClientProps() throws Exception {
378 final Properties httpProperties = new Properties();
380 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES, "PAP,PDP");
381 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_PAP
382 + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, LOCALHOST);
383 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_PAP
384 + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "7777");
385 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_PAP
386 + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, "testpap");
387 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_PAP
388 + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX, ALPHA123);
389 httpProperties.setProperty(
390 PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_PAP
391 + PolicyEndPointProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX,
392 RestMockHealthCheck.class.getName());
393 httpProperties.setProperty(
394 PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_PAP
395 + PolicyEndPointProperties.PROPERTY_HTTP_FILTER_CLASSES_SUFFIX,
396 TestFilter.class.getName());
397 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PAP
398 + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true");
400 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_PDP
401 + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, LOCALHOST);
402 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_PDP
403 + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "7778");
404 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_PDP
405 + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, "testpdp");
406 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_PDP
407 + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX, ALPHA123);
408 httpProperties.setProperty(
409 PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + DOT_PDP
410 + PolicyEndPointProperties.PROPERTY_HTTP_REST_CLASSES_SUFFIX,
411 RestMockHealthCheck.class.getName());
412 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PAP
413 + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true");
415 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES, "PAP,PDP");
416 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PAP
417 + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, LOCALHOST);
418 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PAP
419 + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "7777");
420 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PAP
421 + PolicyEndPointProperties.PROPERTY_HTTP_URL_SUFFIX, "pap/test");
422 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PAP
423 + PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX, FALSE_STRING);
424 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PAP
425 + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, "testpap");
426 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PAP
427 + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX, ALPHA123);
428 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PAP
429 + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true");
431 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PDP
432 + PolicyEndPointProperties.PROPERTY_HTTP_HOST_SUFFIX, LOCALHOST);
433 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PDP
434 + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "7778");
435 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PDP
436 + PolicyEndPointProperties.PROPERTY_HTTP_URL_SUFFIX, "pdp");
437 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PDP
438 + PolicyEndPointProperties.PROPERTY_HTTP_HTTPS_SUFFIX, FALSE_STRING);
439 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PDP
440 + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_USERNAME_SUFFIX, "testpdp");
441 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PDP
442 + PolicyEndPointProperties.PROPERTY_HTTP_AUTH_PASSWORD_SUFFIX, ALPHA123);
443 httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PDP
444 + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true");
446 final List<HttpServletServer> servers =
447 HttpServletServerFactoryInstance.getServerFactory().build(httpProperties);
448 assertEquals(2, servers.size());
450 final List<HttpClient> clients = HttpClientFactoryInstance.getClientFactory().build(httpProperties);
451 assertEquals(2, clients.size());
453 for (final HttpServletServer server : servers) {
454 server.waitedStart(10000);
458 final HttpClient clientPap = HttpClientFactoryInstance.getClientFactory().get("PAP");
459 response = clientPap.get();
460 assertEquals(200, response.getStatus());
462 final HttpClient clientPdp = HttpClientFactoryInstance.getClientFactory().get("PDP");
463 response = clientPdp.get("test");
464 assertEquals(500, response.getStatus());
466 assertFalse(MyGsonProvider.hasWrittenSome());
468 // try with empty path
469 response = clientPap.get("");
470 assertEquals(200, response.getStatus());
472 // try it asynchronously, too
473 MyCallback callback = new MyCallback();
474 response = clientPap.get(callback, null).get();
475 verifyCallback("testHttpAuthClientProps", callback, response);
476 assertEquals(200, response.getStatus());
478 // try it asynchronously, with empty path
479 callback = new MyCallback();
480 response = clientPap.get(callback, "", null).get();
481 verifyCallback("testHttpAuthClientProps - empty path", callback, response);
482 assertEquals(200, response.getStatus());
485 private HttpClient getAuthHttpClient() throws HttpClientConfigException {
486 return HttpClientFactoryInstance.getClientFactory()
487 .build(BusTopicParams.builder().clientName(TEST_HTTP_AUTH_CLIENT).useHttps(true)
488 .allowSelfSignedCerts(true).hostname(LOCALHOST).port(6667).basePath(JUNIT_ECHO)
489 .userName("x").password("y").managed(true).build());
492 private HttpClient getNoAuthHttpClient(String clientName, boolean https, int port)
493 throws HttpClientConfigException {
494 return HttpClientFactoryInstance.getClientFactory()
495 .build(BusTopicParams.builder().clientName(clientName).useHttps(https)
496 .allowSelfSignedCerts(https).hostname(LOCALHOST).port(port).basePath(JUNIT_ECHO)
497 .userName(null).password(null).managed(true).build());
503 private String myParameter;
505 public MyEntity(final String myParameter) {
506 this.myParameter = myParameter;
509 public void setMyParameter(final String myParameter) {
510 this.myParameter = myParameter;
513 public String getMyParameter() {
519 class MyCallback implements InvocationCallback<Response> {
521 private Response response;
524 private Throwable throwable;
526 private CountDownLatch latch = new CountDownLatch(1);
529 public void completed(Response response) {
530 this.response = response;
535 public void failed(Throwable throwable) {
536 this.throwable = throwable;
540 public boolean await() throws InterruptedException {
541 return latch.await(5, TimeUnit.SECONDS);