summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--feature-distributed-locking/pom.xml12
-rw-r--r--feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java59
-rw-r--r--feature-healthcheck/pom.xml5
-rw-r--r--feature-legacy-config/pom.xml5
-rw-r--r--feature-lifecycle/pom.xml5
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java3
-rw-r--r--feature-no-locking/pom.xml5
-rw-r--r--feature-test-transaction/pom.xml5
-rw-r--r--policy-core/pom.xml6
-rw-r--r--policy-domains/pom.xml5
-rw-r--r--policy-management/pom.xml12
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineConstants.java2
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java3
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/internal/FeatureLockImplTest.java15
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/internal/SimpleLockManagerTest.java40
-rw-r--r--policy-utils/pom.xml6
16 files changed, 98 insertions, 90 deletions
diff --git a/feature-distributed-locking/pom.xml b/feature-distributed-locking/pom.xml
index 350f341f..62d5b049 100644
--- a/feature-distributed-locking/pom.xml
+++ b/feature-distributed-locking/pom.xml
@@ -3,7 +3,7 @@
ONAP Policy Engine - Drools PDP
================================================================================
Copyright (C) 2018-2022 AT&T Intellectual Property. All rights reserved.
- Modifications Copyright (C) 2020 Nordix Foundation.
+ Modifications Copyright (C) 2020,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.
@@ -67,7 +67,6 @@
</goals>
<phase>prepare-package</phase>
<configuration>
- <transitive>false</transitive>
<outputDirectory>${project.build.directory}/assembly/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
@@ -118,8 +117,13 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java b/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java
index 082a6199..9646a88c 100644
--- a/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java
+++ b/feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2022 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.
@@ -85,7 +86,7 @@ import org.onap.policy.drools.features.PolicyEngineFeatureApi;
import org.onap.policy.drools.persistence.SystemPersistenceConstants;
import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.powermock.reflect.Whitebox;
+import org.springframework.test.util.ReflectionTestUtils;
@RunWith(MockitoJUnitRunner.class)
public class DistributedLockManagerTest {
@@ -96,7 +97,7 @@ public class DistributedLockManagerTest {
private static final String OTHER_OWNER = "other-owner";
private static final String EXPECTED_EXCEPTION = "expected exception";
private static final String DB_CONNECTION =
- "jdbc:h2:mem:pooling;INIT=CREATE SCHEMA IF NOT EXISTS pooling\\;SET SCHEMA pooling";
+ "jdbc:h2:mem:pooling;INIT=CREATE SCHEMA IF NOT EXISTS pooling\\;SET SCHEMA pooling";
private static final String DB_USER = "user";
private static final String DB_PASSWORD = "password";
private static final String OWNER_KEY = "my key";
@@ -147,7 +148,6 @@ public class DistributedLockManagerTest {
private AtomicInteger nsuccesses;
private DistributedLockManager feature;
-
/**
* Configures the location of the property files and creates the DB.
*
@@ -161,12 +161,13 @@ public class DistributedLockManagerTest {
conn = DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD);
try (PreparedStatement createStmt = conn.prepareStatement("create table pooling.locks "
- + "(resourceId VARCHAR(128), host VARCHAR(128), owner VARCHAR(128), "
- + "expirationTime TIMESTAMP DEFAULT 0, PRIMARY KEY (resourceId))")) {
+ + "(resourceId VARCHAR(128), host VARCHAR(128), owner VARCHAR(128), "
+ + "expirationTime TIMESTAMP DEFAULT 0, PRIMARY KEY (resourceId))")) {
createStmt.executeUpdate();
}
- saveExec = Whitebox.getInternalState(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD);
+ saveExec = (ScheduledExecutorService) ReflectionTestUtils.getField(PolicyEngineConstants.getManager(),
+ POLICY_ENGINE_EXECUTOR_FIELD);
realExec = Executors.newScheduledThreadPool(3);
}
@@ -176,7 +177,7 @@ public class DistributedLockManagerTest {
*/
@AfterClass
public static void tearDownAfterClass() throws SQLException {
- Whitebox.setInternalState(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD, saveExec);
+ ReflectionTestUtils.setField(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD, saveExec);
realExec.shutdown();
conn.close();
}
@@ -232,7 +233,7 @@ public class DistributedLockManagerTest {
@Test
public void testServiceApis() {
assertTrue(new OrderedServiceImpl<>(PolicyEngineFeatureApi.class).getList().stream()
- .anyMatch(obj -> obj instanceof DistributedLockManager));
+ .anyMatch(obj -> obj instanceof DistributedLockManager));
}
@Test
@@ -261,7 +262,7 @@ public class DistributedLockManagerTest {
Properties props = new Properties();
assertThatThrownBy(() -> feature.beforeCreateLockManager(engine, props))
- .isInstanceOf(DistributedLockManagerException.class);
+ .isInstanceOf(DistributedLockManagerException.class);
}
@Test
@@ -448,11 +449,9 @@ public class DistributedLockManagerTest {
// change uuid of another record
updateRecord(RESOURCE5, feature.getPdpName(), OTHER_OWNER, HOLD_SEC);
-
// run the checker
runChecker(0, 0, EXPIRE_SEC);
-
// check lock states
assertTrue(lock.isUnavailable());
assertTrue(lock2.isActive());
@@ -471,7 +470,6 @@ public class DistributedLockManagerTest {
verify(callback2, never()).lockUnavailable(lock2);
verify(callback4, never()).lockUnavailable(lock4);
-
// another check should have been scheduled, with the normal interval
runChecker(1, 0, EXPIRE_SEC);
}
@@ -483,7 +481,7 @@ public class DistributedLockManagerTest {
public void testCheckExpiredExecRejected() {
// arrange for execution to be rejected
when(exsvc.schedule(any(Runnable.class), anyLong(), any()))
- .thenThrow(new RejectedExecutionException(EXPECTED_EXCEPTION));
+ .thenThrow(new RejectedExecutionException(EXPECTED_EXCEPTION));
runChecker(0, 0, EXPIRE_SEC);
}
@@ -576,7 +574,6 @@ public class DistributedLockManagerTest {
// run the checker
runChecker(0, 0, EXPIRE_SEC);
-
// check lock states
assertTrue(lock.isUnavailable());
assertTrue(lock2.isActive());
@@ -604,8 +601,8 @@ public class DistributedLockManagerTest {
@Test
public void testDistributedLock() {
assertThatIllegalArgumentException()
- .isThrownBy(() -> feature.createLock(RESOURCE, OWNER_KEY, -1, callback, false))
- .withMessageContaining("holdSec");
+ .isThrownBy(() -> feature.createLock(RESOURCE, OWNER_KEY, -1, callback, false))
+ .withMessageContaining("holdSec");
// should generate no exception
feature.createLock(RESOURCE, OWNER_KEY, HOLD_SEC, callback, false);
@@ -755,12 +752,12 @@ public class DistributedLockManagerTest {
verify(callback, times(2)).lockUnavailable(lock2);
// force lock2 to be active - should still be denied
- Whitebox.setInternalState(lock2, "state", LockState.ACTIVE);
+ ReflectionTestUtils.setField(lock2, "state", LockState.ACTIVE);
lock2.extend(HOLD_SEC, callback);
verify(callback, times(3)).lockUnavailable(lock2);
assertThatIllegalArgumentException().isThrownBy(() -> lock.extend(-1, callback))
- .withMessageContaining("holdSec");
+ .withMessageContaining("holdSec");
// execute doLock()
runLock(0, 0);
@@ -962,7 +959,7 @@ public class DistributedLockManagerTest {
feature = new MyLockingFeature(true) {
@Override
protected DistributedLock makeLock(LockState state, String resourceId, String ownerKey, int holdSec,
- LockCallback callback) {
+ LockCallback callback) {
return new DistributedLock(state, resourceId, ownerKey, holdSec, callback, feature) {
private static final long serialVersionUID = 1L;
@@ -1346,7 +1343,7 @@ public class DistributedLockManagerTest {
feature = new MyLockingFeature(true) {
@Override
protected DistributedLock makeLock(LockState state, String resourceId, String ownerKey, int holdSec,
- LockCallback callback) {
+ LockCallback callback) {
return new DistributedLock(state, resourceId, ownerKey, holdSec, callback, feature) {
private static final long serialVersionUID = 1L;
private int ntimes = 0;
@@ -1449,7 +1446,7 @@ public class DistributedLockManagerTest {
*/
@Test
public void testMultiThreaded() throws InterruptedException {
- Whitebox.setInternalState(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD, realExec);
+ ReflectionTestUtils.setField(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD, realExec);
feature = new DistributedLockManager();
feature.beforeCreateLockManager(PolicyEngineConstants.getManager(), new Properties());
@@ -1477,7 +1474,7 @@ public class DistributedLockManagerTest {
}
private DistributedLock getLock(String resource, String ownerKey, int holdSec, LockCallback callback,
- boolean waitForLock) {
+ boolean waitForLock) {
return (DistributedLock) feature.createLock(resource, ownerKey, holdSec, callback, waitForLock);
}
@@ -1546,7 +1543,7 @@ public class DistributedLockManagerTest {
*/
private int getRecordCount() throws SQLException {
try (PreparedStatement stmt = conn.prepareStatement("SELECT count(*) FROM pooling.locks");
- ResultSet result = stmt.executeQuery()) {
+ ResultSet result = stmt.executeQuery()) {
if (result.next()) {
return result.getInt(1);
@@ -1571,8 +1568,8 @@ public class DistributedLockManagerTest {
*/
private boolean recordInRange(String resourceId, String uuidString, int holdSec, long tbegin) throws SQLException {
try (PreparedStatement stmt =
- conn.prepareStatement("SELECT timestampdiff(second, now(), expirationTime) FROM pooling.locks"
- + " WHERE resourceId=? AND host=? AND owner=?")) {
+ conn.prepareStatement("SELECT timestampdiff(second, now(), expirationTime) FROM pooling.locks"
+ + " WHERE resourceId=? AND host=? AND owner=?")) {
stmt.setString(1, resourceId);
stmt.setString(2, feature.getPdpName());
@@ -1604,10 +1601,10 @@ public class DistributedLockManagerTest {
}
private void insertRecord(String resourceId, String hostName, String uuidString, int expireOffset)
- throws SQLException {
+ throws SQLException {
try (PreparedStatement stmt =
- conn.prepareStatement("INSERT INTO pooling.locks (resourceId, host, owner, expirationTime) "
- + "values (?, ?, ?, timestampadd(second, ?, now()))")) {
+ conn.prepareStatement("INSERT INTO pooling.locks (resourceId, host, owner, expirationTime) "
+ + "values (?, ?, ?, timestampadd(second, ?, now()))")) {
stmt.setString(1, resourceId);
stmt.setString(2, hostName);
@@ -1628,7 +1625,7 @@ public class DistributedLockManagerTest {
*/
private void updateRecord(String resourceId, String newHost, String newUuid, int expireOffset) throws SQLException {
try (PreparedStatement stmt = conn.prepareStatement("UPDATE pooling.locks SET host=?, owner=?,"
- + " expirationTime=timestampadd(second, ?, now()) WHERE resourceId=?")) {
+ + " expirationTime=timestampadd(second, ?, now()) WHERE resourceId=?")) {
stmt.setString(1, newHost);
stmt.setString(2, newUuid);
@@ -1649,7 +1646,7 @@ public class DistributedLockManagerTest {
exsvc = mock(ScheduledExecutorService.class);
when(exsvc.schedule(any(Runnable.class), anyLong(), any())).thenAnswer(ans -> checker);
- Whitebox.setInternalState(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD, exsvc);
+ ReflectionTestUtils.setField(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD, exsvc);
if (init) {
beforeCreateLockManager(engine, new Properties());
@@ -1717,7 +1714,7 @@ public class DistributedLockManagerTest {
@Override
protected DistributedLock makeLock(LockState state, String resourceId, String ownerKey, int holdSec,
- LockCallback callback) {
+ LockCallback callback) {
return new DistributedLock(state, resourceId, ownerKey, holdSec, callback, feature) {
private static final long serialVersionUID = 1L;
diff --git a/feature-healthcheck/pom.xml b/feature-healthcheck/pom.xml
index fb497ee8..7c9efa1d 100644
--- a/feature-healthcheck/pom.xml
+++ b/feature-healthcheck/pom.xml
@@ -3,6 +3,7 @@
ONAP
================================================================================
Copyright (C) 2017-2022 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.
@@ -107,8 +108,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/feature-legacy-config/pom.xml b/feature-legacy-config/pom.xml
index 9fb83a77..1bb5e3da 100644
--- a/feature-legacy-config/pom.xml
+++ b/feature-legacy-config/pom.xml
@@ -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.
@@ -117,8 +118,8 @@
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
diff --git a/feature-lifecycle/pom.xml b/feature-lifecycle/pom.xml
index bf69b869..816e2f91 100644
--- a/feature-lifecycle/pom.xml
+++ b/feature-lifecycle/pom.xml
@@ -3,6 +3,7 @@
ONAP
================================================================================
Copyright (C) 2019-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.
@@ -110,8 +111,8 @@
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java
index 09dcab00..b09d2563 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021,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.
@@ -39,7 +39,6 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
-import lombok.AccessLevel;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
diff --git a/feature-no-locking/pom.xml b/feature-no-locking/pom.xml
index 352915a1..5584e13c 100644
--- a/feature-no-locking/pom.xml
+++ b/feature-no-locking/pom.xml
@@ -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.
@@ -107,8 +108,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/feature-test-transaction/pom.xml b/feature-test-transaction/pom.xml
index 21d2a4eb..2fdf918a 100644
--- a/feature-test-transaction/pom.xml
+++ b/feature-test-transaction/pom.xml
@@ -3,6 +3,7 @@
feature-test-transaction
================================================================================
Copyright (C) 2017-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.
@@ -95,8 +96,8 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
diff --git a/policy-core/pom.xml b/policy-core/pom.xml
index 3e76199a..0f41294f 100644
--- a/policy-core/pom.xml
+++ b/policy-core/pom.xml
@@ -5,7 +5,7 @@
================================================================================
Copyright (C) 2017-2021, 2023 AT&T Intellectual Property. All rights reserved.
Modifications Copyright (C) 2019 Bell Canada.
- Modifications Copyright (C) 2020,2022 Nordix Foundation.
+ Modifications Copyright (C) 2020,2022-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.
@@ -131,8 +131,8 @@
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
diff --git a/policy-domains/pom.xml b/policy-domains/pom.xml
index ec064a24..918e03ca 100644
--- a/policy-domains/pom.xml
+++ b/policy-domains/pom.xml
@@ -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.
@@ -54,8 +55,8 @@
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
diff --git a/policy-management/pom.xml b/policy-management/pom.xml
index da0a5a14..19fee3e8 100644
--- a/policy-management/pom.xml
+++ b/policy-management/pom.xml
@@ -4,7 +4,7 @@
ONAP Policy Engine - Drools PDP
================================================================================
Copyright (C) 2017-2022 AT&T Intellectual Property. All rights reserved.
- Modifications Copyright (C) 2020 Nordix Foundation.
+ Modifications Copyright (C) 2020,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.
@@ -218,8 +218,14 @@
</dependency>
<dependency>
- <groupId>org.powermock</groupId>
- <artifactId>powermock-api-mockito2</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineConstants.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineConstants.java
index ffd0c858..9a762c0b 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineConstants.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineConstants.java
@@ -3,6 +3,7 @@
* policy-management
* ================================================================================
* Copyright (C) 2019, 2021-2022 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.
@@ -23,7 +24,6 @@ package org.onap.policy.drools.system;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
-import org.onap.policy.common.utils.network.NetworkUtil;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class PolicyEngineConstants {
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
index fe307f28..93c0f348 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2018-2022 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.
@@ -23,7 +24,6 @@ package org.onap.policy.drools.system;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
-import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -47,7 +47,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
-import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/internal/FeatureLockImplTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/internal/FeatureLockImplTest.java
index 075f144b..2ba7cde9 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/internal/FeatureLockImplTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/internal/FeatureLockImplTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-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.
@@ -53,7 +54,7 @@ import org.onap.policy.drools.core.PolicySession;
import org.onap.policy.drools.core.lock.LockCallback;
import org.onap.policy.drools.core.lock.LockState;
import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.powermock.reflect.Whitebox;
+import org.springframework.test.util.ReflectionTestUtils;
@RunWith(MockitoJUnitRunner.class)
public class FeatureLockImplTest {
@@ -71,13 +72,13 @@ public class FeatureLockImplTest {
@Mock
private LockCallback callback;
-
/**
* Saves static fields and configures the location of the property files.
*/
@BeforeClass
public static void setUpBeforeClass() {
- saveExec = Whitebox.getInternalState(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD);
+ saveExec = (ScheduledExecutorService) ReflectionTestUtils.getField(PolicyEngineConstants.getManager(),
+ POLICY_ENGINE_EXECUTOR_FIELD);
}
/**
@@ -85,7 +86,7 @@ public class FeatureLockImplTest {
*/
@AfterClass
public static void tearDownAfterClass() {
- Whitebox.setInternalState(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD, saveExec);
+ ReflectionTestUtils.setField(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD, saveExec);
}
/**
@@ -94,7 +95,7 @@ public class FeatureLockImplTest {
*/
@Before
public void setUp() {
- Whitebox.setInternalState(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD, exsvc);
+ ReflectionTestUtils.setField(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD, exsvc);
}
@Test
@@ -396,7 +397,7 @@ public class FeatureLockImplTest {
}
public MyLockStdSession(LockState state, String resourceId, String ownerKey, int holdSec,
- LockCallback callback) {
+ LockCallback callback) {
super(state, resourceId, ownerKey, holdSec, callback);
}
@@ -447,7 +448,7 @@ public class FeatureLockImplTest {
}
public MyLockNoFeature(LockState state, String resourceId, String ownerKey, int holdSec,
- LockCallback callback) {
+ LockCallback callback) {
super(state, resourceId, ownerKey, holdSec, callback);
}
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/internal/SimpleLockManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/internal/SimpleLockManagerTest.java
index de78849b..4491a73b 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/internal/SimpleLockManagerTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/internal/SimpleLockManagerTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-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.
@@ -69,7 +70,7 @@ import org.onap.policy.drools.core.lock.LockCallback;
import org.onap.policy.drools.core.lock.LockState;
import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.drools.system.internal.SimpleLockManager.SimpleLock;
-import org.powermock.reflect.Whitebox;
+import org.springframework.test.util.ReflectionTestUtils;
@RunWith(MockitoJUnitRunner.class)
public class SimpleLockManagerTest {
@@ -108,14 +109,14 @@ public class SimpleLockManagerTest {
@Mock
private LockCallback callback;
-
/**
* Saves static fields and configures the location of the property files.
*/
@BeforeClass
public static void setUpBeforeClass() {
- saveTime = Whitebox.getInternalState(SimpleLockManager.class, TIME_FIELD);
- saveExec = Whitebox.getInternalState(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD);
+ saveTime = (CurrentTime) ReflectionTestUtils.getField(SimpleLockManager.class, TIME_FIELD);
+ saveExec = (ScheduledExecutorService) ReflectionTestUtils.getField(PolicyEngineConstants.getManager(),
+ POLICY_ENGINE_EXECUTOR_FIELD);
realExec = Executors.newScheduledThreadPool(3);
}
@@ -125,8 +126,8 @@ public class SimpleLockManagerTest {
*/
@AfterClass
public static void tearDownAfterClass() {
- Whitebox.setInternalState(SimpleLockManager.class, TIME_FIELD, saveTime);
- Whitebox.setInternalState(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD, saveExec);
+ ReflectionTestUtils.setField(SimpleLockManager.class, TIME_FIELD, saveTime);
+ ReflectionTestUtils.setField(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD, saveExec);
realExec.shutdown();
}
@@ -151,9 +152,9 @@ public class SimpleLockManagerTest {
nactive = new AtomicInteger(0);
nsuccesses = new AtomicInteger(0);
- Whitebox.setInternalState(SimpleLockManager.class, TIME_FIELD, testTime);
+ ReflectionTestUtils.setField(SimpleLockManager.class, TIME_FIELD, testTime);
- Whitebox.setInternalState(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD, exsvc);
+ ReflectionTestUtils.setField(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD, exsvc);
feature = new MyLockingFeature();
feature.start();
@@ -211,7 +212,6 @@ public class SimpleLockManagerTest {
verify(callback).lockAvailable(lock);
verify(callback, never()).lockUnavailable(lock);
-
// this time it should be busy
Lock lock2 = feature.createLock(RESOURCE, OWNER_KEY, HOLD_SEC, callback, false);
assertFalse(lock2.isActive());
@@ -299,7 +299,7 @@ public class SimpleLockManagerTest {
feature = new MyLockingFeature() {
@Override
protected SimpleLock makeLock(LockState waiting, String resourceId, String ownerKey, int holdSec,
- LockCallback callback) {
+ LockCallback callback) {
return new SimpleLock(waiting, resourceId, ownerKey, holdSec, callback, feature) {
private static final long serialVersionUID = 1L;
@@ -349,7 +349,7 @@ public class SimpleLockManagerTest {
@Override
protected SimpleLock makeLock(LockState waiting, String resourceId, String ownerKey, int holdSec,
- LockCallback callback) {
+ LockCallback callback) {
if (madeLock) {
return new SimpleLock(waiting, resourceId, ownerKey, holdSec, callback, feature);
}
@@ -422,8 +422,8 @@ public class SimpleLockManagerTest {
assertEquals(HOLD_SEC, lock.getHoldSec());
assertThatIllegalArgumentException()
- .isThrownBy(() -> feature.createLock(RESOURCE, OWNER_KEY, -1, callback, false))
- .withMessageContaining("holdSec");
+ .isThrownBy(() -> feature.createLock(RESOURCE, OWNER_KEY, -1, callback, false))
+ .withMessageContaining("holdSec");
}
@Test
@@ -462,7 +462,7 @@ public class SimpleLockManagerTest {
assertFalse(lock2.free());
// force lock2 to be active - still nothing should happen
- Whitebox.setInternalState(lock2, "state", LockState.ACTIVE);
+ ReflectionTestUtils.setField(lock2, "state", LockState.ACTIVE);
assertFalse(lock2.free());
// now free the first lock
@@ -508,12 +508,12 @@ public class SimpleLockManagerTest {
verify(callback, times(2)).lockUnavailable(lock2);
// force lock2 to be active - should still be denied
- Whitebox.setInternalState(lock2, "state", LockState.ACTIVE);
+ ReflectionTestUtils.setField(lock2, "state", LockState.ACTIVE);
lock2.extend(HOLD_SEC, callback);
verify(callback, times(3)).lockUnavailable(lock2);
assertThatIllegalArgumentException().isThrownBy(() -> lock.extend(-1, callback))
- .withMessageContaining("holdSec");
+ .withMessageContaining("holdSec");
// now extend the first lock
lock.extend(HOLD_SEC2, callback);
@@ -581,8 +581,8 @@ public class SimpleLockManagerTest {
*/
@Test
public void testMultiThreaded() throws InterruptedException {
- Whitebox.setInternalState(SimpleLockManager.class, TIME_FIELD, testTime);
- Whitebox.setInternalState(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD, realExec);
+ ReflectionTestUtils.setField(SimpleLockManager.class, TIME_FIELD, testTime);
+ ReflectionTestUtils.setField(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD, realExec);
feature = new SimpleLockManager(null, new Properties());
feature.start();
@@ -608,7 +608,7 @@ public class SimpleLockManagerTest {
}
private SimpleLock getLock(String resource, String ownerKey, int holdSec, LockCallback callback,
- boolean waitForLock) {
+ boolean waitForLock) {
return (SimpleLock) feature.createLock(resource, ownerKey, holdSec, callback, waitForLock);
}
@@ -637,7 +637,7 @@ public class SimpleLockManagerTest {
super(null, props);
exsvc = mock(ScheduledExecutorService.class);
- Whitebox.setInternalState(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD, exsvc);
+ ReflectionTestUtils.setField(PolicyEngineConstants.getManager(), POLICY_ENGINE_EXECUTOR_FIELD, exsvc);
when(exsvc.scheduleWithFixedDelay(any(), anyLong(), anyLong(), any())).thenAnswer(answer -> {
return future;
diff --git a/policy-utils/pom.xml b/policy-utils/pom.xml
index 1e796bcb..3c102dff 100644
--- a/policy-utils/pom.xml
+++ b/policy-utils/pom.xml
@@ -4,6 +4,7 @@
ONAP Policy Engine - Drools PDP
================================================================================
Copyright (C) 2017, 2019-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.
@@ -67,11 +68,6 @@
<version>${policy.common.version}</version>
</dependency>
<dependency>
- <groupId>org.onap.policy.common</groupId>
- <artifactId>utils</artifactId>
- <version>${policy.common.version}</version>
- </dependency>
- <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>