aboutsummaryrefslogtreecommitdiffstats
path: root/feature-pooling-dmaap/src/test/java/org/onap
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-09-30 14:32:56 -0400
committerJim Hahn <jrh3@att.com>2020-09-30 16:29:50 -0400
commitb7239e0e2859d998d5f8448879409eb30c3bc658 (patch)
tree7b9eec66ddaf30200fb4a55c0ceacbdb3035e63e /feature-pooling-dmaap/src/test/java/org/onap
parent7ee6e75574262ca7419481881313bd60e72bf302 (diff)
Fix new sonars in drools-pdp
Addressed the following sonar issues: - extract common test method - too many assertions in test method - don't always return the same value Issue-ID: POLICY-2616 Change-Id: Iab836cdcd667b35e2db9db7d6ffc7896df33e1c8 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'feature-pooling-dmaap/src/test/java/org/onap')
-rw-r--r--feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/PoolingManagerImplTest.java105
1 files changed, 46 insertions, 59 deletions
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 bd3d90b6..2a0066b7 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
@@ -640,27 +640,17 @@ public class PoolingManagerImplTest {
@Test
public void testBeforeInsert_NoIntercept() throws Exception {
- startMgr();
-
- assertFalse(mgr.beforeInsert(CommInfrastructure.UEB, TOPIC2, THE_EVENT, DECODED_EVENT));
+ validateUnhandled(CommInfrastructure.UEB);
}
@Test
public void testHandleExternalCommInfrastructureStringStringString_NullReqId() throws Exception {
- startMgr();
-
- when(extractors.extract(any())).thenReturn(null);
-
- assertFalse(mgr.beforeInsert(CommInfrastructure.UEB, TOPIC2, THE_EVENT, DECODED_EVENT));
+ validateHandleReqId(null);
}
@Test
public void testHandleExternalCommInfrastructureStringStringString_EmptyReqId() throws Exception {
- startMgr();
-
- when(extractors.extract(any())).thenReturn("");
-
- assertFalse(mgr.beforeInsert(CommInfrastructure.UEB, TOPIC2, THE_EVENT, DECODED_EVENT));
+ validateHandleReqId("");
}
@Test
@@ -672,50 +662,28 @@ public class PoolingManagerImplTest {
@Test
public void testHandleExternalCommInfrastructureStringStringString() throws Exception {
- startMgr();
-
- assertFalse(mgr.beforeInsert(CommInfrastructure.UEB, TOPIC2, THE_EVENT, DECODED_EVENT));
+ validateUnhandled(CommInfrastructure.UEB);
}
@Test
public void testHandleExternalForward_NoAssignments() throws Exception {
- startMgr();
-
- assertFalse(mgr.beforeInsert(CommInfrastructure.UEB, TOPIC2, THE_EVENT, DECODED_EVENT));
+ validateUnhandled(CommInfrastructure.UEB);
}
@Test
public void testHandleExternalForward() throws Exception {
- startMgr();
-
- // route the message to this host
- mgr.startDistributing(makeAssignments(true));
-
- assertFalse(mgr.beforeInsert(CommInfrastructure.UEB, TOPIC2, THE_EVENT, DECODED_EVENT));
+ validateNoForward();
}
@Test
public void testHandleEvent_NullTarget() throws Exception {
- startMgr();
-
// buckets have null targets
- mgr.startDistributing(new BucketAssignments(new String[] {null, null}));
-
- assertTrue(mgr.beforeInsert(CommInfrastructure.UEB, TOPIC2, THE_EVENT, DECODED_EVENT));
-
- verify(dmaap, times(START_PUB)).publish(any());
+ validateHandled(new BucketAssignments(new String[] {null, null}), START_PUB);
}
@Test
public void testHandleEvent_SameHost() throws Exception {
- startMgr();
-
- // route the message to this host
- mgr.startDistributing(makeAssignments(true));
-
- assertFalse(mgr.beforeInsert(CommInfrastructure.UEB, TOPIC2, THE_EVENT, DECODED_EVENT));
-
- verify(dmaap, times(START_PUB)).publish(any());
+ validateNoForward();
}
@Test
@@ -736,14 +704,7 @@ public class PoolingManagerImplTest {
@Test
public void testHandleEvent_DiffHost_Forward() throws Exception {
- startMgr();
-
- // route the message to the *OTHER* host
- mgr.startDistributing(makeAssignments(false));
-
- assertTrue(mgr.beforeInsert(CommInfrastructure.UEB, TOPIC2, THE_EVENT, DECODED_EVENT));
-
- verify(dmaap, times(START_PUB + 1)).publish(any());
+ validateHandled(makeAssignments(false), START_PUB + 1);
}
@Test
@@ -755,11 +716,7 @@ public class PoolingManagerImplTest {
@Test
public void testExtractRequestId_NullReqId() throws Exception {
- startMgr();
-
- when(extractors.extract(any())).thenReturn(null);
-
- assertFalse(mgr.beforeInsert(CommInfrastructure.UEB, TOPIC2, THE_EVENT, DECODED_EVENT));
+ validateHandleReqId(null);
}
@Test
@@ -1009,12 +966,7 @@ public class PoolingManagerImplTest {
@Test
public void testStartDistributing() throws Exception {
- startMgr();
-
- // route the message to this host
- mgr.startDistributing(makeAssignments(true));
- assertFalse(mgr.beforeInsert(CommInfrastructure.UEB, TOPIC2, THE_EVENT, DECODED_EVENT));
- verify(dmaap, times(START_PUB)).publish(any());
+ validateNoForward();
// null assignments should cause message to be processed locally
@@ -1133,6 +1085,41 @@ public class PoolingManagerImplTest {
assertEquals(1, latch.getCount());
}
+ private void validateHandleReqId(String requestId) throws PoolingFeatureException {
+ startMgr();
+
+ when(extractors.extract(any())).thenReturn(requestId);
+
+ assertFalse(mgr.beforeInsert(CommInfrastructure.UEB, TOPIC2, THE_EVENT, DECODED_EVENT));
+ }
+
+ private void validateNoForward() throws PoolingFeatureException {
+ startMgr();
+
+ // route the message to this host
+ mgr.startDistributing(makeAssignments(true));
+
+ assertFalse(mgr.beforeInsert(CommInfrastructure.UEB, TOPIC2, THE_EVENT, DECODED_EVENT));
+
+ verify(dmaap, times(START_PUB)).publish(any());
+ }
+
+ private void validateHandled(BucketAssignments assignments, int publishCount) throws PoolingFeatureException {
+ startMgr();
+
+ // route the message to the *OTHER* host
+ mgr.startDistributing(assignments);
+
+ assertTrue(mgr.beforeInsert(CommInfrastructure.UEB, TOPIC2, THE_EVENT, DECODED_EVENT));
+
+ verify(dmaap, times(publishCount)).publish(any());
+ }
+
+ private void validateUnhandled(CommInfrastructure infra) throws PoolingFeatureException {
+ startMgr();
+ assertFalse(mgr.beforeInsert(infra, TOPIC2, THE_EVENT, DECODED_EVENT));
+ }
+
/**
* 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