summaryrefslogtreecommitdiffstats
path: root/controlloop/common/rules-test/src/main
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-03-17 09:52:03 -0400
committerJim Hahn <jrh3@att.com>2020-03-17 10:37:31 -0400
commit01cbeec256bf5ec9e3ec2e7f599aef7eb4814ae3 (patch)
treefbdeaaa4bec64e1829696187ebaa64d902e5eed6 /controlloop/common/rules-test/src/main
parentf71f1109d08c3ca1da43c7122bce0fedb4d0027e (diff)
More sonar fixes in drools-apps
Issue-ID: POLICY-2426 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: Idfdcb229d05ee7f0220f44f8099284caaed754d4
Diffstat (limited to 'controlloop/common/rules-test/src/main')
-rw-r--r--controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTest.java13
-rw-r--r--controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Listener.java2
-rw-r--r--controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Rules.java28
3 files changed, 28 insertions, 15 deletions
diff --git a/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTest.java b/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTest.java
index 711a61738..1de02e54c 100644
--- a/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTest.java
+++ b/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTest.java
@@ -44,6 +44,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
* Superclass used for rule tests.
*/
public abstract class BaseRuleTest {
+ private static final String APPC_RESTART_OP = "restart";
+
/*
* Canonical Topic Names.
*/
@@ -185,7 +187,7 @@ public abstract class BaseRuleTest {
// restart request should be sent and fail four times (i.e., because retry=3)
for (int count = 0; count < 4; ++count) {
- AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> "restart".equals(req.getRpcName()));
+ AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> APPC_RESTART_OP.equals(req.getRpcName()));
topics.inject(APPC_LCM_WRITE_TOPIC, SERVICE123_APPC_RESTART_FAILURE,
appcreq.getBody().getInput().getCommonHeader().getSubRequestId());
@@ -245,7 +247,7 @@ public abstract class BaseRuleTest {
// should see two restarts
for (int count = 0; count < 2; ++count) {
- AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> "restart".equals(req.getRpcName()));
+ AppcLcmDmaapWrapper appcreq = appcLcmRead.await(req -> APPC_RESTART_OP.equals(req.getRpcName()));
// indicate success
topics.inject(APPC_LCM_WRITE_TOPIC, DUPLICATES_APPC_SUCCESS,
@@ -270,7 +272,7 @@ public abstract class BaseRuleTest {
*/
@Test
public void testVcpeSunnyDayLegacy() {
- appcLcmSunnyDay(VCPE_TOSCA_LEGACY_POLICY, VCPE_ONSET_1, "restart");
+ appcLcmSunnyDay(VCPE_TOSCA_LEGACY_POLICY, VCPE_ONSET_1, APPC_RESTART_OP);
}
/**
@@ -278,7 +280,7 @@ public abstract class BaseRuleTest {
*/
@Test
public void testVcpeSunnyDayCompliant() {
- appcLcmSunnyDay(VCPE_TOSCA_COMPLIANT_POLICY, VCPE_ONSET_1, "restart");
+ appcLcmSunnyDay(VCPE_TOSCA_COMPLIANT_POLICY, VCPE_ONSET_1, APPC_RESTART_OP);
}
/**
@@ -288,7 +290,8 @@ public abstract class BaseRuleTest {
*/
@Test
public void testVcpeOnsetFloodPrevention() {
- appcLcmSunnyDay(VCPE_TOSCA_COMPLIANT_POLICY, List.of(VCPE_ONSET_1, VCPE_ONSET_2, VCPE_ONSET_3), "restart");
+ appcLcmSunnyDay(VCPE_TOSCA_COMPLIANT_POLICY, List.of(VCPE_ONSET_1, VCPE_ONSET_2, VCPE_ONSET_3),
+ APPC_RESTART_OP);
}
// VDNS
diff --git a/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Listener.java b/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Listener.java
index 5042f54c6..a353c98fb 100644
--- a/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Listener.java
+++ b/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Listener.java
@@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory;
*/
public class Listener<T> implements TopicListener {
private static final Logger logger = LoggerFactory.getLogger(Listener.class);
- public static long DEFAULT_WAIT_SEC = 5L;
+ private static final long DEFAULT_WAIT_SEC = 5L;
private final TopicSink sink;
private final Function<String, T> decoder;
diff --git a/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Rules.java b/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Rules.java
index 7549c6be6..2e15895bc 100644
--- a/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Rules.java
+++ b/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Rules.java
@@ -74,6 +74,7 @@ import org.slf4j.LoggerFactory;
public class Rules {
private static final Logger logger = LoggerFactory.getLogger(Rules.class);
private static final StandardCoder coder = new StandardCoder();
+ private static final String POLICY_MSG = "policy ";
/**
* PDP-D Engine.
@@ -116,7 +117,7 @@ public class Rules {
File kmoduleFile = new File(resourceDir + "/META-INF/kmodule.xml");
File pomFile = new File("src/test/resources/" + controllerName + ".pom");
String resourceDir2 = resourceDir + "/org/onap/policy/controlloop/";
- File ruleFile = new File(resourceDir + "/" + controllerName + ".drl");
+ File ruleFile = new File(resourceDir + File.separator + controllerName + ".drl");
List<File> ruleFiles = Collections.singletonList(ruleFile);
installArtifact(kmoduleFile, pomFile, resourceDir2, ruleFiles);
@@ -181,8 +182,12 @@ public class Rules {
try {
return setupPolicy(getPolicyFromTemplate(templatePath, policyName));
- } catch (InterruptedException | CoderException e) {
- throw new IllegalArgumentException("policy " + policyName, e);
+ } catch (CoderException e) {
+ throw new IllegalArgumentException(POLICY_MSG + policyName, e);
+
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new IllegalArgumentException(POLICY_MSG + policyName, e);
}
}
@@ -218,12 +223,16 @@ public class Rules {
try {
return setupPolicy(getPolicyFromFile(policyPath));
- } catch (InterruptedException | IOException | CoderException e) {
- throw new IllegalArgumentException("policy " + policyPath, e);
+ } catch (CoderException e) {
+ throw new IllegalArgumentException(POLICY_MSG + policyPath, e);
+
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new IllegalArgumentException(POLICY_MSG + policyPath, e);
}
}
- private ToscaPolicy getPolicyFromFile(String policyPath) throws IOException, CoderException {
+ private ToscaPolicy getPolicyFromFile(String policyPath) throws CoderException {
String policyJson = ResourceUtils.getResourceAsString(policyPath);
if (policyJson == null) {
throw new CoderException(new FileNotFoundException(policyPath));
@@ -232,7 +241,7 @@ public class Rules {
return coder.decode(policyJson, ToscaPolicy.class);
}
- private ToscaPolicy setupPolicy(ToscaPolicy policy) throws InterruptedException {
+ protected ToscaPolicy setupPolicy(ToscaPolicy policy) throws InterruptedException {
final KieObjectExpectedCallback<?> policyTracker = new KieObjectInsertedExpectedCallback<>(policy);
final KieObjectExpectedCallback<?> paramsTracker =
new KieClassInsertedExpectedCallback<>(ControlLoopParams.class);
@@ -243,10 +252,10 @@ public class Rules {
assertTrue(paramsTracker.isNotified());
assertEquals(1, controller.getDrools().facts(controllerName, ToscaPolicy.class).stream()
- .filter((anotherPolicy) -> anotherPolicy == policy).count());
+ .filter(anotherPolicy -> anotherPolicy == policy).count());
assertEquals(1, controller.getDrools().facts(controllerName, ControlLoopParams.class).stream()
- .filter((params) -> params.getToscaPolicy() == policy).count());
+ .filter(params -> params.getToscaPolicy() == policy).count());
return policy;
}
@@ -377,6 +386,7 @@ public class Rules {
super(affected);
}
+ @Override
public void objectInserted(ObjectInsertedEvent event) {
if (subject == event.getObject().getClass()) {
callbacked();