diff options
author | liamfallon <liam.fallon@est.tech> | 2023-01-31 10:44:23 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2023-01-31 12:51:53 +0000 |
commit | 340292f47b86b45eb9bd83df948108fc9ba34efd (patch) | |
tree | d06913aec770c2db3db235fa755f18f75a119bad /policy-management/src/test | |
parent | deaad0775a0672cbca27d6afba6a642a53dbc971 (diff) |
Upgrade and clean up dependencies
- 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>
Diffstat (limited to 'policy-management/src/test')
3 files changed, 29 insertions, 29 deletions
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; |