From fb9bd637567096f6174bbc2e52a5e149a4eed882 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 30 Sep 2020 12:52:25 -0400 Subject: Fix new sonars in drools-apps Addressed the following sonars: - too many assertions in test method - rename test class - use static method to modify static field - use already defined constant - code always returns the same value - use assertNotSame - use appropriate class name to access static method - define a constant - extract nested try block - don't always return the same value - use remove() instead of set(null) for thread-local-storage - add @Override Issue-ID: POLICY-2852 Change-Id: Icc62acd4ad57afa2d44ed4cdca504a3ac0810228 Signed-off-by: Jim Hahn --- .../onap/policy/controlloop/common/rules/test/BaseTest.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'controlloop/common/rules-test/src/main') diff --git a/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/BaseTest.java b/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/BaseTest.java index f5346def8..83825bca9 100644 --- a/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/BaseTest.java +++ b/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/BaseTest.java @@ -30,6 +30,7 @@ import java.util.function.Supplier; import java.util.stream.Collectors; import lombok.AccessLevel; import lombok.Getter; +import lombok.Setter; import org.awaitility.Awaitility; import org.junit.Test; import org.onap.policy.appc.Request; @@ -55,6 +56,9 @@ public abstract class BaseTest { private static final String APPC_RESTART_OP = "restart"; private static final String APPC_MODIFY_CONFIG_OP = "ModifyConfig"; + private static final String SDNR_MODIFY_CONFIG_OP = "ModifyConfig"; + private static final String SNDR_MODIFY_CONFIG_ANR_OP = "ModifyConfigANR"; + /* * Canonical Topic Names. */ @@ -135,6 +139,7 @@ public abstract class BaseTest { // used to inject and wait for messages @Getter(AccessLevel.PROTECTED) + @Setter(AccessLevel.PROTECTED) protected static Topics topics; // used to wait for messages on SINK topics @@ -168,7 +173,7 @@ public abstract class BaseTest { * Initializes {@link #topics} and {@link #controller}. */ public void init() { - topics = topicMaker.get(); + setTopics(topicMaker.get()); Map locks = getLockMap(); if (locks != null) { @@ -348,7 +353,7 @@ public abstract class BaseTest { */ @Test public void testVpciSunnyDayCompliant() { - sdnrSunnyDay(VPCI_TOSCA_COMPLIANT_POLICY, VPCI_ONSET, VPCI_SDNR_SUCCESS, "ModifyConfig"); + sdnrSunnyDay(VPCI_TOSCA_COMPLIANT_POLICY, VPCI_ONSET, VPCI_SDNR_SUCCESS, SDNR_MODIFY_CONFIG_OP); } // VSONH @@ -358,7 +363,7 @@ public abstract class BaseTest { */ @Test public void testVsonhSunnyDayCompliant() { - sdnrSunnyDay(VSONH_TOSCA_COMPLIANT_POLICY, VSONH_ONSET, VSONH_SDNR_SUCCESS, "ModifyConfigANR"); + sdnrSunnyDay(VSONH_TOSCA_COMPLIANT_POLICY, VSONH_ONSET, VSONH_SDNR_SUCCESS, SNDR_MODIFY_CONFIG_ANR_OP); } /** -- cgit 1.2.3-korg