From 2808374bda04dbe709253ca079dfb89d5dbea7dd Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Thu, 29 Nov 2018 09:33:02 -0500 Subject: Remove Factory from various drools-pdp classes Also merged changes from 'Rename test classes in drools-pdp'. Change-Id: I4d0a3a1b0b5523eadf38d1edb5aa86c404b69d19 Issue-ID: POLICY-1288 Signed-off-by: Jim Hahn --- .../core/lock/PolicyResourceLockManager.java | 49 ++++++---------------- .../core/lock/PolicyResourceLockManagerTest.java | 27 ++---------- 2 files changed, 16 insertions(+), 60 deletions(-) (limited to 'policy-core') diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java b/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java index 33f4668c..487814cb 100644 --- a/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java +++ b/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockManager.java @@ -34,11 +34,6 @@ public class PolicyResourceLockManager extends SimpleLockManager { private static Logger logger = LoggerFactory.getLogger(PolicyResourceLockManager.class); - /** - * Used to access various objects. - */ - private static Factory factory = new Factory(); - /** * Used by junit tests. */ @@ -55,19 +50,6 @@ public class PolicyResourceLockManager extends SimpleLockManager { return Singleton.instance; } - protected static Factory getFactory() { - return factory; - } - - /** - * Sets the factory to be used by junit tests. - * - * @param factory the factory - */ - protected static void setFactory(Factory factory) { - PolicyResourceLockManager.factory = factory; - } - @Override public boolean lock(String resourceId, String owner, int holdSec) { if (resourceId == null) { @@ -205,9 +187,9 @@ public class PolicyResourceLockManager extends SimpleLockManager { * @return first non-null value returned by an implementer, continueValue if * they all returned continueValue */ - private static T doIntercept(T continueValue, Function func) { + private T doIntercept(T continueValue, Function func) { - for (PolicyResourceLockFeatureApi impl : factory.getImplementers()) { + for (PolicyResourceLockFeatureApi impl : getImplementers()) { try { T result = func.apply(impl); if (result != continueValue) { @@ -222,6 +204,17 @@ public class PolicyResourceLockManager extends SimpleLockManager { return continueValue; } + // these may be overridden by junit tests + + /** + * Get implementers. + * + * @return the list of feature implementers + */ + protected List getImplementers() { + return PolicyResourceLockFeatureApi.impl.getList(); + } + /** * Initialization-on-demand holder idiom. */ @@ -235,21 +228,5 @@ public class PolicyResourceLockManager extends SimpleLockManager { private Singleton() { super(); } - - } - - /** - * Used to access various objects. - */ - public static class Factory { - - /** - * Get implementers. - * - * @return the list of feature implementers - */ - public List getImplementers() { - return PolicyResourceLockFeatureApi.impl.getList(); - } } } diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockManagerTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockManagerTest.java index 8acafccf..81b52d16 100644 --- a/policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockManagerTest.java +++ b/policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockManagerTest.java @@ -37,12 +37,9 @@ import static org.onap.policy.drools.core.lock.TestingUtils.expectException; import java.util.Arrays; import java.util.LinkedList; import java.util.List; -import org.junit.AfterClass; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.onap.policy.drools.core.lock.PolicyResourceLockFeatureApi.OperResult; -import org.onap.policy.drools.core.lock.PolicyResourceLockManager.Factory; public class PolicyResourceLockManagerTest { @@ -59,27 +56,12 @@ public class PolicyResourceLockManagerTest { private static final String OWNER2 = "owner.two"; private static final String OWNER3 = "owner.three"; - /** - * Saved at the start of the tests and restored once all tests complete. - */ - private static Factory saveFactory; - private PolicyResourceLockFeatureApi impl1; private PolicyResourceLockFeatureApi impl2; private List implList; private PolicyResourceLockManager mgr; - @BeforeClass - public static void setUpBeforeClass() { - saveFactory = PolicyResourceLockManager.getFactory(); - } - - @AfterClass - public static void tearDownAfterClass() { - PolicyResourceLockManager.setFactory(saveFactory); - } - /** * Set up. */ @@ -94,15 +76,12 @@ public class PolicyResourceLockManagerTest { // list of feature API implementers implList = new LinkedList<>(Arrays.asList(impl1, impl2)); - PolicyResourceLockManager.setFactory(new Factory() { - + mgr = new PolicyResourceLockManager() { @Override - public List getImplementers() { + protected List getImplementers() { return implList; } - }); - - mgr = new PolicyResourceLockManager(); + }; } /** -- cgit 1.2.3-korg