summaryrefslogtreecommitdiffstats
path: root/controlloop/common/rules-test/src/test
diff options
context:
space:
mode:
authoradheli.tavares <adheli.tavares@est.tech>2023-08-30 14:57:10 +0100
committeradheli.tavares <adheli.tavares@est.tech>2023-09-22 16:08:42 +0100
commitfc19178b956f4474ed14e810fd911ac60f3756d0 (patch)
tree196af66a25ca190af8f2b2199f977a4e58aad8b3 /controlloop/common/rules-test/src/test
parentd7d54fef032a2ba3118232506a7ed37f24eb4131 (diff)
Upgrade Java 17 in policy-drools-apps
Issue-ID: POLICY-4816 Change-Id: I61d5c2c0b8bf2cc08416d91bbd84f27f2ed5c5c1 Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'controlloop/common/rules-test/src/test')
-rw-r--r--controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/BaseTestTest.java120
-rw-r--r--controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/DroolsRuleTestTest.java76
-rw-r--r--controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/ExceptionsTest.java9
-rw-r--r--controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/HttpClientsTest.java32
-rw-r--r--controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/ListenerTest.java61
-rw-r--r--controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/NamedRunner2Test.java20
-rw-r--r--controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/NamedRunnerTest.java33
-rw-r--r--controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/RulesTest.java105
-rw-r--r--controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/SimulatorExceptionTest.java7
-rw-r--r--controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/SimulatorsTest.java33
-rw-r--r--controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/TopicsTest.java84
-rw-r--r--controlloop/common/rules-test/src/test/resources/rulesTest.drl7
12 files changed, 263 insertions, 324 deletions
diff --git a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/BaseTestTest.java b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/BaseTestTest.java
index 0c8c6fb1c..cc2bda03e 100644
--- a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/BaseTestTest.java
+++ b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/BaseTestTest.java
@@ -21,11 +21,12 @@
package org.onap.policy.controlloop.common.rules.test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -37,14 +38,11 @@ import java.util.Queue;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Predicate;
import java.util.function.Supplier;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import org.onap.policy.appc.CommonHeader;
import org.onap.policy.appc.Request;
import org.onap.policy.appclcm.AppcLcmBody;
@@ -64,8 +62,7 @@ import org.onap.policy.sdnr.PciMessage;
import org.onap.policy.sdnr.PciRequest;
import org.springframework.test.util.ReflectionTestUtils;
-@RunWith(MockitoJUnitRunner.class)
-public class BaseTestTest {
+class BaseTestTest {
private static final String POLICY_NAME = "my-policy-name";
// saved values
@@ -81,33 +78,22 @@ public class BaseTestTest {
private int permitCount;
private int finalCount;
- @Mock
- private HttpClients httpClients;
- @Mock
- private Simulators simulators;
- @Mock
- private Topics topics;
- @Mock
- private Listener<VirtualControlLoopNotification> policyClMgt;
- @Mock
- private Listener<Request> appcClSink;
- @Mock
- private Listener<AppcLcmDmaapWrapper> appcLcmRead;
- @Mock
- private Listener<PciMessage> sdnrClSink;
- @Mock
- private DroolsController drools;
- @Mock
- private ToscaPolicy policy;
- @Mock
- private ToscaConceptIdentifier policyIdent;
-
+ private final HttpClients httpClients = mock(HttpClients.class);
+ private final Simulators simulators = mock(Simulators.class);
+ private final Topics topics = mock(Topics.class);
+ private final Listener<VirtualControlLoopNotification> policyClMgt = mock();
+ private final Listener<Request> appcClSink = mock();
+ private final Listener<AppcLcmDmaapWrapper> appcLcmRead = mock();
+ private final Listener<PciMessage> sdnrClSink = mock();
+ private final DroolsController drools = mock(DroolsController.class);
+ private final ToscaPolicy policy = mock(ToscaPolicy.class);
+ private final ToscaConceptIdentifier policyIdent = mock(ToscaConceptIdentifier.class);
/**
* Saves static values from the class.
*/
@SuppressWarnings("unchecked")
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
httpClientMaker = (Supplier<HttpClients>) ReflectionTestUtils.getField(BaseTest.class, "httpClientMaker");
simMaker = (Supplier<Simulators>) ReflectionTestUtils.getField(BaseTest.class, "simMaker");
@@ -117,7 +103,7 @@ public class BaseTestTest {
/**
* Restores static values.
*/
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
ReflectionTestUtils.setField(BaseTest.class, "httpClientMaker", httpClientMaker);
ReflectionTestUtils.setField(BaseTest.class, "simMaker", simMaker);
@@ -127,7 +113,7 @@ public class BaseTestTest {
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() {
when(topics.createListener(eq(BaseTest.POLICY_CL_MGT_TOPIC), eq(VirtualControlLoopNotification.class),
any(StandardCoder.class))).thenReturn(policyClMgt);
@@ -189,31 +175,31 @@ public class BaseTestTest {
}
@Test
- public void testInitStatics() {
+ void testInitStatics() {
assertSame(httpClients, BaseTest.httpClients);
assertSame(simulators, BaseTest.simulators);
}
@Test
- public void testFinishStatics() {
+ void testFinishStatics() {
BaseTest.finishStatics();
verify(httpClients).destroy();
verify(simulators).destroy();
}
@Test
- public void testInit() {
+ void testInit() {
assertSame(topics, BaseTest.getTopics());
}
@Test
- public void testFinish() {
+ void testFinish() {
base.finish();
verify(topics).destroy();
}
@Test
- public void testTestService123Compliant() {
+ void testTestService123Compliant() {
enqueueAppcLcm("restart", "restart", "restart", "restart", "rebuild", "migrate");
enqueueClMgt(ControlLoopNotificationType.OPERATION_SUCCESS);
enqueueClMgt(ControlLoopNotificationType.FINAL_SUCCESS);
@@ -234,9 +220,9 @@ public class BaseTestTest {
}
@Test
- public void testTestDuplicatesEvents() {
+ void testTestDuplicatesEvents() {
// the test expects the count to be incremented by 2 between calls
- AtomicLong count = new AtomicLong(5);
+ var count = new AtomicLong(5);
base = spy(base);
when(base.getCreateCount()).thenAnswer(args -> count.getAndAdd(2));
@@ -264,12 +250,12 @@ public class BaseTestTest {
}
@Test
- public void testTestVcpeSunnyDayCompliant() {
+ void testTestVcpeSunnyDayCompliant() {
checkAppcLcmPolicy("restart", base::testVcpeSunnyDayCompliant);
}
@Test
- public void testTestVcpeOnsetFloodPrevention() {
+ void testTestVcpeOnsetFloodPrevention() {
enqueueAppcLcm("restart");
enqueueClMgt(ControlLoopNotificationType.OPERATION_SUCCESS);
enqueueClMgt(ControlLoopNotificationType.FINAL_SUCCESS);
@@ -290,37 +276,37 @@ public class BaseTestTest {
}
@Test
- public void testTestVdnsSunnyDayCompliant() {
+ void testTestVdnsSunnyDayCompliant() {
checkHttpPolicy(base::testVdnsSunnyDayCompliant);
}
@Test
- public void testTestVdnsRainyDayCompliant() {
+ void testTestVdnsRainyDayCompliant() {
checkHttpPolicyCompliantFailure(base::testVdnsRainyDayCompliant);
}
@Test
- public void testTestVfwSunnyDayCompliant() {
+ void testTestVfwSunnyDayCompliant() {
checkAppcLegacyPolicy("ModifyConfig", base::testVfwSunnyDayCompliant);
}
@Test
- public void testTestVfwRainyDayOverallTimeout() {
+ void testTestVfwRainyDayOverallTimeout() {
checkAppcLegacyPolicyFinalFailure("ModifyConfig", base::testVfwRainyDayOverallTimeout);
}
@Test
- public void testTestVfwRainyDayCompliantTimeout() {
+ void testTestVfwRainyDayCompliantTimeout() {
checkAppcLegacyPolicyFinalFailure("ModifyConfig", base::testVfwRainyDayCompliantTimeout);
}
@Test
- public void testTestVpciSunnyDayCompliant() {
+ void testTestVpciSunnyDayCompliant() {
checkSdnrPolicy("ModifyConfig", base::testVpciSunnyDayCompliant);
}
@Test
- public void testTestVsonhSunnyDayCompliant() {
+ void testTestVsonhSunnyDayCompliant() {
checkSdnrPolicy("ModifyConfigANR", base::testVsonhSunnyDayCompliant);
}
@@ -453,7 +439,7 @@ public class BaseTestTest {
}
private void enqueueClMgt(ControlLoopNotificationType type) {
- VirtualControlLoopNotification notif = new VirtualControlLoopNotification();
+ var notif = new VirtualControlLoopNotification();
notif.setNotification(type);
notif.setPolicyName(POLICY_NAME + ".EVENT.MANAGER.FINAL");
@@ -461,17 +447,17 @@ public class BaseTestTest {
}
private void enqueueAppcLcm(String... operationNames) {
- for (String oper : operationNames) {
- AppcLcmDmaapWrapper req = new AppcLcmDmaapWrapper();
+ for (var oper : operationNames) {
+ var req = new AppcLcmDmaapWrapper();
req.setRpcName(oper);
- AppcLcmBody body = new AppcLcmBody();
+ var body = new AppcLcmBody();
req.setBody(body);
- AppcLcmInput input = new AppcLcmInput();
+ var input = new AppcLcmInput();
body.setInput(input);
- AppcLcmCommonHeader header = new AppcLcmCommonHeader();
+ var header = new AppcLcmCommonHeader();
input.setCommonHeader(header);
header.setSubRequestId("my-subrequest-id");
@@ -481,11 +467,11 @@ public class BaseTestTest {
}
private void enqueueAppcLegacy(String... operationNames) {
- for (String oper : operationNames) {
- Request req = new Request();
+ for (var oper : operationNames) {
+ var req = new Request();
req.setAction(oper);
- CommonHeader header = new CommonHeader();
+ var header = new CommonHeader();
req.setCommonHeader(header);
header.setSubRequestId("my-subrequest-id");
@@ -496,13 +482,13 @@ public class BaseTestTest {
private void enqueueSdnr(String... operationNames) {
for (String oper : operationNames) {
- PciMessage pcimessage = new PciMessage();
- PciRequest req = new PciRequest();
- PciBody body = new PciBody();
+ var pcimessage = new PciMessage();
+ var req = new PciRequest();
+ var body = new PciBody();
body.setInput(req);
pcimessage.setBody(body);
pcimessage.getBody().getInput().setAction(oper);
- PciCommonHeader header = new PciCommonHeader();
+ var header = new PciCommonHeader();
pcimessage.getBody().getInput().setCommonHeader(header);
header.setSubRequestId("my-subrequest-id");
@@ -526,7 +512,7 @@ public class BaseTestTest {
/*
* We don't want junit trying to run this, so it's marked "Ignore".
*/
- @Ignore
+ @Disabled
private class MyTest extends BaseTest {
@Override
diff --git a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/DroolsRuleTestTest.java b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/DroolsRuleTestTest.java
index 4b9f5774d..0b859adf0 100644
--- a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/DroolsRuleTestTest.java
+++ b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/DroolsRuleTestTest.java
@@ -21,11 +21,12 @@
package org.onap.policy.controlloop.common.rules.test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -35,15 +36,11 @@ import java.util.Queue;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.policy.appc.Request;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import org.onap.policy.appclcm.AppcLcmBody;
import org.onap.policy.appclcm.AppcLcmCommonHeader;
import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
@@ -53,13 +50,10 @@ import org.onap.policy.controlloop.ControlLoopNotificationType;
import org.onap.policy.controlloop.VirtualControlLoopNotification;
import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.system.PolicyController;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-import org.onap.policy.sdnr.PciMessage;
import org.springframework.test.util.ReflectionTestUtils;
-@RunWith(MockitoJUnitRunner.class)
-public class DroolsRuleTestTest {
+class DroolsRuleTestTest {
private static final String CONTROLLER_NAME = "my-controller-name";
private static final String POLICY_NAME = "my-policy-name";
@@ -76,37 +70,21 @@ public class DroolsRuleTestTest {
private int permitCount;
private int finalCount;
- @Mock
- private PolicyController controller;
- @Mock
- private Rules rules;
- @Mock
- private HttpClients httpClients;
- @Mock
- private Simulators simulators;
- @Mock
- private Topics topics;
- @Mock
- private Listener<VirtualControlLoopNotification> policyClMgt;
- @Mock
- private Listener<Request> appcClSink;
- @Mock
- private Listener<AppcLcmDmaapWrapper> appcLcmRead;
- @Mock
- private Listener<PciMessage> sdnrClSink;
- @Mock
- private DroolsController drools;
- @Mock
- private ToscaPolicy policy;
- @Mock
- private ToscaConceptIdentifier policyIdent;
-
+ private final PolicyController controller = mock(PolicyController.class);
+ private final Rules rules = mock(Rules.class);
+ private final HttpClients httpClients = mock(HttpClients.class);
+ private final Simulators simulators = mock(Simulators.class);
+ private final Topics topics = mock(Topics.class);
+ private final Listener<VirtualControlLoopNotification> policyClMgt = mock();
+ private final Listener<AppcLcmDmaapWrapper> appcLcmRead = mock();
+ private final DroolsController drools = mock(DroolsController.class);
+ private final ToscaPolicy policy = mock(ToscaPolicy.class);
/**
* Saves static values from the class.
*/
@SuppressWarnings("unchecked")
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
ruleMaker = (Function<String, Rules>) ReflectionTestUtils.getField(DroolsRuleTest.class, "ruleMaker");
httpClientMaker = (Supplier<HttpClients>) ReflectionTestUtils.getField(DroolsRuleTest.class, "httpClientMaker");
@@ -117,7 +95,7 @@ public class DroolsRuleTestTest {
/**
* Restores static values.
*/
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
ReflectionTestUtils.setField(DroolsRuleTest.class, "ruleMaker", ruleMaker);
ReflectionTestUtils.setField(DroolsRuleTest.class, "httpClientMaker", httpClientMaker);
@@ -128,7 +106,7 @@ public class DroolsRuleTestTest {
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() {
when(rules.getController()).thenReturn(controller);
when(rules.setupPolicyFromFile(any())).thenReturn(policy);
@@ -174,14 +152,14 @@ public class DroolsRuleTestTest {
}
@Test
- public void testInitStatics() {
+ void testInitStatics() {
assertSame(rules, DroolsRuleTest.rules);
assertSame(httpClients, DroolsRuleTest.httpClients);
assertSame(simulators, DroolsRuleTest.simulators);
}
@Test
- public void testFinishStatics() {
+ void testFinishStatics() {
DroolsRuleTest.finishStatics();
verify(rules).destroy();
@@ -190,13 +168,13 @@ public class DroolsRuleTestTest {
}
@Test
- public void testInit() {
+ void testInit() {
assertSame(topics, BaseTest.getTopics());
assertSame(controller, base.controller);
}
@Test
- public void testDroolsTestService123Compliant() {
+ void testDroolsTestService123Compliant() {
enqueueAppcLcm("restart", "restart", "restart", "restart", "rebuild", "migrate");
enqueueClMgt(ControlLoopNotificationType.OPERATION_SUCCESS);
enqueueClMgt(ControlLoopNotificationType.FINAL_SUCCESS);
@@ -263,7 +241,7 @@ public class DroolsRuleTestTest {
* We don't want junit trying to run this, so it's marked "Ignore".
*/
- @Ignore
+ @Disabled
private class MyDroolsTest extends DroolsRuleTest {
@Override
diff --git a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/ExceptionsTest.java b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/ExceptionsTest.java
index 737005eaa..03fadff1d 100644
--- a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/ExceptionsTest.java
+++ b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/ExceptionsTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,15 +21,15 @@
package org.onap.policy.controlloop.common.rules.test;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.test.ExceptionsTester;
-public class ExceptionsTest {
+class ExceptionsTest {
@Test
- public void test() {
+ void test() {
assertEquals(4, new ExceptionsTester().testAllException(TopicException.class));
assertEquals(4, new ExceptionsTester().testAllException(SimulatorException.class));
diff --git a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/HttpClientsTest.java b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/HttpClientsTest.java
index dac10df34..d4c068055 100644
--- a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/HttpClientsTest.java
+++ b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/HttpClientsTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,51 +22,46 @@
package org.onap.policy.controlloop.common.rules.test;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Properties;
-import org.junit.After;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.policy.common.endpoints.http.client.HttpClient;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.http.client.HttpClientConfigException;
import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.drools.persistence.SystemPersistenceConstants;
-@RunWith(MockitoJUnitRunner.class)
-public class HttpClientsTest {
+class HttpClientsTest {
private static final String CLIENT_NAME = "MY-CLIENT";
- @Mock
- private HttpClientFactory factory;
+ private final HttpClientFactory factory = mock(HttpClientFactory.class);
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
SystemPersistenceConstants.getManager().setConfigurationDir("src/test/resources");
}
- @After
+ @AfterEach
public void tearDown() {
HttpClientFactoryInstance.getClientFactory().destroy();
}
@Test
- public void test() throws HttpClientConfigException {
+ void test() throws HttpClientConfigException {
HttpClientFactoryInstance.getClientFactory().destroy();
- HttpClients clients = new HttpClients();
+ var clients = new HttpClients();
clients.addClients("my");
// should find the client now
- HttpClient client = HttpClientFactoryInstance.getClientFactory().get(CLIENT_NAME);
+ var client = HttpClientFactoryInstance.getClientFactory().get(CLIENT_NAME);
assertNotNull(client);
clients.destroy();
@@ -78,7 +74,7 @@ public class HttpClientsTest {
assertThatIllegalArgumentException().isThrownBy(() -> clients.addClients("unknown"));
// force exception from builder
- HttpClients clients2 = new HttpClients() {
+ var clients2 = new HttpClients() {
@Override
protected HttpClientFactory getClientFactory() {
return factory;
diff --git a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/ListenerTest.java b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/ListenerTest.java
index 7a7add5a7..ed30515bc 100644
--- a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/ListenerTest.java
+++ b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/ListenerTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,10 +23,11 @@ package org.onap.policy.controlloop.common.rules.test;
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;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -33,21 +35,17 @@ import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicSink;
import org.onap.policy.common.endpoints.parameters.TopicParameters;
-@RunWith(MockitoJUnitRunner.class)
-public class ListenerTest {
+class ListenerTest {
private static final String EXPECTED_EXCEPTION = "expected exception";
private static final String MY_TOPIC = "my-topic";
private static final String MESSAGE = "the-message";
@@ -55,21 +53,20 @@ public class ListenerTest {
private static final String MSG_SUFFIX = "s";
private static final String DECODED_MESSAGE = MESSAGE + MSG_SUFFIX;
- @Mock
- private NoopTopicSink sink;
- @Mock
- private TopicEndpoint mgr;
+ private final NoopTopicSink sink = mock(NoopTopicSink.class);
+
+ private final TopicEndpoint mgr = mock(TopicEndpoint.class);
private Listener<String> listener;
/**
* Creates topics.
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
TopicEndpointManager.getManager().shutdown();
- TopicParameters params = new TopicParameters();
+ var params = new TopicParameters();
params.setTopic(MY_TOPIC);
params.setManaged(true);
params.setTopicCommInfrastructure("NOOP");
@@ -77,7 +74,7 @@ public class ListenerTest {
TopicEndpointManager.getManager().addTopicSinks(List.of(params));
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
TopicEndpointManager.getManager().shutdown();
}
@@ -85,7 +82,7 @@ public class ListenerTest {
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() {
when(mgr.getNoopTopicSink(MY_TOPIC)).thenReturn(sink);
@@ -98,12 +95,12 @@ public class ListenerTest {
}
@Test
- public void testListener() {
+ void testListener() {
verify(sink).register(listener);
}
@Test
- public void testAwait_testAwaitLongTimeUnit_testIsEmpty() {
+ void testAwait_testAwaitLongTimeUnit_testIsEmpty() {
assertTrue(listener.isEmpty());
listener.onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, MESSAGE);
@@ -115,7 +112,7 @@ public class ListenerTest {
}
@Test
- public void testAwaitPredicateOfT() {
+ void testAwaitPredicateOfT() {
listener.onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, MESSAGE);
listener.onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, MESSAGE2);
assertEquals(MESSAGE2 + MSG_SUFFIX, listener.await(msg -> msg.startsWith("other-")));
@@ -125,7 +122,7 @@ public class ListenerTest {
* Tests await() when the remaining time is negative.
*/
@Test
- public void testAwaitLongTimeUnitPredicateNoTime() {
+ void testAwaitLongTimeUnitPredicateNoTime() {
assertThatThrownBy(() -> listener.await(-1, TimeUnit.SECONDS)).isInstanceOf(TopicException.class);
}
@@ -133,7 +130,7 @@ public class ListenerTest {
* Tests await() when the poll() returns {@code null}.
*/
@Test
- public void testAwaitLongTimeUnitPredicateNoMessage() {
+ void testAwaitLongTimeUnitPredicateNoMessage() {
assertThatThrownBy(() -> listener.await(1, TimeUnit.MILLISECONDS)).isInstanceOf(TopicException.class);
}
@@ -141,7 +138,7 @@ public class ListenerTest {
* Tests await() when the poll() is interrupted.
*/
@Test
- public void testAwaitLongTimeUnitPredicateInterrupted() throws InterruptedException {
+ void testAwaitLongTimeUnitPredicateInterrupted() throws InterruptedException {
listener = new Listener<String>(MY_TOPIC, msg -> msg) {
@Override
protected String pollMessage(long remainingMs) throws InterruptedException {
@@ -150,9 +147,9 @@ public class ListenerTest {
};
AtomicReference<TopicException> exref = new AtomicReference<>();
- CountDownLatch interrupted = new CountDownLatch(1);
+ var interrupted = new CountDownLatch(1);
- Thread thread = new Thread() {
+ var thread = new Thread() {
@Override
public void run() {
try {
@@ -173,13 +170,13 @@ public class ListenerTest {
}
@Test
- public void testUnregister() {
+ void testUnregister() {
listener.unregister();
verify(sink).unregister(listener);
}
@Test
- public void testOnTopicEvent() {
+ void testOnTopicEvent() {
listener = new Listener<>(MY_TOPIC, msg -> {
throw new IllegalArgumentException(EXPECTED_EXCEPTION);
});
@@ -193,7 +190,7 @@ public class ListenerTest {
}
@Test
- public void testGetTopicManager() {
+ void testGetTopicManager() {
// use a listener with a real manager
assertNotNull(new Listener<>(MY_TOPIC, msg -> msg).getTopicManager());
}
diff --git a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/NamedRunner2Test.java b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/NamedRunner2Test.java
index 91e19ce79..b61804c50 100644
--- a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/NamedRunner2Test.java
+++ b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/NamedRunner2Test.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,34 +21,33 @@
package org.onap.policy.controlloop.common.rules.test;
-import static org.junit.Assert.assertEquals;
-
-import org.junit.AfterClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
/**
* Tests NamedRunner when the TestNames annotation is missing - all tests should be
* executed.
*/
-@RunWith(NamedRunner.class)
-public class NamedRunner2Test {
+@ExtendWith(NamedRunner.class)
+class NamedRunner2Test {
private static int testCount = 0;
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
assertEquals(2, testCount);
}
@Test
- public void testAbc() {
+ void testAbc() {
checkTest();
}
@Test
- public void testDef() {
+ void testDef() {
checkTest();
}
diff --git a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/NamedRunnerTest.java b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/NamedRunnerTest.java
index fea440541..c9a13e225 100644
--- a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/NamedRunnerTest.java
+++ b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/NamedRunnerTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,42 +21,42 @@
package org.onap.policy.controlloop.common.rules.test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
-import org.junit.AfterClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
/**
* Tests NamedRunner. The tests don't do much, because all we really want to check is
* which tests are executed based on the {@link TestNames} annotation.
*/
-@RunWith(NamedRunner.class)
+@ExtendWith(NamedRunner.class)
@TestNames(names = {"testAbc", "testDef", "testIgnore"}, prefixes = {"testGhi", "testJkl"})
-public class NamedRunnerTest {
+class NamedRunnerTest {
private static int testCount = 0;
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
assertEquals(5, testCount);
}
@Test
- public void testAbc() {
+ void testAbc() {
checkTest();
}
@Test
- public void testAbc2() {
+ void testAbc2() {
fail("should not run");
}
@Test
- public void testDef() {
+ void testDef() {
checkTest();
}
@@ -64,23 +65,23 @@ public class NamedRunnerTest {
* NamedRunner skips over it, hence the sonar issue is being suppressed.
*/
@Test
- @Ignore
+ @Disabled
public void testIgnore() { // NOSONAR
fail("should not run");
}
@Test
- public void testGhi1() {
+ void testGhi1() {
checkTest();
}
@Test
- public void testGhi2() {
+ void testGhi2() {
checkTest();
}
@Test
- public void testJkl() {
+ void testJkl() {
checkTest();
}
diff --git a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/RulesTest.java b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/RulesTest.java
index a4767dfd9..82f39c189 100644
--- a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/RulesTest.java
+++ b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/RulesTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,10 +23,10 @@ package org.onap.policy.controlloop.common.rules.test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
@@ -42,11 +43,10 @@ import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.kie.api.definition.rule.Rule;
import org.kie.api.event.rule.AfterMatchFiredEvent;
import org.kie.api.event.rule.AgendaEventListener;
@@ -59,8 +59,6 @@ import org.kie.api.event.rule.ObjectUpdatedEvent;
import org.kie.api.event.rule.RuleRuntimeEventListener;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.Match;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
import org.onap.policy.common.utils.test.log.logback.ExtractAppender;
import org.onap.policy.controlloop.ControlLoopEvent;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
@@ -73,8 +71,7 @@ import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.slf4j.LoggerFactory;
-@RunWith(MockitoJUnitRunner.class)
-public class RulesTest {
+class RulesTest {
private static final String EXPECTED_EXCEPTION = "expected exception";
private static final String CONTROLLER_NAME = "rulesTest";
private static final String POLICY_FILE = "src/test/resources/tosca-policy.json";
@@ -89,18 +86,12 @@ public class RulesTest {
private static final Logger logger = (Logger) LoggerFactory.getLogger(Rules.class);
private static final ExtractAppender appender = new ExtractAppender();
- @Mock
- private PolicyEngine engine;
- @Mock
- private SystemPersistence repo;
- @Mock
- private PolicyController controller;
- @Mock
- private KieSession kieSession;
- @Mock
- private PolicyControllerFactory controllerFactory;
- @Mock
- private DroolsController drools;
+ private final PolicyEngine engine = mock(PolicyEngine.class);
+ private final SystemPersistence repo = mock(SystemPersistence.class);
+ private final PolicyController controller = mock(PolicyController.class);
+ private final KieSession kieSession = mock(KieSession.class);
+ private final PolicyControllerFactory controllerFactory = mock(PolicyControllerFactory.class);
+ private final DroolsController drools = mock(DroolsController.class);
private List<Object> facts;
private List<RuleRuntimeEventListener> ruleListeners;
@@ -113,7 +104,7 @@ public class RulesTest {
/**
* Attaches the appender to the logger.
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws Exception {
/*
* Attach appender to the logger.
@@ -127,7 +118,7 @@ public class RulesTest {
/**
* Stops the appender.
*/
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
appender.stop();
}
@@ -135,7 +126,7 @@ public class RulesTest {
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() {
facts = new LinkedList<>();
ruleListeners = new LinkedList<>();
@@ -148,13 +139,13 @@ public class RulesTest {
when(controller.getDrools()).thenReturn(drools);
when(drools.facts(eq(CONTROLLER_NAME), any())).thenAnswer(args -> {
- Class<?> clazz = args.getArgument(1);
+ var clazz = args.getArgument(1);
return facts.stream().filter(obj -> obj.getClass() == clazz).collect(Collectors.toList());
});
// notify listeners when objects are added to drools
when(drools.offer(any())).thenAnswer(args -> {
- Object object = args.getArgument(0);
+ var object = args.getArgument(0);
notifyInserted(object);
if (!(object instanceof ToscaPolicy)) {
@@ -162,8 +153,8 @@ public class RulesTest {
}
// "insert" Params objects associated with the policy (i.e., mimic the rules)
- ToscaPolicy policy = (ToscaPolicy) object;
- ControlLoopParams params = new ControlLoopParams();
+ var policy = (ToscaPolicy) object;
+ var params = new ControlLoopParams();
params.setToscaPolicy(policy);
notifyInserted(params);
@@ -171,7 +162,7 @@ public class RulesTest {
});
when(drools.delete(any())).thenAnswer(args -> {
- Class<?> clazz = args.getArgument(0);
+ var clazz = args.getArgument(0);
facts.removeIf(obj -> obj.getClass() == clazz);
return null;
});
@@ -200,7 +191,7 @@ public class RulesTest {
}
@Test
- public void testRules() {
+ void testRules() {
assertEquals(CONTROLLER_NAME, rules.getControllerName());
assertSame(engine, rules.getPdpd());
@@ -209,7 +200,7 @@ public class RulesTest {
}
@Test
- public void testStart() throws Exception {
+ void testStart() throws Exception {
verify(repo).setConfigurationDir("src/test/resources/config");
assertTrue(installed);
verify(engine).configure(any(Properties.class));
@@ -221,7 +212,7 @@ public class RulesTest {
}
@Test
- public void testDestroy() {
+ void testDestroy() {
rules.destroy();
verify(controllerFactory).shutdown(CONTROLLER_NAME);
@@ -229,7 +220,7 @@ public class RulesTest {
}
@Test
- public void testResetFacts() {
+ void testResetFacts() {
rules.resetFacts();
verify(drools).delete(ToscaPolicy.class);
@@ -239,7 +230,7 @@ public class RulesTest {
}
@Test
- public void testSetupPolicyFromTemplate_testGetPolicyFromTemplate() throws InterruptedException {
+ void testSetupPolicyFromTemplate_testGetPolicyFromTemplate() throws InterruptedException {
rules.setupPolicyFromTemplate("tosca-template.json", MY_POLICY);
assertThatIllegalArgumentException()
@@ -251,7 +242,7 @@ public class RulesTest {
}
@Test
- public void testSetupPolicyFromFile_testGetPolicyFromFile_testSetupPolicy() throws InterruptedException {
+ void testSetupPolicyFromFile_testGetPolicyFromFile_testSetupPolicy() throws InterruptedException {
assertNotNull(rules.setupPolicyFromFile(POLICY_FILE));
assertThatIllegalArgumentException().isThrownBy(() -> rules.setupPolicyFromFile("missing-file.json"));
@@ -261,26 +252,26 @@ public class RulesTest {
}
@Test
- public void testRuleListenerLogger() {
- Rule rule = mock(Rule.class);
+ void testRuleListenerLogger() {
+ var rule = mock(Rule.class);
when(rule.getName()).thenReturn(MY_RULE_NAME);
// insertions - with and without rule name
- ObjectInsertedEvent insert = mock(ObjectInsertedEvent.class);
+ var insert = mock(ObjectInsertedEvent.class);
when(insert.getObject()).thenReturn(MY_TEXT);
checkLogging("inserted", () -> ruleListeners.forEach(listener -> listener.objectInserted(insert)));
when(insert.getRule()).thenReturn(rule);
checkLogging("inserted", () -> ruleListeners.forEach(listener -> listener.objectInserted(insert)));
// updates - with and without rule name
- ObjectUpdatedEvent update = mock(ObjectUpdatedEvent.class);
+ var update = mock(ObjectUpdatedEvent.class);
when(update.getObject()).thenReturn(MY_TEXT);
checkLogging("updated", () -> ruleListeners.forEach(listener -> listener.objectUpdated(update)));
when(update.getRule()).thenReturn(rule);
checkLogging("updated", () -> ruleListeners.forEach(listener -> listener.objectUpdated(update)));
// deletions - with and without rule name
- ObjectDeletedEvent delete = mock(ObjectDeletedEvent.class);
+ var delete = mock(ObjectDeletedEvent.class);
when(delete.getOldObject()).thenReturn(MY_TEXT);
checkLogging("deleted", () -> ruleListeners.forEach(listener -> listener.objectDeleted(delete)));
when(delete.getRule()).thenReturn(rule);
@@ -288,25 +279,25 @@ public class RulesTest {
}
@Test
- public void testAgendaListenerLogger() {
- Rule rule = mock(Rule.class);
+ void testAgendaListenerLogger() {
+ var rule = mock(Rule.class);
when(rule.getName()).thenReturn(MY_RULE_NAME);
- Match match = mock(Match.class);
+ var match = mock(Match.class);
when(match.getRule()).thenReturn(rule);
// create
- MatchCreatedEvent create = mock(MatchCreatedEvent.class);
+ var create = mock(MatchCreatedEvent.class);
when(create.getMatch()).thenReturn(match);
checkLogging("match created", () -> agendaListeners.forEach(listener -> listener.matchCreated(create)));
// cancel
- MatchCancelledEvent cancel = mock(MatchCancelledEvent.class);
+ var cancel = mock(MatchCancelledEvent.class);
when(cancel.getMatch()).thenReturn(match);
checkLogging("match cancelled", () -> agendaListeners.forEach(listener -> listener.matchCancelled(cancel)));
// before-fire
- BeforeMatchFiredEvent before = mock(BeforeMatchFiredEvent.class);
+ var before = mock(BeforeMatchFiredEvent.class);
when(before.getMatch()).thenReturn(match);
// @formatter:off
checkLogging("before match fired",
@@ -314,13 +305,13 @@ public class RulesTest {
// @formatter:on
// after-fire
- AfterMatchFiredEvent after = mock(AfterMatchFiredEvent.class);
+ var after = mock(AfterMatchFiredEvent.class);
when(after.getMatch()).thenReturn(match);
checkLogging("after match fired", () -> agendaListeners.forEach(listener -> listener.afterMatchFired(after)));
}
@Test
- public void testMakePdpd_testMakePdpdRepo() {
+ void testMakePdpd_testMakePdpdRepo() {
// need rules that makes real objects
rules = new Rules(CONTROLLER_NAME);
@@ -340,7 +331,7 @@ public class RulesTest {
BlockingQueue<IllegalArgumentException> exceptions = new LinkedBlockingQueue<>();
- Thread thread = new Thread(() -> {
+ var thread = new Thread(() -> {
try {
command.run();
} catch (IllegalArgumentException e) {
@@ -358,7 +349,7 @@ public class RulesTest {
private void checkLogging(String expectedMsg, Runnable command) {
appender.clearExtractions();
command.run();
- List<String> messages = appender.getExtracted();
+ var messages = appender.getExtracted();
assertEquals(1, messages.size());
assertThat(messages.get(0)).contains(expectedMsg);
}
@@ -368,17 +359,17 @@ public class RulesTest {
facts.add(object);
// increase code coverage by adding random objects
- ObjectInsertedEvent event0 = mock(ObjectInsertedEvent.class);
+ var event0 = mock(ObjectInsertedEvent.class);
when(event0.getObject()).thenReturn(new Object());
ruleListeners.forEach(listener -> listener.objectInserted(event0));
// increase code coverage by adding a random object
- ObjectInsertedEvent event = mock(ObjectInsertedEvent.class);
+ var event = mock(ObjectInsertedEvent.class);
when(event.getObject()).thenReturn(object);
if (object instanceof ToscaPolicy) {
// increase code coverage by associating it with a random rule
- Rule rule = mock(Rule.class);
+ var rule = mock(Rule.class);
when(rule.getName()).thenReturn(MY_RULE_NAME);
when(event.getRule()).thenReturn(rule);
}
diff --git a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/SimulatorExceptionTest.java b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/SimulatorExceptionTest.java
index 0dee6d4be..b2e524463 100644
--- a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/SimulatorExceptionTest.java
+++ b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/SimulatorExceptionTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,13 +21,13 @@
package org.onap.policy.controlloop.common.rules.test;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.test.ExceptionsTester;
-public class SimulatorExceptionTest {
+class SimulatorExceptionTest {
@Test
- public void test() {
+ void test() {
new ExceptionsTester().test(SimulatorException.class);
}
}
diff --git a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/SimulatorsTest.java b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/SimulatorsTest.java
index 3a98c0078..726f31105 100644
--- a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/SimulatorsTest.java
+++ b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/SimulatorsTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,44 +22,38 @@
package org.onap.policy.controlloop.common.rules.test;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.controlloop.common.rules.test.Simulators.SimulatorBuilder;
-@RunWith(MockitoJUnitRunner.class)
-public class SimulatorsTest {
+class SimulatorsTest {
private static final String EXPECTED_EXCEPTION = "expected exception";
- @Mock
- private HttpServletServer server1;
- @Mock
- private HttpServletServer server2;
- @Mock
- private HttpServletServer server3;
+ private final HttpServletServer server1 = mock(HttpServletServer.class);
+ private final HttpServletServer server2 = mock(HttpServletServer.class);
+ private final HttpServletServer server3 = mock(HttpServletServer.class);
private Simulators simulators;
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() {
simulators = new Simulators();
}
@Test
- public void testStart() {
+ void testStart() {
simulators.start(() -> server1, () -> server2);
assertEquals(List.of(server1, server2), simulators.getServers());
@@ -70,7 +65,7 @@ public class SimulatorsTest {
* Tests start() when one of the builders throws an exception.
*/
@Test
- public void testStartException() {
+ void testStartException() {
SimulatorBuilder exbuilder = () -> {
throw new InterruptedException(EXPECTED_EXCEPTION);
};
@@ -88,7 +83,7 @@ public class SimulatorsTest {
}
@Test
- public void testDestroy() {
+ void testDestroy() {
simulators.start(() -> server1, () -> server2, () -> server3);
doThrow(new IllegalStateException(EXPECTED_EXCEPTION)).when(server2).shutdown();
diff --git a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/TopicsTest.java b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/TopicsTest.java
index 409c3d472..9bf0d22b7 100644
--- a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/TopicsTest.java
+++ b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/TopicsTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,8 +23,9 @@ package org.onap.policy.controlloop.common.rules.test;
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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -33,13 +35,10 @@ import java.nio.file.Paths;
import java.util.List;
import java.util.concurrent.TimeUnit;
import lombok.ToString;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
@@ -53,8 +52,7 @@ import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
import org.onap.policy.drools.system.PolicyController;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-@RunWith(MockitoJUnitRunner.class)
-public class TopicsTest {
+class TopicsTest {
private static final String EXPECTED_EXCEPTION = "expected exception";
private static final String MY_SOURCE_TOPIC = "my-source-topic";
private static final String MY_SINK_TOPIC = "my-sink-topic";
@@ -65,18 +63,12 @@ public class TopicsTest {
private static final String INJECT_FILE = "src/test/resources/topics.json";
private static final String POLICY_NAME = "my-policy";
- @Mock
- private DroolsController drools;
- @Mock
- private PolicyController controller;
- @Mock
- private EventProtocolCoder protocolCoder;
- @Mock
- private NoopTopicSink sink;
- @Mock
- private NoopTopicSource source;
- @Mock
- private TopicEndpoint mgr;
+ private final DroolsController drools = mock(DroolsController.class);
+ private final PolicyController controller = mock(PolicyController.class);
+ private final EventProtocolCoder protocolCoder = mock(EventProtocolCoder.class);
+ private final NoopTopicSink sink = mock(NoopTopicSink.class);
+ private final NoopTopicSource source = mock(NoopTopicSource.class);
+ private final TopicEndpoint mgr = mock(TopicEndpoint.class);
private ToscaPolicy policy;
@@ -85,18 +77,18 @@ public class TopicsTest {
/**
* Creates topics.
*/
- @BeforeClass
- public static void setUpBeforeClass() {
+ @BeforeAll
+ static void setUpBeforeClass() {
TopicEndpointManager.getManager().shutdown();
- TopicParameters params = new TopicParameters();
+ var params = new TopicParameters();
params.setTopic(MY_SOURCE_TOPIC);
params.setManaged(true);
params.setTopicCommInfrastructure("NOOP");
TopicEndpointManager.getManager().addTopicSources(List.of(params));
}
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
TopicEndpointManager.getManager().shutdown();
}
@@ -104,7 +96,7 @@ public class TopicsTest {
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() {
policy = new ToscaPolicy();
policy.setName(POLICY_NAME);
@@ -134,9 +126,9 @@ public class TopicsTest {
}
@Test
- public void testDestroy() {
- Listener<String> listener1 = topics.createListener(MY_SINK_TOPIC, msg -> msg);
- Listener<String> listener2 = topics.createListener(MY_SINK_TOPIC, msg -> msg + "a suffix");
+ void testDestroy() {
+ var listener1 = topics.createListener(MY_SINK_TOPIC, msg -> msg);
+ var listener2 = topics.createListener(MY_SINK_TOPIC, msg -> msg + "a suffix");
topics.destroy();
@@ -145,20 +137,20 @@ public class TopicsTest {
}
@Test
- public void testInjectStringFile() throws IOException {
+ void testInjectStringFile() throws IOException {
topics.inject(MY_SOURCE_TOPIC, INJECT_FILE);
// nothing should have been replaced
- String expected = new String(Files.readAllBytes(Paths.get(INJECT_FILE)));
+ var expected = new String(Files.readAllBytes(Paths.get(INJECT_FILE)));
verify(source).offer(expected);
}
@Test
- public void testInjectStringFileString() throws IOException {
+ void testInjectStringFileString() throws IOException {
topics.inject(MY_SOURCE_TOPIC, INJECT_FILE, "hello");
// text should have been replaced with "hello"
- String expected = new String(Files.readAllBytes(Paths.get("src", "test", "resources", "topicsReplaced.json")));
+ var expected = new String(Files.readAllBytes(Paths.get("src", "test", "resources", "topicsReplaced.json")));
verify(source).offer(expected);
// exception reading file
@@ -167,19 +159,19 @@ public class TopicsTest {
}
@Test
- public void testCreateListenerStringClassOfTPolicyController() {
- Listener<String> listener = topics.createListener(MY_SINK_TOPIC, String.class, controller);
+ void testCreateListenerStringClassOfTPolicyController() {
+ var listener = topics.createListener(MY_SINK_TOPIC, String.class, controller);
listener.onTopicEvent(CommInfrastructure.NOOP, MY_SINK_TOPIC, MESSAGE);
assertEquals(TEXT, listener.await());
}
@Test
- public void testCreateListenerStringClassOfTCoder() {
- Listener<Data> listener = topics.createListener(MY_SINK_TOPIC, Data.class, new StandardCoder());
+ void testCreateListenerStringClassOfTCoder() {
+ var listener = topics.createListener(MY_SINK_TOPIC, Data.class, new StandardCoder());
listener.onTopicEvent(CommInfrastructure.NOOP, MY_SINK_TOPIC, MESSAGE);
- Data expected = new Data();
+ var expected = new Data();
expected.text = TEXT;
assertEquals(expected.toString(), listener.await().toString());
}
@@ -188,15 +180,15 @@ public class TopicsTest {
* Tests createListener() when the coder throws an exception.
*/
@Test
- public void testCreateListenerStringClassOfTCoderException() {
- StandardCoder coder = new StandardCoder() {
+ void testCreateListenerStringClassOfTCoderException() {
+ var coder = new StandardCoder() {
@Override
public <T> T decode(String arg0, Class<T> arg1) throws CoderException {
throw new CoderException(EXPECTED_EXCEPTION);
}
};
- Listener<Data> listener = topics.createListener(MY_SINK_TOPIC, Data.class, coder);
+ var listener = topics.createListener(MY_SINK_TOPIC, Data.class, coder);
// onTopicEvent() should not throw an exception
assertThatCode(() -> listener.onTopicEvent(CommInfrastructure.NOOP, MY_SINK_TOPIC, MESSAGE))
@@ -207,15 +199,15 @@ public class TopicsTest {
}
@Test
- public void testCreateListenerStringFunctionOfStringT() {
- Listener<String> listener = topics.createListener(MY_SINK_TOPIC, msg -> msg);
+ void testCreateListenerStringFunctionOfStringT() {
+ var listener = topics.createListener(MY_SINK_TOPIC, msg -> msg);
listener.onTopicEvent(CommInfrastructure.NOOP, MY_SINK_TOPIC, MESSAGE);
assertEquals(MESSAGE, listener.await());
}
@Test
- public void testGetTopicManager_testGetProtocolCoder() {
+ void testGetTopicManager_testGetProtocolCoder() {
// use a topic with a real manager
topics = new Topics();
diff --git a/controlloop/common/rules-test/src/test/resources/rulesTest.drl b/controlloop/common/rules-test/src/test/resources/rulesTest.drl
index 734282ee9..a1a89714a 100644
--- a/controlloop/common/rules-test/src/test/resources/rulesTest.drl
+++ b/controlloop/common/rules-test/src/test/resources/rulesTest.drl
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,7 +53,7 @@ rule "INSERT.PARAMS"
$params : ControlLoopParams()
then
- Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage());
+ Logger logger = LoggerFactory.getLogger(drools.getRule().getPackageName());
logger.info("{}: {} : TOSCA-POLICY=[{}]", $params.getClosedLoopControlName(), $params.getPolicyName() + "."
+ drools.getRule().getName(), $params.getToscaPolicy());
end
@@ -67,7 +68,7 @@ rule "NEW.TOSCA.POLICY"
$policy : ToscaPolicy()
then
- Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage());
+ Logger logger = LoggerFactory.getLogger(drools.getRule().getPackageName());
logger.info("{}: [{}|{}|{}|{}]: CONTENT: {}", drools.getRule().getName(),
$policy.getType(), $policy.getTypeVersion(), $policy.getName(),
$policy.getVersion(), $policy);
@@ -87,7 +88,7 @@ rule "REMOVE.PARAMS"
not ( ToscaPolicy( getName() == $policyName, getVersion() == $policyVersion ) )
then
- Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage());
+ Logger logger = LoggerFactory.getLogger(drools.getRule().getPackageName());
logger.info("{}: [{}|{}|{}]", drools.getRule().getName(),
$params.getPolicyScope(), $params.getPolicyName(), $params.getPolicyVersion());