diff options
author | Jim Hahn <jrh3@att.com> | 2019-07-05 10:52:20 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-07-05 12:25:00 -0400 |
commit | e173fc5ab13b095d8f70fd8a8d4d063adeba6e6b (patch) | |
tree | 8e63717c99cfe9f52f905974c8c67fb8a1dece29 /policy-endpoints/src/test/java/org/onap | |
parent | 53f9550501ca1854318c1f552b0aba2e255b6748 (diff) |
Fix sonar issues in policy/endpoints
Sonar fixes, other than code coverage. These changes are disruptive
and will likely cause breakage in a number of policy repos.
Renamed constants.
Moved constants/factories from interfaces to classes.
Change-Id: I182d50320aa6b53e383081af806c60dd2f806cbe
Issue-ID: POLICY-1791
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'policy-endpoints/src/test/java/org/onap')
18 files changed, 204 insertions, 142 deletions
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicFactoryTestBase.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicFactoryTestBase.java index 67304f91..92d5a865 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicFactoryTestBase.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicFactoryTestBase.java @@ -34,6 +34,7 @@ import static org.onap.policy.common.endpoints.properties.PolicyEndPointProperti import java.util.Map; import org.onap.policy.common.endpoints.event.comm.Topic; import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; +import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; /** * Base class for DmaapTopicXxxFactory tests. @@ -51,9 +52,9 @@ public abstract class DmaapTopicFactoryTestBase<T extends Topic> extends BusTopi @Override public void testBuildProperties() { - + super.testBuildProperties(); - + // check properties specific to DMaaP/DME2 initFactory(); @@ -66,13 +67,13 @@ public abstract class DmaapTopicFactoryTestBase<T extends Topic> extends BusTopi assertEquals(MY_PARTNER, params.getPartner()); Map<String, String> add = params.getAdditionalProps(); - assertEquals(MY_CONN_TIMEOUT, add.get(DmaapTopicSinkFactory.DME2_EP_CONN_TIMEOUT_PROPERTY)); - assertEquals(MY_READ_TIMEOUT, add.get(DmaapTopicSinkFactory.DME2_READ_TIMEOUT_PROPERTY)); - assertEquals(MY_ROUNDTRIP_TIMEOUT, add.get(DmaapTopicSinkFactory.DME2_ROUNDTRIP_TIMEOUT_PROPERTY)); - assertEquals(MY_ROUTE, add.get(DmaapTopicSinkFactory.DME2_ROUTE_OFFER_PROPERTY)); - assertEquals(MY_STICKINESS, add.get(DmaapTopicSinkFactory.DME2_SESSION_STICKINESS_REQUIRED_PROPERTY)); - assertEquals(MY_SUBCONTEXT, add.get(DmaapTopicSinkFactory.DME2_SUBCONTEXT_PATH_PROPERTY)); - assertEquals(MY_DME_VERSION, add.get(DmaapTopicSinkFactory.DME2_VERSION_PROPERTY)); + assertEquals(MY_CONN_TIMEOUT, add.get(PolicyEndPointProperties.DME2_EP_CONN_TIMEOUT_PROPERTY)); + assertEquals(MY_READ_TIMEOUT, add.get(PolicyEndPointProperties.DME2_READ_TIMEOUT_PROPERTY)); + assertEquals(MY_ROUNDTRIP_TIMEOUT, add.get(PolicyEndPointProperties.DME2_ROUNDTRIP_TIMEOUT_PROPERTY)); + assertEquals(MY_ROUTE, add.get(PolicyEndPointProperties.DME2_ROUTE_OFFER_PROPERTY)); + assertEquals(MY_STICKINESS, add.get(PolicyEndPointProperties.DME2_SESSION_STICKINESS_REQUIRED_PROPERTY)); + assertEquals(MY_SUBCONTEXT, add.get(PolicyEndPointProperties.DME2_SUBCONTEXT_PATH_PROPERTY)); + assertEquals(MY_DME_VERSION, add.get(PolicyEndPointProperties.DME2_VERSION_PROPERTY)); } @Override @@ -81,23 +82,23 @@ public abstract class DmaapTopicFactoryTestBase<T extends Topic> extends BusTopi // check "additional" properties expectNullAddProp(PROPERTY_DMAAP_DME2_EP_CONN_TIMEOUT_SUFFIX, - DmaapTopicSinkFactory.DME2_EP_CONN_TIMEOUT_PROPERTY); + PolicyEndPointProperties.DME2_EP_CONN_TIMEOUT_PROPERTY); expectNullAddProp(PROPERTY_DMAAP_DME2_EP_READ_TIMEOUT_MS_SUFFIX, - DmaapTopicSinkFactory.DME2_READ_TIMEOUT_PROPERTY); + PolicyEndPointProperties.DME2_READ_TIMEOUT_PROPERTY); expectNullAddProp(PROPERTY_DMAAP_DME2_ROUNDTRIP_TIMEOUT_MS_SUFFIX, - DmaapTopicSinkFactory.DME2_ROUNDTRIP_TIMEOUT_PROPERTY); + PolicyEndPointProperties.DME2_ROUNDTRIP_TIMEOUT_PROPERTY); - expectNullAddProp(PROPERTY_DMAAP_DME2_ROUTE_OFFER_SUFFIX, DmaapTopicSinkFactory.DME2_ROUTE_OFFER_PROPERTY); + expectNullAddProp(PROPERTY_DMAAP_DME2_ROUTE_OFFER_SUFFIX, PolicyEndPointProperties.DME2_ROUTE_OFFER_PROPERTY); expectNullAddProp(PROPERTY_DMAAP_DME2_SESSION_STICKINESS_REQUIRED_SUFFIX, - DmaapTopicSinkFactory.DME2_SESSION_STICKINESS_REQUIRED_PROPERTY); + PolicyEndPointProperties.DME2_SESSION_STICKINESS_REQUIRED_PROPERTY); expectNullAddProp(PROPERTY_DMAAP_DME2_SUB_CONTEXT_PATH_SUFFIX, - DmaapTopicSinkFactory.DME2_SUBCONTEXT_PATH_PROPERTY); + PolicyEndPointProperties.DME2_SUBCONTEXT_PATH_PROPERTY); - expectNullAddProp(PROPERTY_DMAAP_DME2_VERSION_SUFFIX, DmaapTopicSinkFactory.DME2_VERSION_PROPERTY); + expectNullAddProp(PROPERTY_DMAAP_DME2_VERSION_SUFFIX, PolicyEndPointProperties.DME2_VERSION_PROPERTY); } @Override diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSinkTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSinkTest.java index 52ba3e9e..9136108a 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSinkTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSinkTest.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. @@ -28,7 +28,7 @@ public class DmaapTopicSinkTest { @Test public void test() { - assertNotNull(DmaapTopicSink.factory); + assertNotNull(DmaapTopicFactories.getSinkFactory()); } } 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 d6187420..b4c2f758 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 @@ -35,6 +35,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; +import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; public class DmaapTopicSourceFactoryTest extends DmaapTopicFactoryTestBase<DmaapTopicSource> { @@ -80,11 +81,11 @@ public class DmaapTopicSourceFactoryTest extends DmaapTopicFactoryTestBase<Dmaap // check default values for source-specific parameters checkDefault(PROPERTY_TOPIC_SOURCE_FETCH_LIMIT_SUFFIX, - params2 -> params2.getFetchLimit() == DmaapTopicSource.DEFAULT_LIMIT_FETCH, + params2 -> params2.getFetchLimit() == PolicyEndPointProperties.DEFAULT_LIMIT_FETCH, null, "", "invalid-limit-number"); checkDefault(PROPERTY_TOPIC_SOURCE_FETCH_TIMEOUT_SUFFIX, - params2 -> params2.getFetchTimeout() == DmaapTopicSource.DEFAULT_TIMEOUT_MS_FETCH, + params2 -> params2.getFetchTimeout() == PolicyEndPointProperties.DEFAULT_TIMEOUT_MS_FETCH, null, "", "invalid-timeout-number"); } @@ -97,8 +98,8 @@ public class DmaapTopicSourceFactoryTest extends DmaapTopicFactoryTestBase<Dmaap BusTopicParams params = factory.params.getFirst(); assertEquals(MY_API_KEY, params.getApiKey()); assertEquals(MY_API_SECRET, params.getApiSecret()); - assertEquals(DmaapTopicSource.DEFAULT_LIMIT_FETCH, params.getFetchLimit()); - assertEquals(DmaapTopicSource.DEFAULT_TIMEOUT_MS_FETCH, params.getFetchTimeout()); + assertEquals(PolicyEndPointProperties.DEFAULT_LIMIT_FETCH, params.getFetchLimit()); + assertEquals(PolicyEndPointProperties.DEFAULT_TIMEOUT_MS_FETCH, params.getFetchTimeout()); } @Test @@ -110,8 +111,8 @@ public class DmaapTopicSourceFactoryTest extends DmaapTopicFactoryTestBase<Dmaap BusTopicParams params = factory.params.getFirst(); assertEquals(null, params.getApiKey()); assertEquals(null, params.getApiSecret()); - assertEquals(DmaapTopicSource.DEFAULT_LIMIT_FETCH, params.getFetchLimit()); - assertEquals(DmaapTopicSource.DEFAULT_TIMEOUT_MS_FETCH, params.getFetchTimeout()); + assertEquals(PolicyEndPointProperties.DEFAULT_LIMIT_FETCH, params.getFetchLimit()); + assertEquals(PolicyEndPointProperties.DEFAULT_TIMEOUT_MS_FETCH, params.getFetchTimeout()); } @Test diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSourceTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSourceTest.java index 6828444a..1735e2ee 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSourceTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicSourceTest.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. @@ -28,7 +28,7 @@ public class DmaapTopicSourceTest { @Test public void test() { - assertNotNull(DmaapTopicSource.factory); + assertNotNull(DmaapTopicFactories.getSourceFactory()); } } diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSinkTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSinkTest.java index 3e7aca01..77452604 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSinkTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSinkTest.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. @@ -28,7 +28,7 @@ public class UebTopicSinkTest { @Test public void test() { - assertNotNull(UebTopicSink.factory); + assertNotNull(UebTopicFactories.getSinkFactory()); } } diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSourceFactoryTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSourceFactoryTest.java index 468805de..81e30756 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSourceFactoryTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSourceFactoryTest.java @@ -35,6 +35,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; +import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; public class UebTopicSourceFactoryTest extends UebTopicFactoryTestBase<UebTopicSource> { @@ -81,11 +82,11 @@ public class UebTopicSourceFactoryTest extends UebTopicFactoryTestBase<UebTopicS // check default values for source-specific parameters checkDefault(PROPERTY_TOPIC_SOURCE_FETCH_LIMIT_SUFFIX, - params2 -> params2.getFetchLimit() == UebTopicSource.DEFAULT_LIMIT_FETCH, + params2 -> params2.getFetchLimit() == PolicyEndPointProperties.DEFAULT_LIMIT_FETCH, null, "", "invalid-limit-number"); checkDefault(PROPERTY_TOPIC_SOURCE_FETCH_TIMEOUT_SUFFIX, - params2 -> params2.getFetchTimeout() == UebTopicSource.DEFAULT_TIMEOUT_MS_FETCH, + params2 -> params2.getFetchTimeout() == PolicyEndPointProperties.DEFAULT_TIMEOUT_MS_FETCH, null, "", "invalid-timeout-number"); } @@ -98,8 +99,8 @@ public class UebTopicSourceFactoryTest extends UebTopicFactoryTestBase<UebTopicS BusTopicParams params = factory.params.getFirst(); assertEquals(MY_API_KEY, params.getApiKey()); assertEquals(MY_API_SECRET, params.getApiSecret()); - assertEquals(UebTopicSource.DEFAULT_LIMIT_FETCH, params.getFetchLimit()); - assertEquals(UebTopicSource.DEFAULT_TIMEOUT_MS_FETCH, params.getFetchTimeout()); + assertEquals(PolicyEndPointProperties.DEFAULT_LIMIT_FETCH, params.getFetchLimit()); + assertEquals(PolicyEndPointProperties.DEFAULT_TIMEOUT_MS_FETCH, params.getFetchTimeout()); } @Test @@ -111,8 +112,8 @@ public class UebTopicSourceFactoryTest extends UebTopicFactoryTestBase<UebTopicS BusTopicParams params = factory.params.getFirst(); assertEquals(null, params.getApiKey()); assertEquals(null, params.getApiSecret()); - assertEquals(UebTopicSource.DEFAULT_LIMIT_FETCH, params.getFetchLimit()); - assertEquals(UebTopicSource.DEFAULT_TIMEOUT_MS_FETCH, params.getFetchTimeout()); + assertEquals(PolicyEndPointProperties.DEFAULT_LIMIT_FETCH, params.getFetchLimit()); + assertEquals(PolicyEndPointProperties.DEFAULT_TIMEOUT_MS_FETCH, params.getFetchTimeout()); assertEquals(true, params.isAllowSelfSignedCerts()); } diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSourceTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSourceTest.java index 11bb3f4d..9ef8af84 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSourceTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSourceTest.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. @@ -28,7 +28,7 @@ public class UebTopicSourceTest { @Test public void test() { - assertNotNull(UebTopicSource.factory); + assertNotNull(UebTopicFactories.getSourceFactory()); } } 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 a32083fa..0255c100 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 @@ -91,10 +91,6 @@ public class BusConsumerTest extends TopicTestBase { } catch (IOException e) { assertEquals(ex, e); - - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - assertEquals(ex, e); } } diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/TopicSinkClientTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/TopicSinkClientTest.java index 07630cd4..e30f38a7 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/TopicSinkClientTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/client/TopicSinkClientTest.java @@ -38,7 +38,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; -import org.onap.policy.common.endpoints.event.comm.TopicEndpoint; +import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager; import org.onap.policy.common.endpoints.event.comm.TopicSink; public class TopicSinkClientTest { @@ -66,14 +66,14 @@ public class TopicSinkClientTest { props.setProperty("noop.sink.topics", TOPIC); // clear all topics and then configure one topic - TopicEndpoint.manager.shutdown(); - TopicEndpoint.manager.addTopicSinks(props); + TopicEndpointManager.getManager().shutdown(); + TopicEndpointManager.getManager().addTopicSinks(props); } @AfterClass public static void tearDown() { // clear all topics after the tests - TopicEndpoint.manager.shutdown(); + TopicEndpointManager.getManager().shutdown(); } /** @@ -82,7 +82,7 @@ public class TopicSinkClientTest { @Test public void testGetTopicSinks() throws Exception { - sink = TopicEndpoint.manager.getNoopTopicSink(TOPIC); + sink = TopicEndpointManager.getManager().getNoopTopicSink(TOPIC); assertNotNull(sink); final AtomicReference<String> evref = new AtomicReference<>(null); @@ -106,7 +106,7 @@ public class TopicSinkClientTest { @Test public void testTopicSinkClient_GetTopic() throws TopicSinkClientException { - assertEquals(TOPIC, new TopicSinkClient(TopicEndpoint.manager.getNoopTopicSink(TOPIC)).getTopic()); + assertEquals(TOPIC, new TopicSinkClient(TopicEndpointManager.getManager().getNoopTopicSink(TOPIC)).getTopic()); assertEquals(TOPIC, new TopicSinkClient(TOPIC).getTopic()); assertThatThrownBy(() -> new TopicSinkClient((TopicSink) null)).isInstanceOf(IllegalArgumentException.class); 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 f559b112..2aaf1367 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 @@ -25,8 +25,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -40,7 +38,10 @@ 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.client.HttpClientConfigException; +import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance; import org.onap.policy.common.endpoints.http.server.HttpServletServer; +import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; import org.onap.policy.common.endpoints.http.server.internal.JettyJerseyServer; import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; import org.onap.policy.common.utils.network.NetworkUtil; @@ -72,7 +73,7 @@ public class HttpClientTest { /* echo server - http + no auth */ final HttpServletServer echoServerNoAuth = - HttpServletServer.factory.build("echo", LOCALHOST, 6666, "/", false, true); + HttpServletServerFactoryInstance.getServerFactory().build("echo", LOCALHOST, 6666, "/", false, true); echoServerNoAuth.addServletPackage("/*", HttpClientTest.class.getPackage().getName()); echoServerNoAuth.waitedStart(5000); @@ -112,8 +113,8 @@ public class HttpClientTest { /* echo server - https + basic auth */ - final HttpServletServer echoServerAuth = - HttpServletServer.factory.build("echo", true, LOCALHOST, 6667, "/", false, true); + final HttpServletServer echoServerAuth = HttpServletServerFactoryInstance.getServerFactory() + .build("echo", true, LOCALHOST, 6667, "/", false, true); echoServerAuth.setBasicAuthentication("x", "y", null); echoServerAuth.addServletPackage("/*", HttpClientTest.class.getPackage().getName()); echoServerAuth.addFilterClass("/*", TestFilter.class.getName()); @@ -132,7 +133,7 @@ public class HttpClientTest { */ @Before public void setUp() { - HttpClient.factory.destroy(); + HttpClientFactoryInstance.getClientFactory().destroy(); MyGsonProvider.resetSome(); MyJacksonProvider.resetSome(); @@ -143,8 +144,8 @@ public class HttpClientTest { */ @AfterClass public static void tearDownAfterClass() { - HttpServletServer.factory.destroy(); - HttpClient.factory.destroy(); + HttpServletServerFactoryInstance.getServerFactory().destroy(); + HttpClientFactoryInstance.getClientFactory().destroy(); if (savedValuesMap.containsKey(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME)) { System.setProperty(JettyJerseyServer.SYSTEM_KEYSTORE_PROPERTY_NAME, @@ -254,10 +255,11 @@ public class HttpClientTest { @Test public void testHttpPutAuthClient_JacksonProvider() throws Exception { - 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.getName()).build()); + final HttpClient client = HttpClientFactoryInstance.getClientFactory() + .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.getName()).build()); Entity<MyEntity> entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON); final Response response = client.put(HELLO, entity, Collections.emptyMap()); @@ -273,10 +275,11 @@ public class HttpClientTest { @Test public void testHttpPutAuthClient_GsonProvider() throws Exception { - 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.getName()).build()); + final HttpClient client = HttpClientFactoryInstance.getClientFactory() + .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.getName()).build()); Entity<MyEntity> entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON); final Response response = client.put(HELLO, entity, Collections.emptyMap()); @@ -368,21 +371,22 @@ public class HttpClientTest { httpProperties.setProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES + DOT_PDP + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true"); - final List<HttpServletServer> servers = HttpServletServer.factory.build(httpProperties); + final List<HttpServletServer> servers = + HttpServletServerFactoryInstance.getServerFactory().build(httpProperties); assertEquals(2, servers.size()); - final List<HttpClient> clients = HttpClient.factory.build(httpProperties); + final List<HttpClient> clients = HttpClientFactoryInstance.getClientFactory().build(httpProperties); assertEquals(2, clients.size()); for (final HttpServletServer server : servers) { server.waitedStart(10000); } - final HttpClient clientPap = HttpClient.factory.get("PAP"); + final HttpClient clientPap = HttpClientFactoryInstance.getClientFactory().get("PAP"); final Response response = clientPap.get(); assertEquals(200, response.getStatus()); - final HttpClient clientPdp = HttpClient.factory.get("PDP"); + final HttpClient clientPdp = HttpClientFactoryInstance.getClientFactory().get("PDP"); final Response response2 = clientPdp.get("test"); assertEquals(500, response2.getStatus()); @@ -425,7 +429,7 @@ public class HttpClientTest { + PolicyEndPointProperties.PROPERTY_HTTP_SERIALIZATION_PROVIDER, MyJacksonProvider.class.getName()); - final List<HttpClient> clients = HttpClient.factory.build(httpProperties); + final List<HttpClient> clients = HttpClientFactoryInstance.getClientFactory().build(httpProperties); assertEquals(2, clients.size()); Entity<MyEntity> entity = Entity.entity(new MyEntity(MY_VALUE), MediaType.APPLICATION_JSON); @@ -433,7 +437,7 @@ public class HttpClientTest { // use gson client MyGsonProvider.resetSome(); MyJacksonProvider.resetSome(); - HttpClient client = HttpClient.factory.get("GSON"); + HttpClient client = HttpClientFactoryInstance.getClientFactory().get("GSON"); Response response = client.put(HELLO, entity, Collections.emptyMap()); String body = HttpClient.getBody(response, String.class); @@ -447,7 +451,7 @@ public class HttpClientTest { // use jackson client MyGsonProvider.resetSome(); MyJacksonProvider.resetSome(); - client = HttpClient.factory.get("JACKSON"); + client = HttpClientFactoryInstance.getClientFactory().get("JACKSON"); response = client.put(HELLO, entity, Collections.emptyMap()); body = HttpClient.getBody(response, String.class); @@ -459,18 +463,19 @@ public class HttpClientTest { assertFalse(MyGsonProvider.hasWrittenSome()); } - private HttpClient getAuthHttpClient() - throws KeyManagementException, NoSuchAlgorithmException, ClassNotFoundException { - 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 getAuthHttpClient() throws HttpClientConfigException { + return HttpClientFactoryInstance.getClientFactory() + .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) - .userName(null).password(null).managed(true).build()); + throws HttpClientConfigException { + return HttpClientFactoryInstance.getClientFactory() + .build(BusTopicParams.builder().clientName(clientName).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/HttpExceptionsTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpExceptionsTest.java new file mode 100644 index 00000000..85135759 --- /dev/null +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpExceptionsTest.java @@ -0,0 +1,33 @@ +/* + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.common.endpoints.http.server.test; + +import org.junit.Test; +import org.onap.policy.common.endpoints.http.client.HttpClientConfigException; +import org.onap.policy.common.utils.test.ExceptionsTester; + +public class HttpExceptionsTest extends ExceptionsTester { + + @Test + public void testHttpClientConfigException() { + test(HttpClientConfigException.class); + } +} 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 c6ff2f32..f2b53648 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 @@ -39,6 +39,7 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.onap.policy.common.endpoints.http.server.HttpServletServer; +import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; import org.onap.policy.common.utils.gson.GsonTestUtils; import org.onap.policy.common.utils.network.NetworkUtil; import org.slf4j.Logger; @@ -79,7 +80,7 @@ public class HttpServerTest { incrementPort(); portUrl = LOCALHOST_PREFIX + port; - HttpServletServer.factory.destroy(); + HttpServletServerFactoryInstance.getServerFactory().destroy(); MyJacksonProvider.resetSome(); MyGsonProvider.resetSome(); @@ -91,19 +92,20 @@ public class HttpServerTest { @AfterClass public static void tearDownAfterClass() { - HttpServletServer.factory.destroy(); + HttpServletServerFactoryInstance.getServerFactory().destroy(); } @Test public void testDefaultPackageServer() throws Exception { logger.info("-- testDefaultPackageServer() --"); - HttpServletServer server = HttpServletServer.factory.build("echo", LOCALHOST, port, "/", false, true); + HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory() + .build("echo", LOCALHOST, port, "/", false, true); server.addServletPackage("/*", this.getClass().getPackage().getName()); server.addFilterClass("/*", TestFilter.class.getName()); server.waitedStart(5000); - assertTrue(HttpServletServer.factory.get(port).isAlive()); + assertTrue(HttpServletServerFactoryInstance.getServerFactory().get(port).isAlive()); RestEchoReqResp request = new RestEchoReqResp(); request.setRequestId(100); @@ -118,14 +120,15 @@ public class HttpServerTest { public void testJacksonPackageServer() throws Exception { logger.info("-- testJacksonPackageServer() --"); - HttpServletServer server = HttpServletServer.factory.build("echo", LOCALHOST, port, "/", false, true); + HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory() + .build("echo", LOCALHOST, port, "/", false, true); server.setSerializationProvider(MyJacksonProvider.class.getName()); server.addServletPackage("/*", this.getClass().getPackage().getName()); server.addFilterClass("/*", TestFilter.class.getName()); server.waitedStart(5000); - assertTrue(HttpServletServer.factory.get(port).isAlive()); + assertTrue(HttpServletServerFactoryInstance.getServerFactory().get(port).isAlive()); RestEchoReqResp request = new RestEchoReqResp(); request.setRequestId(100); @@ -146,14 +149,15 @@ public class HttpServerTest { public void testGsonPackageServer() throws Exception { logger.info("-- testGsonPackageServer() --"); - HttpServletServer server = HttpServletServer.factory.build("echo", LOCALHOST, port, "/", false, true); + HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory() + .build("echo", LOCALHOST, port, "/", false, true); server.setSerializationProvider(MyGsonProvider.class.getName()); server.addServletPackage("/*", this.getClass().getPackage().getName()); server.addFilterClass("/*", TestFilter.class.getName()); server.waitedStart(5000); - assertTrue(HttpServletServer.factory.get(port).isAlive()); + assertTrue(HttpServletServerFactoryInstance.getServerFactory().get(port).isAlive()); RestEchoReqResp request = new RestEchoReqResp(); request.setRequestId(100); @@ -174,12 +178,13 @@ public class HttpServerTest { public void testDefaultClassServer() throws Exception { logger.info("-- testDefaultClassServer() --"); - HttpServletServer server = HttpServletServer.factory.build("echo", LOCALHOST, port, "/", false, true); + HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory() + .build("echo", LOCALHOST, port, "/", false, true); server.addServletClass("/*", RestEchoService.class.getName()); server.addFilterClass("/*", TestFilter.class.getName()); server.waitedStart(5000); - assertTrue(HttpServletServer.factory.get(port).isAlive()); + assertTrue(HttpServletServerFactoryInstance.getServerFactory().get(port).isAlive()); RestEchoReqResp request = new RestEchoReqResp(); request.setRequestId(100); @@ -194,13 +199,14 @@ public class HttpServerTest { public void testJacksonClassServer() throws Exception { logger.info("-- testJacksonClassServer() --"); - HttpServletServer server = HttpServletServer.factory.build("echo", LOCALHOST, port, "/", false, true); + HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory() + .build("echo", LOCALHOST, port, "/", false, true); server.setSerializationProvider(MyJacksonProvider.class.getName()); server.addServletClass("/*", RestEchoService.class.getName()); server.addFilterClass("/*", TestFilter.class.getName()); server.waitedStart(5000); - assertTrue(HttpServletServer.factory.get(port).isAlive()); + assertTrue(HttpServletServerFactoryInstance.getServerFactory().get(port).isAlive()); RestEchoReqResp request = new RestEchoReqResp(); request.setRequestId(100); @@ -221,13 +227,14 @@ public class HttpServerTest { public void testGsonClassServer() throws Exception { logger.info("-- testGsonClassServer() --"); - HttpServletServer server = HttpServletServer.factory.build("echo", LOCALHOST, port, "/", false, true); + HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory() + .build("echo", LOCALHOST, port, "/", false, true); server.setSerializationProvider(MyGsonProvider.class.getName()); server.addServletClass("/*", RestEchoService.class.getName()); server.addFilterClass("/*", TestFilter.class.getName()); server.waitedStart(5000); - assertTrue(HttpServletServer.factory.get(port).isAlive()); + assertTrue(HttpServletServerFactoryInstance.getServerFactory().get(port).isAlive()); RestEchoReqResp request = new RestEchoReqResp(); request.setRequestId(100); @@ -246,7 +253,8 @@ public class HttpServerTest { @Test public void testSerialize() { - HttpServletServer server = HttpServletServer.factory.build("echo", LOCALHOST, port, "/", false, true); + HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory() + .build("echo", LOCALHOST, port, "/", false, true); server.addServletPackage("/*", this.getClass().getPackage().getName()); server.addFilterClass("/*", TestFilter.class.getName()); @@ -258,13 +266,14 @@ public class HttpServerTest { public void testSingleServer() throws Exception { logger.info("-- testSingleServer() --"); - HttpServletServer server = HttpServletServer.factory.build("echo", LOCALHOST, port, "/", false, true); + HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory() + .build("echo", LOCALHOST, port, "/", false, true); server.addServletPackage("/*", this.getClass().getPackage().getName()); server.addFilterClass("/*", TestFilter.class.getName()); server.waitedStart(5000); - assertTrue(HttpServletServer.factory.get(port).isAlive()); - assertFalse(HttpServletServer.factory.get(port).isAaf()); + assertTrue(HttpServletServerFactoryInstance.getServerFactory().get(port).isAlive()); + assertFalse(HttpServletServerFactoryInstance.getServerFactory().get(port).isAaf()); String response = http(portUrl + JUNIT_ECHO_HELLO); assertEquals(HELLO, response); @@ -274,32 +283,34 @@ public class HttpServerTest { response = http(portUrl + "/junit/echo/hello?block=true"); assertEquals("FILTERED", response); - assertTrue(HttpServletServer.factory.get(port).isAlive()); - assertEquals(1, HttpServletServer.factory.inventory().size()); + assertTrue(HttpServletServerFactoryInstance.getServerFactory().get(port).isAlive()); + assertEquals(1, HttpServletServerFactoryInstance.getServerFactory().inventory().size()); server.setAafAuthentication("/*"); - assertTrue(HttpServletServer.factory.get(port).isAaf()); + assertTrue(HttpServletServerFactoryInstance.getServerFactory().get(port).isAaf()); - HttpServletServer.factory.destroy(port); - assertEquals(0, HttpServletServer.factory.inventory().size()); + HttpServletServerFactoryInstance.getServerFactory().destroy(port); + assertEquals(0, HttpServletServerFactoryInstance.getServerFactory().inventory().size()); } @Test public void testMultipleServers() throws Exception { logger.info("-- testMultipleServers() --"); - HttpServletServer server1 = HttpServletServer.factory.build("echo-1", false,LOCALHOST, port, "/", true, true); + HttpServletServer server1 = HttpServletServerFactoryInstance.getServerFactory() + .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 = HttpServletServerFactoryInstance.getServerFactory() + .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()); + assertTrue(HttpServletServerFactoryInstance.getServerFactory().get(port).isAlive()); + assertTrue(HttpServletServerFactoryInstance.getServerFactory().get(port2).isAlive()); String response = http(portUrl + JUNIT_ECHO_HELLO); assertTrue(HELLO.equals(response)); @@ -312,8 +323,8 @@ public class HttpServerTest { assertThatThrownBy(() -> http(LOCALHOST_PREFIX + port2 + SWAGGER_JSON)).isInstanceOf(IOException.class); - HttpServletServer.factory.destroy(); - assertTrue(HttpServletServer.factory.inventory().isEmpty()); + HttpServletServerFactoryInstance.getServerFactory().destroy(); + assertTrue(HttpServletServerFactoryInstance.getServerFactory().inventory().isEmpty()); } @Test @@ -322,11 +333,12 @@ public class HttpServerTest { String randomName = UUID.randomUUID().toString(); - HttpServletServer server = HttpServletServer.factory.build(randomName, LOCALHOST, port, "/", false, true); + HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory() + .build(randomName, LOCALHOST, port, "/", false, true); server.addServletPackage("/*", this.getClass().getPackage().getName()); server.waitedStart(5000); - assertTrue(HttpServletServer.factory.get(port).isAlive()); + assertTrue(HttpServletServerFactoryInstance.getServerFactory().get(port).isAlive()); String response = http(portUrl + JUNIT_ECHO_HELLO); assertTrue(HELLO.equals(response)); @@ -334,8 +346,8 @@ public class HttpServerTest { response = http(portUrl + "/junit/endpoints/http/servers"); assertTrue(response.contains(randomName)); - HttpServletServer.factory.destroy(); - assertTrue(HttpServletServer.factory.inventory().isEmpty()); + HttpServletServerFactoryInstance.getServerFactory().destroy(); + assertTrue(HttpServletServerFactoryInstance.getServerFactory().inventory().isEmpty()); } @Test @@ -343,17 +355,18 @@ public class HttpServerTest { logger.info("-- testServiceClass() --"); String randomName = UUID.randomUUID().toString(); - HttpServletServer server = HttpServletServer.factory.build(randomName, LOCALHOST, port, "/", false, true); + HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory() + .build(randomName, LOCALHOST, port, "/", false, true); server.addServletClass("/*", RestEchoService.class.getName()); server.waitedStart(5000); - assertTrue(HttpServletServer.factory.get(port).isAlive()); + assertTrue(HttpServletServerFactoryInstance.getServerFactory().get(port).isAlive()); String response = http(portUrl + JUNIT_ECHO_HELLO); assertTrue(HELLO.equals(response)); - HttpServletServer.factory.destroy(); - assertTrue(HttpServletServer.factory.inventory().isEmpty()); + HttpServletServerFactoryInstance.getServerFactory().destroy(); + assertTrue(HttpServletServerFactoryInstance.getServerFactory().inventory().isEmpty()); } @Test @@ -362,12 +375,13 @@ public class HttpServerTest { String randomName = UUID.randomUUID().toString(); - HttpServletServer server = HttpServletServer.factory.build(randomName, LOCALHOST, port, "/", false, true); + HttpServletServer server = HttpServletServerFactoryInstance.getServerFactory() + .build(randomName, LOCALHOST, port, "/", false, true); server.addServletClass("/*", RestEchoService.class.getName()); server.addServletClass("/*", RestEndpoints.class.getName()); server.waitedStart(5000); - assertTrue(HttpServletServer.factory.get(port).isAlive()); + assertTrue(HttpServletServerFactoryInstance.getServerFactory().get(port).isAlive()); String response = http(portUrl + JUNIT_ECHO_HELLO); assertTrue(HELLO.equals(response)); @@ -375,8 +389,8 @@ public class HttpServerTest { response = http(portUrl + "/junit/endpoints/http/servers"); assertTrue(response.contains(randomName)); - HttpServletServer.factory.destroy(); - assertTrue(HttpServletServer.factory.inventory().isEmpty()); + HttpServletServerFactoryInstance.getServerFactory().destroy(); + assertTrue(HttpServletServerFactoryInstance.getServerFactory().inventory().isEmpty()); } /** diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestEndpoints.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestEndpoints.java index fe199645..6ada15c5 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestEndpoints.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/RestEndpoints.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-endpoints * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017, 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. @@ -28,23 +28,23 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.onap.policy.common.endpoints.http.server.HttpServletServer; +import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance; @Path("/junit/endpoints") public class RestEndpoints { /** * Returns the http servers. - * + * * @return the list of servers as a string */ @GET @Path("http/servers") @Produces(MediaType.TEXT_PLAIN) - public String httpServers() { - List<HttpServletServer> servers = - HttpServletServer.factory.inventory(); + public String httpServers() { + List<HttpServletServer> servers = HttpServletServerFactoryInstance.getServerFactory().inventory(); return servers.toString(); } - - + + } diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/CommonTestData.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/CommonTestData.java index 80d1e865..346ac5d6 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/CommonTestData.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/CommonTestData.java @@ -1,6 +1,8 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 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. @@ -40,7 +42,7 @@ import org.onap.policy.common.utils.coder.StandardCoder; */ public class CommonTestData { - public static final String REST_SERVER_PASSWORD = "zb!XztG34"; + public static final String REST_SERVER_PASS = "zb!XztG34"; public static final String REST_SERVER_USER = "healthcheck"; public static final int REST_SERVER_PORT = 6969; public static final String REST_SERVER_HOST = "0.0.0.0"; @@ -50,9 +52,11 @@ public class CommonTestData { public static final String TOPIC_NAME = "POLICY-PDP-PAP"; public static final String TOPIC_INFRA = "dmaap"; public static final String TOPIC_SERVER = "message-router"; - public static final List<TopicParameters> TOPIC_PARAMS = + + protected static final List<TopicParameters> TOPIC_PARAMS = Arrays.asList(getTopicParameters(TOPIC_NAME, TOPIC_INFRA, TOPIC_SERVER)); - public static final Coder coder = new StandardCoder(); + + protected static final Coder coder = new StandardCoder(); /** * Create topic parameters for test cases. @@ -102,7 +106,7 @@ public class CommonTestData { map.put("host", REST_SERVER_HOST); map.put("port", REST_SERVER_PORT); map.put("userName", REST_SERVER_USER); - map.put("password", REST_SERVER_PASSWORD); + map.put("password", REST_SERVER_PASS); } return map; @@ -133,7 +137,6 @@ public class CommonTestData { */ public String getParameterGroupAsString(String filePath) throws IOException { File file = new File(filePath); - String json = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8); - return json; + return new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8); } } diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/RestServerParametersTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/RestServerParametersTest.java index ca2b3c4c..58bf98b3 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/RestServerParametersTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/RestServerParametersTest.java @@ -1,6 +1,8 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 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,7 +43,7 @@ public class RestServerParametersTest { private static final Coder coder = new StandardCoder(); @Test - public void test() throws Exception { + public void test() { final RestServerParameters restServerParameters = testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class); final GroupValidationResult validationResult = restServerParameters.validate(); @@ -49,13 +51,13 @@ public class RestServerParametersTest { assertEquals(CommonTestData.REST_SERVER_HOST, restServerParameters.getHost()); assertEquals(CommonTestData.REST_SERVER_PORT, restServerParameters.getPort()); assertEquals(CommonTestData.REST_SERVER_USER, restServerParameters.getUserName()); - assertEquals(CommonTestData.REST_SERVER_PASSWORD, restServerParameters.getPassword()); + assertEquals(CommonTestData.REST_SERVER_PASS, restServerParameters.getPassword()); assertEquals(CommonTestData.REST_SERVER_HTTPS, restServerParameters.isHttps()); assertEquals(CommonTestData.REST_SERVER_AAF, restServerParameters.isAaf()); } @Test - public void testValidate() throws Exception { + public void testValidate() { final RestServerParameters restServerParameters = testData.toObject(testData.getRestServerParametersMap(false), RestServerParameters.class); final GroupValidationResult result = restServerParameters.validate(); diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroupTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroupTest.java index eaf0b2a9..db26a1a4 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroupTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/parameters/TopicParameterGroupTest.java @@ -1,6 +1,8 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 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. @@ -40,7 +42,7 @@ public class TopicParameterGroupTest { private static final Coder coder = new StandardCoder(); @Test - public void test() throws Exception { + public void test() { final TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParameterGroupMap(false), TopicParameterGroup.class); final GroupValidationResult validationResult = topicParameterGroup.validate(); @@ -50,7 +52,7 @@ public class TopicParameterGroupTest { } @Test - public void testValidate() throws Exception { + public void testValidate() { final TopicParameterGroup topicParameterGroup = testData.toObject(testData.getTopicParameterGroupMap(false), TopicParameterGroup.class); final GroupValidationResult result = topicParameterGroup.validate(); diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/NetLoggerUtilTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/NetLoggerUtilTest.java index 2860377e..1e8c0316 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/NetLoggerUtilTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/NetLoggerUtilTest.java @@ -31,6 +31,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.features.NetLoggerFeatureApi; +import org.onap.policy.common.endpoints.features.NetLoggerFeatureProviders; import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType; import org.slf4j.Logger; @@ -51,7 +52,7 @@ public class NetLoggerUtilTest { */ @BeforeClass public static void setUp() { - netLoggerFeature = (NetLoggerFeature) NetLoggerFeatureApi.providers.getList().get(0); + netLoggerFeature = (NetLoggerFeature) NetLoggerFeatureProviders.getProviders().getList().get(0); } /** diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/ParameterUtilsTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/ParameterUtilsTest.java index 7e5c3a12..06c16e9c 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/ParameterUtilsTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/ParameterUtilsTest.java @@ -1,6 +1,8 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 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. @@ -34,6 +36,7 @@ import org.onap.policy.common.endpoints.parameters.TopicParameterGroup; * @author Ajith Sreekumar (ajith.sreekumar@est.tech) */ public class ParameterUtilsTest { + private static final String SERVERS = ".servers"; /** * Test getTopicProperties from TopicParameterGroup. @@ -49,9 +52,9 @@ public class ParameterUtilsTest { assertEquals(CommonTestData.TOPIC_NAME, topicProperties.getProperty(CommonTestData.TOPIC_INFRA + ".sink.topics")); assertEquals(CommonTestData.TOPIC_SERVER, topicProperties - .getProperty(CommonTestData.TOPIC_INFRA + ".source.topics." + CommonTestData.TOPIC_NAME + ".servers")); + .getProperty(CommonTestData.TOPIC_INFRA + ".source.topics." + CommonTestData.TOPIC_NAME + SERVERS)); assertEquals(CommonTestData.TOPIC_SERVER, topicProperties - .getProperty(CommonTestData.TOPIC_INFRA + ".sink.topics." + CommonTestData.TOPIC_NAME + ".servers")); + .getProperty(CommonTestData.TOPIC_INFRA + ".sink.topics." + CommonTestData.TOPIC_NAME + SERVERS)); } @Test @@ -62,12 +65,12 @@ public class ParameterUtilsTest { assertEquals(CommonTestData.TOPIC_NAME, topicProperties.getProperty(CommonTestData.TOPIC_INFRA + ".source.topics")); assertEquals(CommonTestData.TOPIC_SERVER, topicProperties - .getProperty(CommonTestData.TOPIC_INFRA + ".source.topics." + CommonTestData.TOPIC_NAME + ".servers")); + .getProperty(CommonTestData.TOPIC_INFRA + ".source.topics." + CommonTestData.TOPIC_NAME + SERVERS)); ParameterUtils.updateTopicProperties(topicProperties, "sink", CommonTestData.TOPIC_INFRA, CommonTestData.TOPIC_NAME, Arrays.asList(CommonTestData.TOPIC_SERVER)); assertEquals(CommonTestData.TOPIC_NAME, topicProperties.getProperty(CommonTestData.TOPIC_INFRA + ".sink.topics")); assertEquals(CommonTestData.TOPIC_SERVER, topicProperties - .getProperty(CommonTestData.TOPIC_INFRA + ".sink.topics." + CommonTestData.TOPIC_NAME + ".servers")); + .getProperty(CommonTestData.TOPIC_INFRA + ".sink.topics." + CommonTestData.TOPIC_NAME + SERVERS)); } } |