summaryrefslogtreecommitdiffstats
path: root/policy-core
diff options
context:
space:
mode:
Diffstat (limited to 'policy-core')
-rw-r--r--policy-core/pom.xml4
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java15
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java11
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/jmx/PdpJmx.java3
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/lock/AlwaysFailLock.java3
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/core/lock/AlwaysSuccessLock.java3
-rw-r--r--policy-core/src/main/java/org/onap/policy/drools/util/FeatureEnabledChecker.java5
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/core/DroolsContainerTest.java41
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionFeatureApiMock.java16
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionFeatureApiTest.java16
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionTest.java27
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/core/jmx/PdpJmxTest.java25
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysFailLockTest.java19
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysLockBaseTest.java9
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysSuccessLockTest.java23
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/core/lock/LockImplTest.java47
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/util/FeatureEnabledCheckerTest.java11
-rw-r--r--policy-core/src/test/java/org/onap/policy/drools/util/KieUtilsTest.java35
-rw-r--r--policy-core/src/test/resources/drools-artifact-1.1/src/main/resources/META-INF/kmodule.xml2
-rw-r--r--policy-core/src/test/resources/drools-artifact-1.2/src/main/resources/META-INF/kmodule.xml2
20 files changed, 160 insertions, 157 deletions
diff --git a/policy-core/pom.xml b/policy-core/pom.xml
index a9f47311..0a743e86 100644
--- a/policy-core/pom.xml
+++ b/policy-core/pom.xml
@@ -61,10 +61,6 @@
-->
<exclusions>
<exclusion>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-utils</artifactId>
- </exclusion>
- <exclusion>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java
index 1eab676f..ec5ceb21 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicyContainer.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,12 +47,12 @@ import org.slf4j.LoggerFactory;
*/
public class PolicyContainer implements Startable {
// get an instance of logger
- private static Logger logger = LoggerFactory.getLogger(PolicyContainer.class);
+ private static final Logger logger = LoggerFactory.getLogger(PolicyContainer.class);
// 'KieServices' singleton
private static KieServices kieServices = KieServices.Factory.get();
// set of all 'PolicyContainer' instances
- private static HashSet<PolicyContainer> containers = new HashSet<>();
+ private static final HashSet<PolicyContainer> containers = new HashSet<>();
// maps feature objects to per-PolicyContainer data
private ConcurrentHashMap<Object, Object> adjuncts = new ConcurrentHashMap<>();
@@ -65,7 +66,7 @@ public class PolicyContainer implements Startable {
private volatile boolean isStarted = false;
// maps session name into the associated 'PolicySession' instance
- private HashMap<String, PolicySession> sessions = new HashMap<>();
+ private final HashMap<String, PolicySession> sessions = new HashMap<>();
// if not null, this is a 'KieScanner' looking for updates
private KieScanner scanner = null;
@@ -171,7 +172,7 @@ public class PolicyContainer implements Startable {
}
}
if (exception != null) {
- // all of the 'newKieContainer' invocations failed -- throw the
+ // all the 'newKieContainer' invocations failed -- throw the
// most recent exception
throw exception;
}
@@ -263,7 +264,7 @@ public class PolicyContainer implements Startable {
PolicySession session = null;
KieSession kieSession = null;
- // loop through all of the features, and give each one
+ // loop through all the features, and give each one
// a chance to create the 'KieSession'
for (PolicySessionFeatureApi feature : PolicySessionFeatureApiConstants.getImpl().getList()) {
try {
@@ -432,7 +433,7 @@ public class PolicyContainer implements Startable {
/**
* Get policy sessions.
*
- * @return all of the 'PolicySession' instances
+ * @return all the 'PolicySession' instances
*/
public Collection<PolicySession> getPolicySessions() {
// KLUDGE WARNING: this is a temporary workaround -- if there are
@@ -703,7 +704,7 @@ public class PolicyContainer implements Startable {
var configDir = "config";
logger.info("PolicyContainer.main: configDir={}", configDir);
- // invoke 'globalInit' on all of the features
+ // invoke 'globalInit' on all the features
for (PolicySessionFeatureApi feature : PolicySessionFeatureApiConstants.getImpl().getList()) {
try {
feature.globalInit(args, configDir);
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java
index 1f8a61c6..0c10e984 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/PolicySession.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,14 +50,12 @@ import org.slf4j.LoggerFactory;
* 2) Access to UEB
* 3) Logging of events
*/
-public class PolicySession
- implements AgendaEventListener, RuleRuntimeEventListener {
+public class PolicySession implements AgendaEventListener, RuleRuntimeEventListener {
// get an instance of logger
- private static Logger logger = LoggerFactory.getLogger(PolicySession.class);
+ private static final Logger logger = LoggerFactory.getLogger(PolicySession.class);
// supports 'getCurrentSession()' method
- private static ThreadLocal<PolicySession> policySess =
- new ThreadLocal<>();
+ private static ThreadLocal<PolicySession> policySess = new ThreadLocal<>();
// name of the 'PolicySession' and associated 'KieSession'
@Getter
@@ -115,7 +114,7 @@ public class PolicySession
return;
}
- // loop through all of the features, and give each one
+ // loop through all the features, and give each one
// a chance to create the 'ThreadModel'
for (PolicySessionFeatureApi feature :
PolicySessionFeatureApiConstants.getImpl().getList()) {
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/jmx/PdpJmx.java b/policy-core/src/main/java/org/onap/policy/drools/core/jmx/PdpJmx.java
index 0f4add77..4356d111 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/jmx/PdpJmx.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/jmx/PdpJmx.java
@@ -3,6 +3,7 @@
* policy-core
* ================================================================================
* Copyright (C) 2017-2018, 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,7 +42,7 @@ public class PdpJmx implements PdpJmxMBean {
return actions.longValue();
}
- public void updateOccured() {
+ public void updateOccurred() {
updates.incrementAndGet();
}
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/lock/AlwaysFailLock.java b/policy-core/src/main/java/org/onap/policy/drools/core/lock/AlwaysFailLock.java
index dbb20883..df0ac151 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/lock/AlwaysFailLock.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/lock/AlwaysFailLock.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 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,6 +21,7 @@
package org.onap.policy.drools.core.lock;
+import java.io.Serial;
import lombok.NoArgsConstructor;
/**
@@ -27,6 +29,7 @@ import lombok.NoArgsConstructor;
*/
@NoArgsConstructor
public class AlwaysFailLock extends LockImpl {
+ @Serial
private static final long serialVersionUID = 1L;
/**
diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/lock/AlwaysSuccessLock.java b/policy-core/src/main/java/org/onap/policy/drools/core/lock/AlwaysSuccessLock.java
index 6b1e1494..ced6c4c9 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/core/lock/AlwaysSuccessLock.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/core/lock/AlwaysSuccessLock.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 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,12 +21,14 @@
package org.onap.policy.drools.core.lock;
+import java.io.Serial;
import lombok.NonNull;
/**
* Lock implementation whose operations always succeed.
*/
public class AlwaysSuccessLock extends LockImpl {
+ @Serial
private static final long serialVersionUID = 1L;
/**
diff --git a/policy-core/src/main/java/org/onap/policy/drools/util/FeatureEnabledChecker.java b/policy-core/src/main/java/org/onap/policy/drools/util/FeatureEnabledChecker.java
index 755e7a18..285a9a0a 100644
--- a/policy-core/src/main/java/org/onap/policy/drools/util/FeatureEnabledChecker.java
+++ b/policy-core/src/main/java/org/onap/policy/drools/util/FeatureEnabledChecker.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2018, 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +26,7 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
/**
- * Checks whether or not a feature is enabled.
+ * Checks whether a feature is enabled.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class FeatureEnabledChecker {
@@ -40,6 +41,6 @@ public class FeatureEnabledChecker {
*/
public static boolean isFeatureEnabled(Properties props, String propName) {
String val = props.getProperty(propName);
- return (val != null && Boolean.valueOf(val));
+ return (Boolean.parseBoolean(val));
}
}
diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/DroolsContainerTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/DroolsContainerTest.java
index 81ca3407..abed9727 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/core/DroolsContainerTest.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/core/DroolsContainerTest.java
@@ -3,6 +3,7 @@
* policy-core
* ================================================================================
* Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 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,11 +21,11 @@
package org.onap.policy.drools.core;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertFalse;
+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.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -32,11 +33,13 @@ import static org.mockito.Mockito.when;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection;
+import java.util.List;
+import java.util.Objects;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.drools.core.WorkingMemory;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.onap.policy.drools.util.KieUtils;
/**
@@ -54,7 +57,7 @@ public class DroolsContainerTest {
* and 'PolicySession', and the updating of that container to a new
* version.
*/
- @BeforeClass
+ @BeforeAll
public static void setUp() throws Exception {
KieUtils.installArtifact(
Paths.get("src/test/resources/drools-artifact-1.1/src/main/resources/META-INF/kmodule.xml").toFile(),
@@ -75,13 +78,13 @@ public class DroolsContainerTest {
* version.
*/
@Test
- public void createAndUpdate() throws Exception {
+ void createAndUpdate() throws Exception {
// make sure feature log starts out clean
PolicySessionFeatureApiMock.getLog();
// run 'globalInit', and verify expected feature hook fired
PolicyContainer.globalInit(new String[0]);
- assertEquals(Arrays.asList("globalInit"),
+ assertEquals(List.of("globalInit"),
PolicySessionFeatureApiMock.getLog());
// initial conditions -- there should be no containers
@@ -139,15 +142,15 @@ public class DroolsContainerTest {
session.getKieSession().insert(result);
// the Drools rules should add 3 + 8 + 2, and store 13 in a[0]
- assertEquals(13, result.poll(TIMEOUT_SEC, TimeUnit.SECONDS).intValue());
+ assertEquals(13, Objects.requireNonNull(result.poll(TIMEOUT_SEC, TimeUnit.SECONDS)).intValue());
// update the container to a new version --
// the rules will then multiply values rather than add them
assertEquals("[]",
- container.updateToVersion("17.2.0-SNAPSHOT").toString());
+ container.updateToVersion("17.2.0-SNAPSHOT"));
// verify expected feature hooks fired
- assertEquals(Arrays.asList("selectThreadModel"),
+ assertEquals(List.of("selectThreadModel"),
PolicySessionFeatureApiMock.getLog());
// verify new container attributes
@@ -169,7 +172,7 @@ public class DroolsContainerTest {
container.insert("session1", Arrays.asList(3, 8, 2));
container.insert("session1", result);
- assertEquals(48, result.poll(TIMEOUT_SEC, TimeUnit.SECONDS).intValue());
+ assertEquals(48, Objects.requireNonNull(result.poll(TIMEOUT_SEC, TimeUnit.SECONDS)).intValue());
/*
* verify that default KiePackages have been added by testing that
@@ -198,7 +201,7 @@ public class DroolsContainerTest {
assertFalse(container.isAlive());
// verify expected feature hooks fired
- assertEquals(Arrays.asList("disposeKieSession"),
+ assertEquals(List.of("disposeKieSession"),
PolicySessionFeatureApiMock.getLog());
}
@@ -213,7 +216,7 @@ public class DroolsContainerTest {
* test, also to increase code coverage.
*/
@Test
- public void versionList() throws Exception {
+ void versionList() throws Exception {
// make sure feature log starts out clean
PolicySessionFeatureApiMock.getLog();
@@ -222,7 +225,7 @@ public class DroolsContainerTest {
// run 'globalInit', and verify expected feature hook fired
PolicyContainer.globalInit(new String[0]);
- assertEquals(Arrays.asList("globalInit-exception"),
+ assertEquals(List.of("globalInit-exception"),
PolicySessionFeatureApiMock.getLog());
// initial conditions -- there should be no containers
@@ -317,7 +320,7 @@ public class DroolsContainerTest {
container.insertAll(result);
// the Drools rules should add 7 + 3 + 4, and store 14 in a[0]
- assertEquals(14, result.poll(TIMEOUT_SEC, TimeUnit.SECONDS).intValue());
+ assertEquals(14, Objects.requireNonNull(result.poll(TIMEOUT_SEC, TimeUnit.SECONDS)).intValue());
// exercise some more API methods
assertEquals(container.getClassLoader(),
@@ -328,7 +331,7 @@ public class DroolsContainerTest {
assertFalse(container.isAlive());
// verify expected feature hooks fired
- assertEquals(Arrays.asList("destroyKieSession-exception"),
+ assertEquals(List.of("destroyKieSession-exception"),
PolicySessionFeatureApiMock.getLog());
// clear exception trigger
diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionFeatureApiMock.java b/policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionFeatureApiMock.java
index fbd81391..d8257067 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionFeatureApiMock.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionFeatureApiMock.java
@@ -3,6 +3,7 @@
* policy-core
* ================================================================================
* Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 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,6 +22,7 @@
package org.onap.policy.drools.core;
import java.util.ArrayList;
+import lombok.Setter;
import org.kie.api.runtime.KieSession;
/**
@@ -30,10 +32,11 @@ import org.kie.api.runtime.KieSession;
*/
public class PolicySessionFeatureApiMock implements PolicySessionFeatureApi {
// contains the log entries since the most recent 'getLog()' call
- private static ArrayList<String> log = new ArrayList<>();
+ private static final ArrayList<String> log = new ArrayList<>();
// if 'true', trigger an exception right after doing the log,
// to verify that exceptions are handled
+ @Setter
private static boolean exceptionTrigger = false;
/**
@@ -50,17 +53,6 @@ public class PolicySessionFeatureApiMock implements PolicySessionFeatureApi {
}
/**
- * This method controls whether these hooks trigger an exception after
- * being invoked.
- *
- * @param indicator if 'true', subsequent hook method calls will trigger
- * an exception; if 'false', no exception is triggered
- */
- public static void setExceptionTrigger(boolean indicator) {
- exceptionTrigger = indicator;
- }
-
- /**
* This method adds an entry to the log, and possibly triggers an exception.
*
* @param arg value to add to the log
diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionFeatureApiTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionFeatureApiTest.java
index 1d1ca0ff..9e5643f1 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionFeatureApiTest.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionFeatureApiTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 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,20 +21,15 @@
package org.onap.policy.drools.core;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class PolicySessionFeatureApiTest {
+class PolicySessionFeatureApiTest {
@Test
- public void test() {
- PolicySessionFeatureApi api = new PolicySessionFeatureApi() {
- @Override
- public int getSequenceNumber() {
- return 0;
- }
- };
+ void test() {
+ PolicySessionFeatureApi api = () -> 0;
// test default methods
api.globalInit(null, null);
diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionTest.java
index e937bb30..6f07a34f 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionTest.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/core/PolicySessionTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2018, 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 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,22 +22,22 @@
package org.onap.policy.drools.core;
import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.concurrent.Semaphore;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.kie.api.event.rule.AgendaEventListener;
import org.kie.api.event.rule.RuleRuntimeEventListener;
import org.kie.api.runtime.KieSession;
import org.onap.policy.drools.core.PolicySession.ThreadModel;
-public class PolicySessionTest {
+class PolicySessionTest {
private static final String MY_NAME = "my-name";
private static final String CONTAINER = "my-container";
@@ -49,7 +50,7 @@ public class PolicySessionTest {
/**
* Initialize test objects.
*/
- @Before
+ @BeforeEach
public void setUp() {
container = mock(PolicyContainer.class);
kie = mock(KieSession.class);
@@ -60,7 +61,7 @@ public class PolicySessionTest {
}
@Test
- public void test_Simple() {
+ void test_Simple() {
// verify constructor operations
AgendaEventListener agenda = session;
verify(kie).addEventListener(agenda);
@@ -92,7 +93,7 @@ public class PolicySessionTest {
}
@Test
- public void testStartThread() {
+ void testStartThread() {
session.startThread();
// re-start
@@ -102,7 +103,7 @@ public class PolicySessionTest {
}
@Test
- public void testSetPolicySession_testGetCurrentSession_testRemovePolicySession() {
+ void testSetPolicySession_testGetCurrentSession_testRemovePolicySession() {
PolicySession sess2 = new PolicySession(MY_NAME + "-b", container, kie);
session.setPolicySession();
@@ -121,7 +122,7 @@ public class PolicySessionTest {
}
@Test
- public void testGetAdjunct_testSetAdjunct() {
+ void testGetAdjunct_testSetAdjunct() {
Object adjnm1 = "adjunct-a";
Object adjval1 = "value-a";
session.setAdjunct(adjnm1, adjval1);
@@ -136,7 +137,7 @@ public class PolicySessionTest {
}
@Test
- public void testThreadModel() {
+ void testThreadModel() {
ThreadModel model = new PolicySession.ThreadModel() {
@Override
public void stop() {
@@ -149,11 +150,11 @@ public class PolicySessionTest {
}
};
- assertThatCode(() -> model.updated()).doesNotThrowAnyException();
+ assertThatCode(model::updated).doesNotThrowAnyException();
}
@Test
- public void testDefaultThreadModelRun() throws Exception {
+ void testDefaultThreadModelRun() throws Exception {
testDefaultThreadModelRun_Ex(() -> {
throw new RuntimeException(EXPECTED);
});
diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/jmx/PdpJmxTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/jmx/PdpJmxTest.java
index e585a4b6..6bd994be 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/core/jmx/PdpJmxTest.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/core/jmx/PdpJmxTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2018, 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 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,45 +21,45 @@
package org.onap.policy.drools.core.jmx;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
+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 org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class PdpJmxTest {
+class PdpJmxTest {
private PdpJmx jmx;
- @Before
+ @BeforeEach
public void setUp() {
jmx = new PdpJmx();
}
@Test
- public void testGetInstance() {
+ void testGetInstance() {
jmx = PdpJmx.getInstance();
assertNotNull(jmx);
assertSame(jmx, PdpJmx.getInstance());
}
@Test
- public void testGetUpdates_testUpdateOccured() {
+ void testGetUpdates_testUpdateOccurred() {
assertEquals(0, jmx.getUpdates());
assertEquals(0, jmx.getRulesFired());
- jmx.updateOccured();
+ jmx.updateOccurred();
assertEquals(1, jmx.getUpdates());
assertEquals(0, jmx.getRulesFired());
- jmx.updateOccured();
+ jmx.updateOccurred();
assertEquals(2, jmx.getUpdates());
assertEquals(0, jmx.getRulesFired());
}
@Test
- public void testGetRulesFired_testRuleFired() {
+ void testGetRulesFired_testRuleFired() {
assertEquals(0, jmx.getUpdates());
assertEquals(0, jmx.getRulesFired());
diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysFailLockTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysFailLockTest.java
index 178ef0af..51273d7d 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysFailLockTest.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysFailLockTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 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,33 +22,33 @@
package org.onap.policy.drools.core.lock;
import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class AlwaysFailLockTest extends AlwaysLockBaseTest<AlwaysFailLock> {
+class AlwaysFailLockTest extends AlwaysLockBaseTest<AlwaysFailLock> {
- @Before
+ @BeforeEach
public void setUp() {
callback = mock(LockCallback.class);
lock = new AlwaysFailLock(RESOURCE, OWNER_KEY, HOLD_SEC, callback);
}
@Test
- public void testAlwaysFailLockNoArgs() {
+ void testAlwaysFailLockNoArgs() {
assertThatCode(AlwaysFailLock::new).doesNotThrowAnyException();
}
@Test
- public void testUnavailableLock() {
+ void testUnavailableLock() {
assertTrue(lock.isUnavailable());
}
@Test
- public void testFree() {
+ void testFree() {
assertFalse(lock.free());
assertTrue(lock.isUnavailable());
}
diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysLockBaseTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysLockBaseTest.java
index b5f7a64c..347ff874 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysLockBaseTest.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysLockBaseTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 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.drools.core.lock;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public abstract class AlwaysLockBaseTest<T extends LockImpl> {
protected static final String RESOURCE = "hello";
diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysSuccessLockTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysSuccessLockTest.java
index 32889484..80f81f92 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysSuccessLockTest.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/core/lock/AlwaysSuccessLockTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 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,24 +23,24 @@ package org.onap.policy.drools.core.lock;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
-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.Mockito.mock;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class AlwaysSuccessLockTest extends AlwaysLockBaseTest<AlwaysSuccessLock> {
+class AlwaysSuccessLockTest extends AlwaysLockBaseTest<AlwaysSuccessLock> {
- @Before
+ @BeforeEach
public void setUp() {
callback = mock(LockCallback.class);
lock = new AlwaysSuccessLock(RESOURCE, OWNER_KEY, HOLD_SEC, callback);
}
@Test
- public void testAlwaysSuccessLockConstructors() {
+ void testAlwaysSuccessLockConstructors() {
assertThatCode(AlwaysSuccessLock::new).doesNotThrowAnyException();
assertThatCode(() -> new AlwaysSuccessLock(LockState.ACTIVE, RESOURCE, OWNER_KEY, HOLD_SEC, callback))
.doesNotThrowAnyException();
@@ -48,18 +49,18 @@ public class AlwaysSuccessLockTest extends AlwaysLockBaseTest<AlwaysSuccessLock>
}
@Test
- public void testActiveLock() {
+ void testActiveLock() {
assertTrue(lock.isActive());
}
@Test
- public void testFree() {
+ void testFree() {
assertTrue(lock.free());
assertTrue(lock.isActive());
}
@Test
- public void testExtend() {
+ void testExtend() {
LockCallback callback2 = mock(LockCallback.class);
lock.extend(HOLD_SEC2, callback2);
diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/lock/LockImplTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/lock/LockImplTest.java
index 56cd5090..f16d9c4e 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/core/lock/LockImplTest.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/core/lock/LockImplTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,12 +25,12 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
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.assertNull;
-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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+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.Mockito.doThrow;
import static org.mockito.Mockito.mock;
@@ -40,10 +41,10 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class LockImplTest {
+class LockImplTest {
private static final LockState STATE = LockState.WAITING;
private static final String RESOURCE = "hello";
private static final String OWNER_KEY = "world";
@@ -57,7 +58,7 @@ public class LockImplTest {
/**
* Populates {@link #lock}.
*/
- @Before
+ @BeforeEach
public void setUp() {
callback = mock(LockCallback.class);
@@ -65,7 +66,7 @@ public class LockImplTest {
}
@Test
- public void testSerializable() throws Exception {
+ void testSerializable() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(lock);
@@ -86,7 +87,7 @@ public class LockImplTest {
}
@Test
- public void testLockImplNoArgs() {
+ void testLockImplNoArgs() {
// use no-arg constructor
lock = new LockImpl();
assertEquals(LockState.UNAVAILABLE, lock.getState());
@@ -97,7 +98,7 @@ public class LockImplTest {
}
@Test
- public void testLockImpl_testGetters() {
+ void testLockImpl_testGetters() {
assertEquals(STATE, lock.getState());
assertEquals(RESOURCE, lock.getResourceId());
assertEquals(OWNER_KEY, lock.getOwnerKey());
@@ -118,7 +119,7 @@ public class LockImplTest {
}
@Test
- public void testFree() {
+ void testFree() {
assertTrue(lock.free());
assertTrue(lock.isUnavailable());
@@ -132,7 +133,7 @@ public class LockImplTest {
}
@Test
- public void testExtend() {
+ void testExtend() {
lock.setState(LockState.WAITING);
LockCallback callback2 = mock(LockCallback.class);
@@ -181,7 +182,7 @@ public class LockImplTest {
}
@Test
- public void testNotifyAvailable() {
+ void testNotifyAvailable() {
lock.notifyAvailable();
verify(callback).lockAvailable(any());
@@ -189,7 +190,7 @@ public class LockImplTest {
}
@Test
- public void testNotifyAvailable_Ex() {
+ void testNotifyAvailable_Ex() {
doThrow(new IllegalArgumentException(EXPECTED_EXCEPTION)).when(callback).lockAvailable(any());
doThrow(new IllegalArgumentException(EXPECTED_EXCEPTION)).when(callback).lockUnavailable(any());
@@ -198,7 +199,7 @@ public class LockImplTest {
}
@Test
- public void testNotifyUnavailable() {
+ void testNotifyUnavailable() {
lock.notifyUnavailable();
verify(callback, never()).lockAvailable(any());
@@ -206,7 +207,7 @@ public class LockImplTest {
}
@Test
- public void testNotifyUnavailable_Ex() {
+ void testNotifyUnavailable_Ex() {
doThrow(new IllegalArgumentException(EXPECTED_EXCEPTION)).when(callback).lockAvailable(any());
doThrow(new IllegalArgumentException(EXPECTED_EXCEPTION)).when(callback).lockUnavailable(any());
@@ -215,7 +216,7 @@ public class LockImplTest {
}
@Test
- public void testSetState_testIsActive_testIsWaiting_testIsUnavailable() {
+ void testSetState_testIsActive_testIsWaiting_testIsUnavailable() {
lock.setState(LockState.WAITING);
assertEquals(LockState.WAITING, lock.getState());
assertFalse(lock.isActive());
@@ -236,7 +237,7 @@ public class LockImplTest {
}
@Test
- public void testSetHoldSec() {
+ void testSetHoldSec() {
assertEquals(HOLD_SEC, lock.getHoldSec());
lock.setHoldSec(HOLD_SEC2);
@@ -244,7 +245,7 @@ public class LockImplTest {
}
@Test
- public void testSetCallback() {
+ void testSetCallback() {
assertSame(callback, lock.getCallback());
LockCallback callback2 = mock(LockCallback.class);
@@ -253,7 +254,7 @@ public class LockImplTest {
}
@Test
- public void testToString() {
+ void testToString() {
String text = lock.toString();
assertNotNull(text);
diff --git a/policy-core/src/test/java/org/onap/policy/drools/util/FeatureEnabledCheckerTest.java b/policy-core/src/test/java/org/onap/policy/drools/util/FeatureEnabledCheckerTest.java
index c118b897..454544a6 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/util/FeatureEnabledCheckerTest.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/util/FeatureEnabledCheckerTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 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,18 +21,18 @@
package org.onap.policy.drools.util;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Properties;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class FeatureEnabledCheckerTest {
+class FeatureEnabledCheckerTest {
private static final String PROP_NAME = "enable.it";
@Test
- public void test() {
+ void test() {
assertFalse(check(null));
assertTrue(check(true));
assertFalse(check(false));
diff --git a/policy-core/src/test/java/org/onap/policy/drools/util/KieUtilsTest.java b/policy-core/src/test/java/org/onap/policy/drools/util/KieUtilsTest.java
index 1622a2b9..7089fdad 100644
--- a/policy-core/src/test/java/org/onap/policy/drools/util/KieUtilsTest.java
+++ b/policy-core/src/test/java/org/onap/policy/drools/util/KieUtilsTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 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,9 +21,9 @@
package org.onap.policy.drools.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.io.IOException;
import java.net.URL;
@@ -32,8 +33,8 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.stream.Collectors;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.kie.api.builder.ReleaseId;
import org.kie.api.definition.KiePackage;
import org.kie.api.definition.rule.Rule;
@@ -51,7 +52,7 @@ public class KieUtilsTest {
/**
* Test class initialization.
*/
- @BeforeClass
+ @BeforeAll
public static void createArtifact() throws Exception {
ReleaseId releaseId =
KieUtils.installArtifact(
@@ -65,7 +66,7 @@ public class KieUtilsTest {
}
@Test
- public void testInstallArtifact() throws IOException {
+ void testInstallArtifact() throws IOException {
ReleaseId releaseId =
KieUtils.installArtifact(
Paths.get("src/test/resources/drools-artifact-1.1/src/main/resources/META-INF/kmodule.xml").toFile(),
@@ -77,7 +78,7 @@ public class KieUtilsTest {
}
@Test
- public void testInstallArtifactList() throws IOException {
+ void testInstallArtifactList() throws IOException {
ReleaseId releaseId =
KieUtils.installArtifact(
Paths.get("src/test/resources/drools-artifact-1.1/src/main/resources/META-INF/kmodule.xml").toFile(),
@@ -90,41 +91,41 @@ public class KieUtilsTest {
}
@Test
- public void getBases() {
+ void getBases() {
assertEquals(Collections.singletonList("rules"), KieUtils.getBases(container));
}
@Test
- public void getPackages() {
+ void getPackages() {
assertEquals(Arrays.asList("java.util", "java.util.concurrent", "org.onap.policy.drools.core.test"),
KieUtils.getPackages(container).stream().map(KiePackage::getName).collect(Collectors.toList()));
}
@Test
- public void getPackageNames() {
+ void getPackageNames() {
assertEquals(Arrays.asList("java.util", "java.util.concurrent", "org.onap.policy.drools.core.test"),
new ArrayList<>(KieUtils.getPackageNames(container)));
}
@Test
- public void getRules() {
+ void getRules() {
assertEquals(Arrays.asList("Initialization", "Add elements of an int list"),
KieUtils.getRules(container).stream().map(Rule::getName).collect(Collectors.toList()));
}
@Test
- public void getRuleNames() {
+ void getRuleNames() {
assertEquals(Arrays.asList("Initialization", "Add elements of an int list"),
- KieUtils.getRuleNames(container).stream().collect(Collectors.toList()));
+ new ArrayList<>(KieUtils.getRuleNames(container)));
}
@Test
- public void getFacts() {
+ void getFacts() {
assertEquals(0, KieUtils.getFacts(session).size());
}
@Test
- public void testResourceToPackages() {
+ void testResourceToPackages() {
// Some minimal logging -- it would be nice to verify the 'KieUtils' logger messages
StringBuffer log;
@@ -156,7 +157,7 @@ public class KieUtilsTest {
@Override
public Enumeration<URL> getResources(String name) throws IOException {
if ("BogusUrl".equals(name)) {
- return new Enumeration<URL>() {
+ return new Enumeration<>() {
@Override
public boolean hasMoreElements() {
return true;
diff --git a/policy-core/src/test/resources/drools-artifact-1.1/src/main/resources/META-INF/kmodule.xml b/policy-core/src/test/resources/drools-artifact-1.1/src/main/resources/META-INF/kmodule.xml
index 22319689..2ab03fcf 100644
--- a/policy-core/src/test/resources/drools-artifact-1.1/src/main/resources/META-INF/kmodule.xml
+++ b/policy-core/src/test/resources/drools-artifact-1.1/src/main/resources/META-INF/kmodule.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
+<kmodule xmlns="http://www.drools.org/xsd/kmodule">
<kbase name="rules">
<ksession name="session1"/>
</kbase>
diff --git a/policy-core/src/test/resources/drools-artifact-1.2/src/main/resources/META-INF/kmodule.xml b/policy-core/src/test/resources/drools-artifact-1.2/src/main/resources/META-INF/kmodule.xml
index 22319689..2ab03fcf 100644
--- a/policy-core/src/test/resources/drools-artifact-1.2/src/main/resources/META-INF/kmodule.xml
+++ b/policy-core/src/test/resources/drools-artifact-1.2/src/main/resources/META-INF/kmodule.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
+<kmodule xmlns="http://www.drools.org/xsd/kmodule">
<kbase name="rules">
<ksession name="session1"/>
</kbase>