summaryrefslogtreecommitdiffstats
path: root/feature-pooling-dmaap/src/test/java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-04-06 15:33:23 -0400
committerJim Hahn <jrh3@att.com>2020-04-06 19:30:02 -0400
commit15014b8ca386a8bfd5c26435f45de94ca06e95e8 (patch)
tree3cca518b950dfa35da0ea64dab2f9ff2b80f4595 /feature-pooling-dmaap/src/test/java
parentece155048af47ea83ff898c999aa5137dc99a988 (diff)
Address sonar issues in drools-pdp
Addressed the following sonar issues: - add "final" to public static fields - commented code; some were bogus - just updated the comments so sonar is happy - use "{}" instead of string concatenation - junit should assert something - when using logger, invoke compute-intensive tasks conditionally - use superclass name instead of subclass name to access static fields - don't always return the same value - remove "transient" from fields of classes that aren't Serializable - don't nest try/catch blocks - use appropriate class name in Logger.getLogger() - use Predicate<T> instead of Function<T,Boolean> - remove unused parameters from private methods - either log or throw - remove duplicate methods - use remove() TLS instead of set(null) - null check is implicit in instanceof check - do something with return value - don't use volatile - don't return "null" list; used Optional instead - add no-arg constructor to non-Serializable superclass - add callSuper=true for EqualsAndHashCode - don't declare "throws XXX" where XXX is a subclass of RuntimeException - remove serialVersionUID field if the class isn't Serializable Also addressed some eclipse warnings: - unused fields - suppress generic typic cast warnings Issue-ID: POLICY-2305 Change-Id: I906d5bf71c1f86531423e23b3667a585cdba45e1 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'feature-pooling-dmaap/src/test/java')
-rw-r--r--feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/DmaapManagerTest.java33
-rw-r--r--feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingManagerImplTest.java37
-rw-r--r--feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingPropertiesTest.java17
-rw-r--r--feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/SerializerTest.java9
-rw-r--r--feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/BucketAssignmentsTest.java15
-rw-r--r--feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/StateTest.java9
6 files changed, 58 insertions, 62 deletions
diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/DmaapManagerTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/DmaapManagerTest.java
index 69896d34..d5b397a6 100644
--- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/DmaapManagerTest.java
+++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/DmaapManagerTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2020 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.
@@ -20,6 +20,7 @@
package org.onap.policy.drools.pooling;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -48,7 +49,7 @@ public class DmaapManagerTest {
private static final String MY_TOPIC = "my.topic";
private static final String MSG = "a message";
private static final String FILTER = "a filter";
-
+
private TopicListener listener;
private FilterableTopicSource source;
private boolean gotSources;
@@ -58,7 +59,7 @@ public class DmaapManagerTest {
/**
* Setup.
- *
+ *
* @throws Exception throws an exception
*/
@Before
@@ -116,11 +117,6 @@ public class DmaapManagerTest {
assertEquals(MY_TOPIC, mgr.getTopic());
}
- @Test
- public void testFindTopicSource() {
- // getting here means it worked
- }
-
@Test(expected = PoolingFeatureException.class)
public void testFindTopicSource_NotFilterableTopicSource() throws PoolingFeatureException {
@@ -158,11 +154,6 @@ public class DmaapManagerTest {
};
}
- @Test
- public void testFindTopicSink() {
- // getting here means it worked
- }
-
@Test(expected = PoolingFeatureException.class)
public void testFindTopicSink_NotFound() throws PoolingFeatureException {
// one item in list, and its topic doesn't match
@@ -187,7 +178,7 @@ public class DmaapManagerTest {
@Test
public void testStartPublisher() throws PoolingFeatureException {
-
+
mgr.startPublisher();
// restart should have no effect
@@ -210,7 +201,7 @@ public class DmaapManagerTest {
mgr.stopPublisher(0);
// re-stopping should have no effect
- mgr.stopPublisher(0);
+ assertThatCode(() -> mgr.stopPublisher(0)).doesNotThrowAnyException();
}
@Test
@@ -285,7 +276,7 @@ public class DmaapManagerTest {
@Test
public void testSetFilter() throws PoolingFeatureException {
- mgr.setFilter(FILTER);
+ assertThatCode(() -> mgr.setFilter(FILTER)).doesNotThrowAnyException();
}
@Test(expected = PoolingFeatureException.class)
@@ -337,7 +328,7 @@ public class DmaapManagerTest {
mgr.publish(MSG);
}
-
+
/**
* Manager with overrides.
*/
@@ -350,7 +341,7 @@ public class DmaapManagerTest {
@Override
protected List<TopicSource> getTopicSources() {
gotSources = true;
-
+
// three sources, with the desired one in the middle
return Arrays.asList(mock(TopicSource.class), source, mock(TopicSource.class));
}
@@ -358,7 +349,7 @@ public class DmaapManagerTest {
@Override
protected List<TopicSink> getTopicSinks() {
gotSinks = true;
-
+
// three sinks, with the desired one in the middle
return Arrays.asList(mock(TopicSink.class), sink, mock(TopicSink.class));
}
diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingManagerImplTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingManagerImplTest.java
index 5293b794..bd3d90b6 100644
--- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingManagerImplTest.java
+++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingManagerImplTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2020 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.
@@ -20,6 +20,7 @@
package org.onap.policy.drools.pooling;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -286,7 +287,7 @@ public class PoolingManagerImplTest {
Forward msg = new Forward(mgr.getHost(), CommInfrastructure.UEB, TOPIC2, THE_EVENT, REQUEST_ID);
mgr.handle(msg);
verify(dmaap, times(START_PUB + 1)).publish(any());
-
+
mgr.beforeStop();
verify(dmaap).stopConsumer(mgr);
@@ -453,7 +454,7 @@ public class PoolingManagerImplTest {
doThrow(new PoolingFeatureException()).when(dmaap).setFilter(any());
// start should invoke setFilter()
- startMgr();
+ assertThatCode(() -> startMgr()).doesNotThrowAnyException();
// no exception, means success
}
@@ -552,7 +553,7 @@ public class PoolingManagerImplTest {
// generate exception
doThrow(new PoolingFeatureException()).when(dmaap).publish(any());
- mgr.publish(Message.ADMIN, new Offline(mgr.getHost()));
+ assertThatCode(() -> mgr.publish(Message.ADMIN, new Offline(mgr.getHost()))).doesNotThrowAnyException();
}
@Test
@@ -578,7 +579,7 @@ public class PoolingManagerImplTest {
public void testOnTopicEvent_NullEvent() throws Exception {
startMgr();
- mgr.onTopicEvent(CommInfrastructure.UEB, TOPIC2, null);
+ assertThatCode(() -> mgr.onTopicEvent(CommInfrastructure.UEB, TOPIC2, null)).doesNotThrowAnyException();
}
@Test
@@ -780,7 +781,7 @@ public class PoolingManagerImplTest {
return false;
}
};
-
+
startMgr();
when(controller.isLocked()).thenReturn(true);
@@ -801,7 +802,7 @@ public class PoolingManagerImplTest {
throw new UnsupportedOperationException();
}
};
-
+
startMgr();
when(controller.isLocked()).thenReturn(true);
@@ -821,7 +822,7 @@ public class PoolingManagerImplTest {
throw new IllegalArgumentException();
}
};
-
+
startMgr();
when(controller.isLocked()).thenReturn(true);
@@ -841,7 +842,7 @@ public class PoolingManagerImplTest {
throw new IllegalStateException();
}
};
-
+
startMgr();
when(controller.isLocked()).thenReturn(true);
@@ -867,19 +868,19 @@ public class PoolingManagerImplTest {
@Test
public void testMakeForward() throws Exception {
startMgr();
-
+
// route the message to another host
mgr.startDistributing(makeAssignments(false));
assertTrue(mgr.beforeInsert(CommInfrastructure.UEB, TOPIC2, THE_EVENT, DECODED_EVENT));
-
+
verify(dmaap, times(START_PUB + 1)).publish(any());
}
@Test
public void testMakeForward_InvalidMsg() throws Exception {
startMgr();
-
+
// route the message to another host
mgr.startDistributing(makeAssignments(false));
@@ -1136,10 +1137,10 @@ public class PoolingManagerImplTest {
* Configure the mock controller to act like a real controller, invoking beforeOffer
* and then beforeInsert, so we can make sure they pass through. We'll keep count to
* ensure we don't get into infinite recursion.
- *
+ *
* @param invokeBeforeInsert {@code true} if beforeInsert() should be invoked,
* {@code false} if it should be skipped
- *
+ *
* @return a latch that will be counted down if both beforeXxx() methods return false
*/
private CountDownLatch catchRecursion(boolean invokeBeforeInsert) {
@@ -1176,7 +1177,7 @@ public class PoolingManagerImplTest {
/**
* Makes an assignment with two buckets.
- *
+ *
* @param sameHost {@code true} if the {@link #REQUEST_ID} should hash to the
* manager's bucket, {@code false} if it should hash to the other host's bucket
* @return a new bucket assignment
@@ -1198,7 +1199,7 @@ public class PoolingManagerImplTest {
/**
* Invokes methods necessary to start the manager.
- *
+ *
* @throws PoolingFeatureException if an error occurs
*/
private void startMgr() throws PoolingFeatureException {
diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingPropertiesTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingPropertiesTest.java
index cc716a2a..b15908dc 100644
--- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingPropertiesTest.java
+++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingPropertiesTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2020 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.
@@ -20,6 +20,7 @@
package org.onap.policy.drools.pooling;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.onap.policy.drools.pooling.PoolingProperties.ACTIVE_HEARTBEAT_MS;
import static org.onap.policy.drools.pooling.PoolingProperties.FEATURE_ENABLED;
@@ -60,7 +61,7 @@ public class PoolingPropertiesTest {
/**
* Setup.
- *
+ *
* @throws Exception throws an exception
*/
@Before
@@ -73,7 +74,7 @@ public class PoolingPropertiesTest {
@Test
public void testPoolingProperties() throws PropertyException {
// ensure no exceptions
- new PoolingProperties(CONTROLLER, plain);
+ assertThatCode(() -> new PoolingProperties(CONTROLLER, plain)).doesNotThrowAnyException();
}
@Test
@@ -130,7 +131,7 @@ public class PoolingPropertiesTest {
* Tests a particular property. Verifies that the correct value is returned if the
* specialized property has a value or the property has no value. Also verifies that
* the property name can be generalized.
- *
+ *
* @param propnm name of the property of interest
* @param specValue expected specialized value
* @param dfltValue expected default value
@@ -156,7 +157,7 @@ public class PoolingPropertiesTest {
/**
* Makes a set of properties, where all of the properties are specialized for the
* controller.
- *
+ *
* @return a new property set
*/
private Properties makeProperties() {
@@ -178,7 +179,7 @@ public class PoolingPropertiesTest {
/**
* Embeds a specializer within a property name, after the prefix.
- *
+ *
* @param propnm property name into which it should be embedded
* @param spec specializer to be embedded
* @return the property name, with the specializer embedded within it
diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/SerializerTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/SerializerTest.java
index b51a18f2..09e83852 100644
--- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/SerializerTest.java
+++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/SerializerTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2020 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.
@@ -20,6 +20,7 @@
package org.onap.policy.drools.pooling;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -39,7 +40,7 @@ public class SerializerTest {
@Test
public void testSerializer() {
- new Serializer();
+ assertThatCode(() -> new Serializer()).doesNotThrowAnyException();
}
@Test
diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/BucketAssignmentsTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/BucketAssignmentsTest.java
index 5788141b..50cab788 100644
--- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/BucketAssignmentsTest.java
+++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/BucketAssignmentsTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2020 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.
@@ -20,6 +20,7 @@
package org.onap.policy.drools.pooling.message;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -37,7 +38,7 @@ public class BucketAssignmentsTest {
@Test
public void testBucketAssignments() {
- new BucketAssignments();
+ assertThatCode(() -> new BucketAssignments()).doesNotThrowAnyException();
}
@Test
@@ -172,7 +173,7 @@ public class BucketAssignmentsTest {
/**
* Gets the hosts, sorted, so that the order is predictable.
- *
+ *
* @param asgn assignment whose hosts are to be retrieved
* @return a new, sorted set of hosts
*/
@@ -201,7 +202,7 @@ public class BucketAssignmentsTest {
/*
* get assignments for consecutive integers, including negative numbers and
* numbers extending past the length of the array.
- *
+ *
*/
TreeSet<String> seen = new TreeSet<>();
for (int x = -1; x < arr.length + 2; ++x) {
@@ -342,7 +343,7 @@ public class BucketAssignmentsTest {
/**
* Expects an exception when checkValidity() is called.
- *
+ *
* @param asgn assignments to be checked
*/
private void expectException(BucketAssignments asgn) {
diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/StateTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/StateTest.java
index 65d9ee31..5284ed11 100644
--- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/StateTest.java
+++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/state/StateTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2020 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.
@@ -20,6 +20,7 @@
package org.onap.policy.drools.pooling.state;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@@ -136,7 +137,7 @@ public class StateTest extends SupportBasicStateTester {
@Test
public void testStart() {
- state.start();
+ assertThatCode(() -> state.start()).doesNotThrowAnyException();
}
@Test