From 1e39e2bf48a7122aec00792cf43672a46ae9fa65 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Mon, 28 Sep 2020 14:37:44 -0400 Subject: New sonars in policy-common Addressed the following sonars: - too many assertions in a test case - use parameterized test method Disabled production sonars for util-test, as the entire module is only used for testing other modules. Issue-ID: POLICY-2650-sonar Change-Id: If49775a6c95855dcd9601ee0d833bb00741b1550 Signed-off-by: Jim Hahn --- .../event/comm/bus/internal/BusTopicParamsTest.java | 16 +++++++++++++--- .../endpoints/event/comm/bus/internal/TopicBaseTest.java | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) (limited to 'policy-endpoints/src/test') 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 c00f2b56..93e5067e 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-endpoints * ================================================================================ - * 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. @@ -41,7 +41,7 @@ public class BusTopicParamsTest extends TopicTestBase { } @Test - public void test() { + public void testGetters() { BusTopicParams params = makeBuilder().build(); assertEquals(addProps, params.getAdditionalProps()); @@ -69,11 +69,19 @@ public class BusTopicParamsTest extends TopicTestBase { assertEquals(MY_EFFECTIVE_TOPIC, params.getEffectiveTopic()); assertEquals(true, params.isUseHttps()); assertEquals(MY_USERNAME, params.getUserName()); + } + @Test + public void testBooleanGetters() { // ensure that booleans are independent of each other testBoolean("true:false:false", (bldr, flag) -> bldr.allowSelfSignedCerts(flag)); testBoolean("false:true:false", (bldr, flag) -> bldr.managed(flag)); testBoolean("false:false:true", (bldr, flag) -> bldr.useHttps(flag)); + } + + @Test + public void testValidators() { + BusTopicParams params = makeBuilder().build(); // test validity methods assertTrue(params.isAdditionalPropsValid()); @@ -94,8 +102,10 @@ public class BusTopicParamsTest extends TopicTestBase { assertFalse(params.isServersInvalid()); assertFalse(params.isTopicInvalid()); assertTrue(params.isUserNameValid()); + } - // test inverted validity + @Test + public void testInvertedValidators() { assertFalse(makeBuilder().additionalProps(null).build().isAdditionalPropsValid()); assertTrue(makeBuilder().aftEnvironment("").build().isAftEnvironmentInvalid()); assertFalse(makeBuilder().apiKey("").build().isApiKeyValid()); 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 67b84ea8..0f09b12e 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 @@ -194,9 +194,15 @@ public class TopicBaseTest extends TopicTestBase { assertTrue(base.unlock()); assertEquals(1, base.startCount); assertEquals(1, base.stopCount); + } + + /** + * Tests lock/unlock when the stop/start methods return false. + */ + @Test + public void testLock_testUnlock_FalseReturns() { // lock, but stop returns false - base = new TopicBaseImpl(servers, MY_TOPIC); base.stopReturn = false; assertFalse(base.lock()); assertTrue(base.isLocked()); @@ -207,9 +213,15 @@ public class TopicBaseTest extends TopicTestBase { assertFalse(base.unlock()); assertFalse(base.isLocked()); assertTrue(base.unlock()); + } + + /** + * Tests lock/unlock when the start method throws an exception. + */ + @Test + public void testLock_testUnlock_Exception() { // lock & re-lock, but start throws an exception - base = new TopicBaseImpl(servers, MY_TOPIC); base.startEx = true; assertTrue(base.lock()); assertFalse(base.unlock()); -- cgit 1.2.3-korg