summaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/test/java/org/onap
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-06-24 15:46:36 -0400
committerJim Hahn <jrh3@att.com>2019-06-26 08:55:15 -0400
commit67fcc6f6abb7904ecd4b4444fa23b355cf9fd4ae (patch)
treef5c63d96a4d337e8210f4d83c3dd14caf8e1c051 /policy-endpoints/src/test/java/org/onap
parentd1ab0ec8471deeb7739206dc2ef0aac3dc5b245f (diff)
Fix some sonar issues in policy-endpoints
Refactored various classes to reduce cyclomatic complexity. Introduced some endpoint utility classes to facilitate extraction and conversion of property values, and populating of common "builder" values. Change-Id: Ie1c91cd94cb54700dc9127f72780b4d94b82ec39 Issue-ID: POLICY-1791 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'policy-endpoints/src/test/java/org/onap')
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicPropertyBuilder.java4
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicEndpointTest.java5
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicFactoryTest.java3
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/TopicTestBase.java4
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicPropertyBuilder.java4
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSinkFactoryTest.java10
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSourceFactoryTest.java14
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusConsumerTest.java2
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusPublisherTest.java20
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/BusTopicParamsTest.java2
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSourceTest.java1
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedDmaapTopicSourceTest.java8
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedUebTopicSourceTest.java1
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/TopicBaseTest.java1
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpClientTest.java4
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/HttpServerTest.java23
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyGsonProvider.java10
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyJacksonProvider.java10
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/JsonListenerTest.java4
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/ScoListenerTest.java4
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/NetLoggerUtilTest.java15
-rw-r--r--policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/PropertyUtilsTest.java108
22 files changed, 197 insertions, 60 deletions
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicPropertyBuilder.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicPropertyBuilder.java
index 3b63796c..dff3f788 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicPropertyBuilder.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/DmaapTopicPropertyBuilder.java
@@ -73,7 +73,7 @@ public class DmaapTopicPropertyBuilder extends TopicPropertyBuilder {
public static final String MY_SUBCONTEXT = "my-subcontext";
public static final String MY_DME_VERSION = "my-version";
public static final String MY_AAF_MECHID = "my-aaf-mechid";
- public static final String MY_AAF_PASSWD = "my-aaf-passwd";
+ public static final String MY_AAF_PASS = "my-aaf-passwd";
/**
* Constructs the object.
@@ -99,7 +99,7 @@ public class DmaapTopicPropertyBuilder extends TopicPropertyBuilder {
setTopicProperty(PROPERTY_MANAGED_SUFFIX, "true");
setTopicProperty(PROPERTY_HTTP_HTTPS_SUFFIX, "true");
setTopicProperty(PROPERTY_TOPIC_AAF_MECHID_SUFFIX, MY_AAF_MECHID);
- setTopicProperty(PROPERTY_TOPIC_AAF_PASSWORD_SUFFIX, MY_AAF_PASSWD);
+ setTopicProperty(PROPERTY_TOPIC_AAF_PASSWORD_SUFFIX, MY_AAF_PASS);
setTopicProperty(PROPERTY_DMAAP_DME2_AFT_ENVIRONMENT_SUFFIX, MY_AFT_ENV);
setTopicProperty(PROPERTY_ALLOW_SELF_SIGNED_CERTIFICATES_SUFFIX, "true");
setTopicProperty(PROPERTY_TOPIC_API_KEY_SUFFIX, MY_API_KEY);
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicEndpointTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicEndpointTest.java
index 5bbc80cd..8e916ba0 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicEndpointTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicEndpointTest.java
@@ -40,13 +40,14 @@ public abstract class NoopTopicEndpointTest<F extends NoopTopicFactory<T>, T ext
protected final F factory;
protected T endpoint;
- protected abstract boolean io(String message);
-
public NoopTopicEndpointTest(F factory) {
this.factory = factory;
}
+ protected abstract boolean io(String message);
+
@Before
+ @Override
public void setUp() {
super.setUp();
this.endpoint = this.factory.build(servers, MY_TOPIC);
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicFactoryTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicFactoryTest.java
index 16d9e539..1f7506f8 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicFactoryTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/NoopTopicFactoryTest.java
@@ -52,6 +52,7 @@ public abstract class NoopTopicFactoryTest<F extends NoopTopicFactory<T>, T exte
* Creates the object to be tested.
*/
@Before
+ @Override
public void setUp() {
super.setUp();
initFactory();
@@ -164,12 +165,14 @@ public abstract class NoopTopicFactoryTest<F extends NoopTopicFactory<T>, T exte
}
@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/TopicTestBase.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/TopicTestBase.java
index 326ec042..8b75fa35 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/TopicTestBase.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/TopicTestBase.java
@@ -46,7 +46,7 @@ public class TopicTestBase {
public static final String MY_LAT = "my-lat";
public static final String MY_LONG = "my-long";
public static final String MY_PARTNER = "my-partner";
- public static final String MY_PASSWD = "my-pass";
+ public static final String MY_PASS = "my-pass";
public static final int MY_PORT = 102;
public static final String MY_TOPIC = "my-topic";
public static final String MY_EFFECTIVE_TOPIC = "my-effective-topic";
@@ -116,7 +116,7 @@ public class TopicTestBase {
.consumerGroup(MY_CONS_GROUP).consumerInstance(MY_CONS_INST).environment(MY_ENV)
.fetchLimit(MY_FETCH_LIMIT).fetchTimeout(MY_FETCH_TIMEOUT).hostname(MY_HOST).latitude(MY_LAT)
.longitude(MY_LONG).managed(true).partitionId(MY_PARTITION).partner(MY_PARTNER)
- .password(MY_PASSWD).port(MY_PORT).servers(servers).topic(MY_TOPIC)
+ .password(MY_PASS).port(MY_PORT).servers(servers).topic(MY_TOPIC)
.effectiveTopic(MY_EFFECTIVE_TOPIC).useHttps(true).userName(MY_USERNAME);
}
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicPropertyBuilder.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicPropertyBuilder.java
index 3ac7d9ae..6119284f 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicPropertyBuilder.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicPropertyBuilder.java
@@ -51,7 +51,7 @@ public class UebTopicPropertyBuilder extends TopicPropertyBuilder {
public static final String TOPIC2 = "my-topic-2";
public static final String MY_AAF_MECHID = "my-aaf-mechid";
- public static final String MY_AAF_PASSWD = "my-aaf-passwd";
+ public static final String MY_AAF_PASS = "my-aaf-passwd";
/**
* Constructs the object.
@@ -77,7 +77,7 @@ public class UebTopicPropertyBuilder extends TopicPropertyBuilder {
setTopicProperty(PROPERTY_MANAGED_SUFFIX, "true");
setTopicProperty(PROPERTY_HTTP_HTTPS_SUFFIX, "true");
setTopicProperty(PROPERTY_TOPIC_AAF_MECHID_SUFFIX, MY_AAF_MECHID);
- setTopicProperty(PROPERTY_TOPIC_AAF_PASSWORD_SUFFIX, MY_AAF_PASSWD);
+ setTopicProperty(PROPERTY_TOPIC_AAF_PASSWORD_SUFFIX, MY_AAF_PASS);
setTopicProperty(PROPERTY_DMAAP_DME2_AFT_ENVIRONMENT_SUFFIX, MY_AFT_ENV);
setTopicProperty(PROPERTY_ALLOW_SELF_SIGNED_CERTIFICATES_SUFFIX, "true");
setTopicProperty(PROPERTY_TOPIC_API_KEY_SUFFIX, MY_API_KEY);
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSinkFactoryTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSinkFactoryTest.java
index 10d61f60..4896a9df 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSinkFactoryTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSinkFactoryTest.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 UebTopicSinkFactoryTest extends UebTopicFactoryTestBase<UebTopicSin
* Creates the object to be tested.
*/
@Before
+ @Override
public void setUp() {
super.setUp();
@@ -53,12 +54,14 @@ public class UebTopicSinkFactoryTest extends UebTopicFactoryTestBase<UebTopicSin
}
@Test
+ @Override
public void testBuildBusTopicParams() {
super.testBuildBusTopicParams();
super.testBuildBusTopicParams_Ex();
}
@Test
+ @Override
public void testBuildListOfStringString() {
super.testBuildListOfStringString();
@@ -68,11 +71,12 @@ public class UebTopicSinkFactoryTest extends UebTopicFactoryTestBase<UebTopicSin
}
@Test
+ @Override
public void testBuildProperties() {
super.testBuildProperties();
super.testBuildProperties_Variations();
super.testBuildProperties_Multiple();
-
+
initFactory();
assertEquals(1, buildTopics(makePropBuilder().makeTopic(MY_TOPIC).build()).size());
@@ -82,12 +86,14 @@ public class UebTopicSinkFactoryTest extends UebTopicFactoryTestBase<UebTopicSin
}
@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/UebTopicSourceFactoryTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/UebTopicSourceFactoryTest.java
index 73e3930d..468805de 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
@@ -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 UebTopicSourceFactoryTest extends UebTopicFactoryTestBase<UebTopicS
* Creates the object to be tested.
*/
@Before
+ @Override
public void setUp() {
super.setUp();
@@ -56,14 +57,16 @@ public class UebTopicSourceFactoryTest extends UebTopicFactoryTestBase<UebTopicS
}
@Test
+ @Override
public void testBuildBusTopicParams() {
super.testBuildBusTopicParams();
super.testBuildBusTopicParams_Ex();
}
@Test
+ @Override
public void testBuildProperties() {
-
+
super.testBuildProperties();
// check source-specific parameters that were used
@@ -72,7 +75,7 @@ public class UebTopicSourceFactoryTest extends UebTopicFactoryTestBase<UebTopicS
assertEquals(MY_CONS_INST, params.getConsumerInstance());
assertEquals(MY_FETCH_LIMIT, params.getFetchLimit());
assertEquals(MY_FETCH_TIMEOUT, params.getFetchTimeout());
-
+
super.testBuildProperties_Variations();
super.testBuildProperties_Multiple();
@@ -80,7 +83,7 @@ public class UebTopicSourceFactoryTest extends UebTopicFactoryTestBase<UebTopicS
checkDefault(PROPERTY_TOPIC_SOURCE_FETCH_LIMIT_SUFFIX,
params2 -> params2.getFetchLimit() == UebTopicSource.DEFAULT_LIMIT_FETCH,
null, "", "invalid-limit-number");
-
+
checkDefault(PROPERTY_TOPIC_SOURCE_FETCH_TIMEOUT_SUFFIX,
params2 -> params2.getFetchTimeout() == UebTopicSource.DEFAULT_TIMEOUT_MS_FETCH,
null, "", "invalid-timeout-number");
@@ -100,6 +103,7 @@ public class UebTopicSourceFactoryTest extends UebTopicFactoryTestBase<UebTopicS
}
@Test
+ @Override
public void testBuildListOfStringString() {
super.testBuildListOfStringString();
@@ -114,12 +118,14 @@ public class UebTopicSourceFactoryTest extends UebTopicFactoryTestBase<UebTopicS
}
@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 ae07798d..a32083fa 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
@@ -27,12 +27,12 @@ import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import com.att.aft.dme2.internal.apache.commons.collections.IteratorUtils;
import com.att.nsa.cambria.client.CambriaConsumer;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import org.apache.commons.collections4.IteratorUtils;
import org.junit.Before;
import org.junit.Test;
import org.onap.dmaap.mr.client.impl.MRConsumerImpl;
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 283d44da..1d02a9d2 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
@@ -107,35 +107,35 @@ public class BusPublisherTest extends TopicTestBase {
@Test
public void testDmaapPublisherWrapper() {
// verify with different constructor arguments
- new DmaapAafPublisherWrapper(servers, MY_TOPIC, MY_USERNAME, MY_PASSWD, true);
- new DmaapAafPublisherWrapper(servers, MY_TOPIC, MY_USERNAME, MY_PASSWD, false);
- new DmaapPublisherWrapper(ProtocolTypeConstants.DME2, servers, MY_TOPIC, MY_USERNAME, MY_PASSWD, true) {};
+ new DmaapAafPublisherWrapper(servers, MY_TOPIC, MY_USERNAME, MY_PASS, true);
+ new DmaapAafPublisherWrapper(servers, MY_TOPIC, MY_USERNAME, MY_PASS, false);
+ new DmaapPublisherWrapper(ProtocolTypeConstants.DME2, servers, MY_TOPIC, MY_USERNAME, MY_PASS, true) {};
}
@Test(expected = IllegalArgumentException.class)
public void testDmaapPublisherWrapper_InvalidTopic() {
- new DmaapPublisherWrapper(ProtocolTypeConstants.DME2, servers, "", MY_USERNAME, MY_PASSWD, true) {};
+ new DmaapPublisherWrapper(ProtocolTypeConstants.DME2, servers, "", MY_USERNAME, MY_PASS, true) {};
}
@Test(expected = IllegalArgumentException.class)
public void testDmaapPublisherWrapper_Aaf_NullServers() {
- new DmaapAafPublisherWrapper(null, MY_TOPIC, MY_USERNAME, MY_PASSWD, true);
+ new DmaapAafPublisherWrapper(null, MY_TOPIC, MY_USERNAME, MY_PASS, true);
}
@Test(expected = IllegalArgumentException.class)
public void testDmaapPublisherWrapper_Aaf_NoServers() {
- new DmaapAafPublisherWrapper(Collections.emptyList(), MY_TOPIC, MY_USERNAME, MY_PASSWD, true);
+ new DmaapAafPublisherWrapper(Collections.emptyList(), MY_TOPIC, MY_USERNAME, MY_PASS, true);
}
@Test(expected = IllegalArgumentException.class)
public void testDmaapPublisherWrapper_InvalidProtocol() {
- new DmaapPublisherWrapper(ProtocolTypeConstants.HTTPNOAUTH, servers, MY_TOPIC, MY_USERNAME, MY_PASSWD, true) {};
+ new DmaapPublisherWrapper(ProtocolTypeConstants.HTTPNOAUTH, servers, MY_TOPIC, MY_USERNAME, MY_PASS, true) {};
}
@Test
public void testDmaapPublisherWrapperClose() throws Exception {
MRSimplerBatchPublisher pub = mock(MRSimplerBatchPublisher.class);
- DmaapPublisherWrapper dmaap = new DmaapAafPublisherWrapper(servers, MY_TOPIC, MY_USERNAME, MY_PASSWD, true);
+ DmaapPublisherWrapper dmaap = new DmaapAafPublisherWrapper(servers, MY_TOPIC, MY_USERNAME, MY_PASS, true);
dmaap.publisher = pub;
dmaap.close();
@@ -149,7 +149,7 @@ public class BusPublisherTest extends TopicTestBase {
@Test
public void testDmaapPublisherWrapperSend() {
MRSimplerBatchPublisher pub = mock(MRSimplerBatchPublisher.class);
- DmaapPublisherWrapper dmaap = new DmaapAafPublisherWrapper(servers, MY_TOPIC, MY_USERNAME, MY_PASSWD, true);
+ DmaapPublisherWrapper dmaap = new DmaapAafPublisherWrapper(servers, MY_TOPIC, MY_USERNAME, MY_PASS, true);
dmaap.publisher = pub;
// null response
@@ -171,7 +171,7 @@ public class BusPublisherTest extends TopicTestBase {
@Test(expected = IllegalArgumentException.class)
public void testDmaapPublisherWrapperSend_NullMessage() {
MRSimplerBatchPublisher pub = mock(MRSimplerBatchPublisher.class);
- DmaapPublisherWrapper dmaap = new DmaapAafPublisherWrapper(servers, MY_TOPIC, MY_USERNAME, MY_PASSWD, true);
+ DmaapPublisherWrapper dmaap = new DmaapAafPublisherWrapper(servers, MY_TOPIC, MY_USERNAME, MY_PASS, true);
dmaap.publisher = pub;
dmaap.send(MY_PARTITION, null);
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 54531c56..c00f2b56 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
@@ -62,7 +62,7 @@ public class BusTopicParamsTest extends TopicTestBase {
assertEquals(true, params.isManaged());
assertEquals(MY_PARTITION, params.getPartitionId());
assertEquals(MY_PARTNER, params.getPartner());
- assertEquals(MY_PASSWD, params.getPassword());
+ assertEquals(MY_PASS, params.getPassword());
assertEquals(MY_PORT, params.getPort());
assertEquals(servers, params.getServers());
assertEquals(MY_TOPIC, params.getTopic());
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSourceTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSourceTest.java
index f930fb6b..16d74df2 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSourceTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedBusTopicSourceTest.java
@@ -55,6 +55,7 @@ public class SingleThreadedBusTopicSourceTest extends TopicTestBase {
* Creates the object to be tested, as well as various mocks.
*/
@Before
+ @Override
public void setUp() {
super.setUp();
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedDmaapTopicSourceTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedDmaapTopicSourceTest.java
index 29c34591..b7faf161 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedDmaapTopicSourceTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedDmaapTopicSourceTest.java
@@ -32,12 +32,14 @@ import org.onap.policy.common.endpoints.event.comm.bus.TopicTestBase;
import org.onap.policy.common.utils.gson.GsonTestUtils;
public class SingleThreadedDmaapTopicSourceTest extends TopicTestBase {
+ private static final String SOURCE_NAME = "SingleThreadedDmaapTopicSource [";
private SingleThreadedDmaapTopicSource source;
/**
* Creates the object to be tested.
*/
@Before
+ @Override
public void setUp() {
super.setUp();
@@ -56,17 +58,17 @@ public class SingleThreadedDmaapTopicSourceTest extends TopicTestBase {
@Test
public void testToString() {
- assertTrue(source.toString().startsWith("SingleThreadedDmaapTopicSource ["));
+ assertTrue(source.toString().startsWith(SOURCE_NAME));
source.shutdown();
// try with null password
source = new SingleThreadedDmaapTopicSource(makeBuilder().password(null).build());
- assertTrue(source.toString().startsWith("SingleThreadedDmaapTopicSource ["));
+ assertTrue(source.toString().startsWith(SOURCE_NAME));
source.shutdown();
// try with empty password
source = new SingleThreadedDmaapTopicSource(makeBuilder().password("").build());
- assertTrue(source.toString().startsWith("SingleThreadedDmaapTopicSource ["));
+ assertTrue(source.toString().startsWith(SOURCE_NAME));
source.shutdown();
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedUebTopicSourceTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedUebTopicSourceTest.java
index 99dc6fb7..2ff353b8 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedUebTopicSourceTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/SingleThreadedUebTopicSourceTest.java
@@ -37,6 +37,7 @@ public class SingleThreadedUebTopicSourceTest 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/TopicBaseTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/TopicBaseTest.java
index 55b2b404..1535acc7 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/TopicBaseTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/event/comm/bus/internal/TopicBaseTest.java
@@ -47,6 +47,7 @@ public class TopicBaseTest 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 d214d23b..f559b112 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,7 +25,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Collections;
@@ -67,10 +66,9 @@ public class HttpClientTest {
* Setup before class method.
*
* @throws InterruptedException can be interrupted
- * @throws IOException can have an IO exception
*/
@BeforeClass
- public static void setUpBeforeClass() throws InterruptedException, IOException {
+ public static void setUpBeforeClass() throws InterruptedException {
/* echo server - http + no auth */
final HttpServletServer echoServerNoAuth =
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 41ad2122..c6ff2f32 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
@@ -20,6 +20,7 @@
package org.onap.policy.common.endpoints.http.server.test;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -75,7 +76,7 @@ public class HttpServerTest {
*/
@Before
public void setUp() {
- port += 10;
+ incrementPort();
portUrl = LOCALHOST_PREFIX + port;
HttpServletServer.factory.destroy();
@@ -84,6 +85,10 @@ public class HttpServerTest {
MyGsonProvider.resetSome();
}
+ private static void incrementPort() {
+ port += 10;
+ }
+
@AfterClass
public static void tearDownAfterClass() {
HttpServletServer.factory.destroy();
@@ -264,13 +269,7 @@ public class HttpServerTest {
String response = http(portUrl + JUNIT_ECHO_HELLO);
assertEquals(HELLO, response);
- response = null;
- try {
- response = http(portUrl + SWAGGER_JSON);
- } catch (IOException e) {
- // Expected
- }
- assertTrue(response == null);
+ assertThatThrownBy(() -> http(portUrl + SWAGGER_JSON)).isInstanceOf(IOException.class);
response = http(portUrl + "/junit/echo/hello?block=true");
assertEquals("FILTERED", response);
@@ -311,13 +310,7 @@ public class HttpServerTest {
response = http(LOCALHOST_PREFIX + port2 + JUNIT_ECHO_HELLO);
assertTrue(HELLO.equals(response));
- response = null;
- try {
- response = http(LOCALHOST_PREFIX + port2 + SWAGGER_JSON);
- } catch (IOException e) {
- // Expected
- }
- assertTrue(response == null);
+ assertThatThrownBy(() -> http(LOCALHOST_PREFIX + port2 + SWAGGER_JSON)).isInstanceOf(IOException.class);
HttpServletServer.factory.destroy();
assertTrue(HttpServletServer.factory.inventory().isEmpty());
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyGsonProvider.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyGsonProvider.java
index 286d73dc..8343d02d 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyGsonProvider.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyGsonProvider.java
@@ -27,13 +27,19 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
+import lombok.AccessLevel;
+import lombok.Setter;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
/**
* GsonMessageBodyHandler that tracks activities.
*/
public class MyGsonProvider extends GsonMessageBodyHandler {
+
+ @Setter(AccessLevel.PRIVATE)
private static boolean readSome = false;
+
+ @Setter(AccessLevel.PRIVATE)
private static boolean wroteSome = false;
/**
@@ -48,7 +54,7 @@ public class MyGsonProvider extends GsonMessageBodyHandler {
public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException {
- readSome = true;
+ setReadSome(true);
return super.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream);
}
@@ -56,7 +62,7 @@ public class MyGsonProvider extends GsonMessageBodyHandler {
public void writeTo(Object object, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException {
- wroteSome = true;
+ setWroteSome(true);
super.writeTo(object, type, genericType, annotations, mediaType, httpHeaders, entityStream);
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyJacksonProvider.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyJacksonProvider.java
index 07062451..55efd8bb 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyJacksonProvider.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/http/server/test/MyJacksonProvider.java
@@ -28,12 +28,18 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
+import lombok.AccessLevel;
+import lombok.Setter;
/**
* JacksonJsonProvider that tracks activities.
*/
public class MyJacksonProvider extends JacksonJsonProvider {
+
+ @Setter(AccessLevel.PRIVATE)
private static boolean readSome = false;
+
+ @Setter(AccessLevel.PRIVATE)
private static boolean wroteSome = false;
/**
@@ -48,7 +54,7 @@ public class MyJacksonProvider extends JacksonJsonProvider {
public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException {
- readSome = true;
+ setReadSome(true);
return super.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream);
}
@@ -56,7 +62,7 @@ public class MyJacksonProvider extends JacksonJsonProvider {
public void writeTo(Object object, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException {
- wroteSome = true;
+ setWroteSome(true);
super.writeTo(object, type, genericType, annotations, mediaType, httpHeaders, entityStream);
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/JsonListenerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/JsonListenerTest.java
index 39fc9d8f..c2ef4eba 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/JsonListenerTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/JsonListenerTest.java
@@ -86,7 +86,9 @@ public class JsonListenerTest {
primary = new JsonListener() {
@Override
- public void onTopicEvent(CommInfrastructure infra, String topic, StandardCoderObject sco) {}
+ public void onTopicEvent(CommInfrastructure infra, String topic, StandardCoderObject sco) {
+ // do nothing
+ }
};
}
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/ScoListenerTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/ScoListenerTest.java
index 0749f891..4d10c65e 100644
--- a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/ScoListenerTest.java
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/listeners/ScoListenerTest.java
@@ -93,7 +93,9 @@ public class ScoListenerTest {
primary = new ScoListener<MyMessage>(MyMessage.class) {
@Override
public void onTopicEvent(CommInfrastructure infra, String topic, StandardCoderObject sco,
- MyMessage message) {}
+ MyMessage message) {
+ // do nothing
+ }
};
}
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 6e84c137..2860377e 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
@@ -39,6 +39,7 @@ import org.slf4j.Logger;
*/
public class NetLoggerUtilTest {
+ private static final String TEST_TOPIC = "test-topic";
private static final String MESSAGE = "hello world!";
/**
* Test feature used for junits.
@@ -76,7 +77,7 @@ public class NetLoggerUtilTest {
*/
@Test
public void logTest() {
- NetLoggerUtil.log(EventType.IN, CommInfrastructure.NOOP, "test-topic", MESSAGE);
+ NetLoggerUtil.log(EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE);
assertEquals(3, TestAppender.events.size());
}
@@ -85,7 +86,7 @@ public class NetLoggerUtilTest {
*/
@Test
public void logDefaultTest() {
- NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, "test-topic", MESSAGE);
+ NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE);
assertEquals(3, TestAppender.events.size());
assertEquals("network", TestAppender.events.get(0).getLoggerName());
}
@@ -96,7 +97,7 @@ public class NetLoggerUtilTest {
@Test
public void beforeLogReturnTrueTest() {
netLoggerFeature.setReturnValue(true, false);
- NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, "test-topic", MESSAGE);
+ NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE);
assertEquals(1, TestAppender.events.size());
}
@@ -106,7 +107,7 @@ public class NetLoggerUtilTest {
@Test
public void afterLogReturnTrueTest() {
netLoggerFeature.setReturnValue(false, true);
- NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, "test-topic", MESSAGE);
+ NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE);
assertEquals(3, TestAppender.events.size());
}
@@ -116,7 +117,7 @@ public class NetLoggerUtilTest {
@Test
public void beforeLogExceptionTest() {
netLoggerFeature.setExceptions(true, false);
- NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, "test-topic", MESSAGE);
+ NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE);
assertEquals(2, TestAppender.events.size());
}
@@ -126,7 +127,7 @@ public class NetLoggerUtilTest {
@Test
public void afterLogExceptionTest() {
netLoggerFeature.setExceptions(false, true);
- NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, "test-topic", MESSAGE);
+ NetLoggerUtil.log(null, EventType.IN, CommInfrastructure.NOOP, TEST_TOPIC, MESSAGE);
assertEquals(2, TestAppender.events.size());
}
@@ -139,7 +140,7 @@ public class NetLoggerUtilTest {
/**
* List of logged events.
*/
- public static List<ILoggingEvent> events = new ArrayList<>();
+ private static final List<ILoggingEvent> events = new ArrayList<>();
/**
* Called after every unit test to clear list of events.
diff --git a/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/PropertyUtilsTest.java b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/PropertyUtilsTest.java
new file mode 100644
index 00000000..048a3902
--- /dev/null
+++ b/policy-endpoints/src/test/java/org/onap/policy/common/endpoints/utils/PropertyUtilsTest.java
@@ -0,0 +1,108 @@
+/*
+ * ============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.utils;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Properties;
+import org.junit.Before;
+import org.junit.Test;
+
+public class PropertyUtilsTest {
+ private static final String DFLT_STRING = "my-default";
+ private static final int DLFT_INT = 1000;
+
+ private PropertyUtils utils;
+ private String invalidName;
+ private String invalidValue;
+ private Exception invalidEx;
+
+ /**
+ * Initializes {@link #utils}.
+ */
+ @Before
+ public void setUp() {
+ Properties properties = new Properties();
+ properties.put("myPrefix.my-string", "some text");
+ properties.put("myPrefix.empty-string", "");
+
+ properties.put("myPrefix.my-bool", "true");
+ properties.put("myPrefix.my-bool2", "false");
+ properties.put("myPrefix.empty-bool", "");
+ properties.put("myPrefix.invalid-bool", "not a bool");
+
+ properties.put("myPrefix.my-int", "100");
+ properties.put("myPrefix.my-int2", "200");
+ properties.put("myPrefix.empty-int", "");
+ properties.put("myPrefix.invalid-int", "not an int");
+
+ utils = new PropertyUtils(properties, "myPrefix", (name, value, ex) -> {
+ invalidName = name;
+ invalidValue = value;
+ invalidEx = ex;
+ });
+ }
+
+ @Test
+ public void testGetString() {
+ assertEquals("some text", utils.getString(".my-string", DFLT_STRING));
+ assertEquals(DFLT_STRING, utils.getString(".empty-string", DFLT_STRING));
+ assertEquals(DFLT_STRING, utils.getString(".missing-string", DFLT_STRING));
+
+ assertNull(invalidName);
+ assertNull(invalidValue);
+ assertNull(invalidEx);
+ }
+
+ @Test
+ public void testGetBoolean() {
+ assertEquals(true, utils.getBoolean(".my-bool", false));
+ assertEquals(false, utils.getBoolean(".my-bool2", true));
+ assertEquals(true, utils.getBoolean(".empty-bool", true));
+ assertEquals(false, utils.getBoolean(".invalid-bool", true));
+ assertEquals(true, utils.getBoolean(".missing-bool", true));
+
+ assertNull(invalidName);
+ assertNull(invalidValue);
+ assertNull(invalidEx);
+ }
+
+ @Test
+ public void testGetInteger() {
+ assertEquals(100, utils.getInteger(".my-int", DLFT_INT));
+ assertEquals(200, utils.getInteger(".my-int2", DLFT_INT));
+ assertEquals(DLFT_INT, utils.getInteger(".empty-int", DLFT_INT));
+ assertEquals(DLFT_INT, utils.getInteger(".missing-int", DLFT_INT));
+
+ assertNull(invalidName);
+ assertNull(invalidValue);
+ assertNull(invalidEx);
+
+ assertEquals(DLFT_INT, utils.getInteger(".invalid-int", DLFT_INT));
+
+ assertEquals("myPrefix.invalid-int", invalidName);
+ assertEquals("not an int", invalidValue);
+ assertTrue(invalidEx instanceof NumberFormatException);
+ }
+
+}