Upgrade and clean up dependencies 86/133086/1
authorliamfallon <liam.fallon@est.tech>
Tue, 31 Jan 2023 10:44:23 +0000 (10:44 +0000)
committerliamfallon <liam.fallon@est.tech>
Tue, 31 Jan 2023 12:51:53 +0000 (12:51 +0000)
- Upgrade Hibernate
- Upgrade Mockito
- Upgrade Mockserver
- Remove Powermock (no longer supported) and replace with spring-test ReflectionTestUtils
- Upgrade Spring Framework
- Add spring-security to allow authentication on unit tests using MockMVC

Minor clean-up
- Replace deprecated authorization configuraiton on spring boot applications with SecurityFilterChain bean
- Change @LocalPort include on tests to use test include rather than runtime include
- Remove unused imports
- Remove unused constants and variables
- Add deprecation annotations where required

Issue-ID: POLICY-4482
Change-Id: Ibc2097f6d832a893c9e99a01b79121c28ba878ad
Signed-off-by: liamfallon <liam.fallon@est.tech>
16 files changed:
feature-distributed-locking/pom.xml
feature-distributed-locking/src/test/java/org/onap/policy/distributed/locking/DistributedLockManagerTest.java
feature-healthcheck/pom.xml
feature-legacy-config/pom.xml
feature-lifecycle/pom.xml
feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java
feature-no-locking/pom.xml
feature-test-transaction/pom.xml
policy-core/pom.xml
policy-domains/pom.xml
policy-management/pom.xml
policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineConstants.java
policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
policy-management/src/test/java/org/onap/policy/drools/system/internal/FeatureLockImplTest.java
policy-management/src/test/java/org/onap/policy/drools/system/internal/SimpleLockManagerTest.java
policy-utils/pom.xml

index 350f341..62d5b04 100644 (file)
@@ -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>
             <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>
index 082a619..9646a88 100644 (file)
@@ -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;
index fb497ee..7c9efa1 100644 (file)
@@ -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.
             <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>
index 9fb83a7..1bb5e3d 100644 (file)
@@ -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.
         </dependency>
 
         <dependency>
-            <groupId>org.powermock</groupId>
-            <artifactId>powermock-api-mockito2</artifactId>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
             <scope>test</scope>
         </dependency>
 
index bf69b86..816e2f9 100644 (file)
@@ -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.
         </dependency>
 
         <dependency>
-            <groupId>org.powermock</groupId>
-            <artifactId>powermock-api-mockito2</artifactId>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
             <scope>test</scope>
         </dependency>
 
index 09dcab0..b09d256 100644 (file)
@@ -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;
index 352915a..5584e13 100644 (file)
@@ -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.
             <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>
index 21d2a4e..2fdf918 100644 (file)
@@ -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>
index 3e76199..0f41294 100644 (file)
@@ -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.
         </dependency>
 
         <dependency>
-            <groupId>org.powermock</groupId>
-            <artifactId>powermock-api-mockito2</artifactId>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
             <scope>test</scope>
         </dependency>
 
index ec064a2..918e03c 100644 (file)
@@ -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>
 
index da0a5a1..19fee3e 100644 (file)
@@ -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.
         </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>
 
index ffd0c85..9a762c0 100644 (file)
@@ -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 {
index fe307f2..93c0f34 100644 (file)
@@ -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;
index 075f144..2ba7cde 100644 (file)
@@ -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);
         }
 
index de78849..4491a73 100644 (file)
@@ -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;
index 1e796bc..3c102df 100644 (file)
@@ -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.
             <artifactId>gson</artifactId>
             <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>