From a0e0c7840f72392152a970d88a5a66d394c4a793 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Fri, 28 Sep 2018 04:58:26 -0400 Subject: Set drools-pdp checkstyle config Fixed last remaining checkstyle issues along with setting the pom.xml to the correct path setting. Fixed forbidden summary fragments, not allowed to prepend summary with "This method returns" Issue-ID: POLICY-1153 Change-Id: I267842080494132a7b5507731e14f027a3f6fe44 Signed-off-by: Pamela Dragosh --- policy-core/checkstyle-suppressions.xml | 30 ++++ policy-core/pom.xml | 40 +++++ .../onap/policy/drools/core/PolicyContainer.java | 22 ++- .../org/onap/policy/drools/core/PolicySession.java | 52 +++--- .../core/lock/PolicyResourceLockFeatureAPI.java | 176 --------------------- .../core/lock/PolicyResourceLockFeatureApi.java | 176 +++++++++++++++++++++ .../core/lock/PolicyResourceLockManager.java | 12 +- .../lock/PolicyResourceLockFeatureAPITest.java | 92 ----------- .../lock/PolicyResourceLockFeatureApiTest.java | 92 +++++++++++ .../core/lock/PolicyResourceLockManagerTest.java | 16 +- 10 files changed, 388 insertions(+), 320 deletions(-) create mode 100644 policy-core/checkstyle-suppressions.xml delete mode 100644 policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureAPI.java create mode 100644 policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureApi.java delete mode 100644 policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureAPITest.java create mode 100644 policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureApiTest.java (limited to 'policy-core') diff --git a/policy-core/checkstyle-suppressions.xml b/policy-core/checkstyle-suppressions.xml new file mode 100644 index 00000000..d771a027 --- /dev/null +++ b/policy-core/checkstyle-suppressions.xml @@ -0,0 +1,30 @@ + + + + + + + + diff --git a/policy-core/pom.xml b/policy-core/pom.xml index 34a78a39..70df3745 100644 --- a/policy-core/pom.xml +++ b/policy-core/pom.xml @@ -124,4 +124,44 @@ test + + + + maven-checkstyle-plugin + + + onap-java-style + + check + + process-sources + + + onap-checkstyle/onap-java-style.xml + + ${project.build.sourceDirectory} + true + true + true + + + ${project.baseUri}checkstyle-suppressions.xml + true + true + warning + + + + + + org.onap.oparent + checkstyle + ${oparent.version} + compile + + + + + 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 f2a084e4..2c5d87f8 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 @@ -109,7 +109,7 @@ public class PolicyContainer implements Startable { } synchronized (containers) { if (newReleaseId != null) { - logger.info("Add a new kieContainer in containers: releaseId: {}", newReleaseId.toString()); + logger.info("Add a new kieContainer in containers: releaseId: {}", newReleaseId); } else { logger.warn("input releaseId is null"); } @@ -289,8 +289,8 @@ public class PolicyContainer implements Startable { } logger.info("activatePolicySession:new session was added in sessions with name {}", name); } - logger.info("activatePolicySession:session - " + (session == null ? "null" : session.getFullName()) - + " is returned."); + logger.info("activatePolicySession:session - {} is returned.", + session == null ? "null" : session.getFullName()); return session; } } @@ -317,7 +317,7 @@ public class PolicyContainer implements Startable { logger.warn("adoptKieSession:input kieSession is null"); throw new IllegalArgumentException("KieSession '" + name + "' is null " + getName()); } else { - logger.info("adoptKieSession:name: " + name + " kieSession: " + kieSession); + logger.info("adoptKieSession:name: {} kieSession: {}", name, kieSession); } // fetch KieBase, and verify it belongs to this KieContainer boolean match = false; @@ -507,12 +507,12 @@ public class PolicyContainer implements Startable { return rval; } - /*************************/ + /*=======================*/ /* 'Startable' interface */ - /*************************/ + /*=======================*/ /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public synchronized boolean start() { @@ -537,7 +537,7 @@ public class PolicyContainer implements Startable { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public synchronized boolean stop() { @@ -576,7 +576,7 @@ public class PolicyContainer implements Startable { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public synchronized void shutdown() { @@ -594,15 +594,13 @@ public class PolicyContainer implements Startable { } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public boolean isAlive() { return isStarted; } - /*************************/ - /** * This method is similar to 'shutdown', but it also frees any persistence resources as well. */ 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 bb2148c0..958933fb 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 @@ -232,12 +232,12 @@ public class PolicySession } } - /***********************************/ + /*=================================*/ /* 'AgendaEventListener' interface */ - /***********************************/ + /*=================================*/ /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void afterMatchFired(AfterMatchFiredEvent event) { @@ -249,7 +249,7 @@ public class PolicySession } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void afterRuleFlowGroupActivated(RuleFlowGroupActivatedEvent event) { @@ -261,7 +261,7 @@ public class PolicySession } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void afterRuleFlowGroupDeactivated(RuleFlowGroupDeactivatedEvent event) { @@ -273,7 +273,7 @@ public class PolicySession } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void agendaGroupPopped(AgendaGroupPoppedEvent event) { @@ -285,7 +285,7 @@ public class PolicySession } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void agendaGroupPushed(AgendaGroupPushedEvent event) { @@ -297,7 +297,7 @@ public class PolicySession } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void beforeMatchFired(BeforeMatchFiredEvent event) { @@ -309,7 +309,7 @@ public class PolicySession } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void beforeRuleFlowGroupActivated(RuleFlowGroupActivatedEvent event) { @@ -321,7 +321,7 @@ public class PolicySession } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void beforeRuleFlowGroupDeactivated(RuleFlowGroupDeactivatedEvent event) { @@ -333,7 +333,7 @@ public class PolicySession } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void matchCancelled(MatchCancelledEvent event) { @@ -344,7 +344,7 @@ public class PolicySession } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void matchCreated(MatchCreatedEvent event) { @@ -354,12 +354,12 @@ public class PolicySession } } - /****************************************/ + /*======================================*/ /* 'RuleRuntimeEventListener' interface */ - /****************************************/ + /*======================================*/ /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void objectDeleted(ObjectDeletedEvent event) { @@ -370,7 +370,7 @@ public class PolicySession } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void objectInserted(ObjectInsertedEvent event) { @@ -381,7 +381,7 @@ public class PolicySession } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void objectUpdated(ObjectUpdatedEvent event) { @@ -390,7 +390,7 @@ public class PolicySession + ": AgendaEventListener.objectUpdated(" + event + ")"); } } - + /* ============================================================ */ /** @@ -451,12 +451,12 @@ public class PolicySession return "Session " + session.getFullName(); } - /***************************/ + /*=========================*/ /* 'ThreadModel' interface */ - /***************************/ + /*=========================*/ /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void start() { @@ -465,7 +465,7 @@ public class PolicySession } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void stop() { @@ -486,7 +486,7 @@ public class PolicySession } /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void updated() { @@ -494,12 +494,12 @@ public class PolicySession thread.setName(getThreadName()); } - /************************/ + /*======================*/ /* 'Runnable' interface */ - /************************/ + /*======================*/ /** - * {@inheritDoc} + * {@inheritDoc}. */ @Override public void run() { diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureAPI.java b/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureAPI.java deleted file mode 100644 index 105d6ec9..00000000 --- a/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureAPI.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * api-resource-locks - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.drools.core.lock; - -import org.onap.policy.drools.utils.OrderedService; -import org.onap.policy.drools.utils.OrderedServiceImpl; - -/** - * Resource locks. Each lock has an "owner", which is intended to be unique across a - * single instance of a running PolicyEngine. - * - *

This interface provides a way to invoke optional features at various points in the - * code. At appropriate points in the application, the code iterates through this list, - * invoking these optional methods. - * - *

Implementers may choose to implement a level of locking appropriate to the application. - * For instance, they may choose to implement an engine-wide locking scheme, or they may - * choose to implement a global locking scheme (e.g., through a shared DB). - */ -public interface PolicyResourceLockFeatureAPI extends OrderedService { - - /** - * 'FeatureAPI.impl.getList()' returns an ordered list of objects implementing the - * 'FeatureAPI' interface. - */ - public static OrderedServiceImpl impl = - new OrderedServiceImpl<>(PolicyResourceLockFeatureAPI.class); - - /** - * Result of a requested operation. - */ - public enum OperResult { - - /** - * The implementer accepted the request; no additional locking logic should be - * performed. - */ - OPER_ACCEPTED, - - /** - * The implementer denied the request; no additional locking logic should be - * performed. - */ - OPER_DENIED, - - - /** - * The implementer did not handle the request; additional locking logic should - * be performed. - */ - OPER_UNHANDLED - } - - /** - * This method is called before a lock is acquired on a resource. - * - * @param resourceId resource id - * @param owner owner - * @param holdSec the amount of time, in seconds, that the lock should be held - * @return the result, where OPER_DENIED indicates that the lock is currently - * held by another owner - */ - public default OperResult beforeLock(String resourceId, String owner, int holdSec) { - return OperResult.OPER_UNHANDLED; - } - - /** - * This method is called after a lock for a resource has been acquired or denied. - * - * @param resourceId resource id - * @param owner owner - * @param locked {@code true} if the lock was acquired, {@code false} if it was denied - * @return {@code true} if the implementer handled the request, {@code false} - * otherwise - */ - public default boolean afterLock(String resourceId, String owner, boolean locked) { - return false; - } - - /** - * This method is called before a lock is refreshed on a resource. It may be invoked - * repeatedly to extend the time that a lock is held. - * - * @param resourceId resource id - * @param owner owner - * @param holdSec the amount of time, in seconds, that the lock should be held - * @return the result, where OPER_DENIED indicates that the resource is not - * currently locked by the given owner - */ - public default OperResult beforeRefresh(String resourceId, String owner, int holdSec) { - return OperResult.OPER_UNHANDLED; - } - - /** - * This method is called after a lock for a resource has been refreshed (or after the - * refresh has been denied). - * - * @param resourceId resource id - * @param owner owner - * @param locked {@code true} if the lock was acquired, {@code false} if it was denied - * @return {@code true} if the implementer handled the request, {@code false} - * otherwise - */ - public default boolean afterRefresh(String resourceId, String owner, boolean locked) { - return false; - } - - /** - * This method is called before a lock on a resource is released. - * - * @param resourceId resource id - * @param owner owner - * @return the result, where OPER_DENIED indicates that the lock is not - * currently held by the given owner - */ - public default OperResult beforeUnlock(String resourceId, String owner) { - return OperResult.OPER_UNHANDLED; - } - - /** - * This method is called after a lock on a resource is released. - * - * @param resourceId resource id - * @param owner owner - * @param unlocked {@code true} if the lock was released, {@code false} if the owner - * did not have a lock on the resource - * @return {@code true} if the implementer handled the request, {@code false} - * otherwise - */ - public default boolean afterUnlock(String resourceId, String owner, boolean unlocked) { - return false; - } - - /** - * This method is called before a check is made to determine if a resource is locked. - * - * @param resourceId resource id - * @return the result, where OPER_ACCEPTED indicates that the resource is - * locked, while OPER_DENIED indicates that it is not - */ - public default OperResult beforeIsLocked(String resourceId) { - return OperResult.OPER_UNHANDLED; - } - - /** - * This method is called before a check is made to determine if a particular owner - * holds the lock on a resource. - * - * @param resourceId resource id - * @param owner owner - * @return the result, where OPER_ACCEPTED indicates that the resource is - * locked by the given owner, while OPER_DENIED indicates that it is - * not - */ - public default OperResult beforeIsLockedBy(String resourceId, String owner) { - return OperResult.OPER_UNHANDLED; - } -} diff --git a/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureApi.java b/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureApi.java new file mode 100644 index 00000000..66766453 --- /dev/null +++ b/policy-core/src/main/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureApi.java @@ -0,0 +1,176 @@ +/* + * ============LICENSE_START======================================================= + * api-resource-locks + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.drools.core.lock; + +import org.onap.policy.drools.utils.OrderedService; +import org.onap.policy.drools.utils.OrderedServiceImpl; + +/** + * Resource locks. Each lock has an "owner", which is intended to be unique across a + * single instance of a running PolicyEngine. + * + *

This interface provides a way to invoke optional features at various points in the + * code. At appropriate points in the application, the code iterates through this list, + * invoking these optional methods. + * + *

Implementers may choose to implement a level of locking appropriate to the application. + * For instance, they may choose to implement an engine-wide locking scheme, or they may + * choose to implement a global locking scheme (e.g., through a shared DB). + */ +public interface PolicyResourceLockFeatureApi extends OrderedService { + + /** + * 'FeatureAPI.impl.getList()' returns an ordered list of objects implementing the + * 'FeatureAPI' interface. + */ + public static OrderedServiceImpl impl = + new OrderedServiceImpl<>(PolicyResourceLockFeatureApi.class); + + /** + * Result of a requested operation. + */ + public enum OperResult { + + /** + * The implementer accepted the request; no additional locking logic should be + * performed. + */ + OPER_ACCEPTED, + + /** + * The implementer denied the request; no additional locking logic should be + * performed. + */ + OPER_DENIED, + + + /** + * The implementer did not handle the request; additional locking logic should + * be performed. + */ + OPER_UNHANDLED + } + + /** + * This method is called before a lock is acquired on a resource. + * + * @param resourceId resource id + * @param owner owner + * @param holdSec the amount of time, in seconds, that the lock should be held + * @return the result, where OPER_DENIED indicates that the lock is currently + * held by another owner + */ + public default OperResult beforeLock(String resourceId, String owner, int holdSec) { + return OperResult.OPER_UNHANDLED; + } + + /** + * This method is called after a lock for a resource has been acquired or denied. + * + * @param resourceId resource id + * @param owner owner + * @param locked {@code true} if the lock was acquired, {@code false} if it was denied + * @return {@code true} if the implementer handled the request, {@code false} + * otherwise + */ + public default boolean afterLock(String resourceId, String owner, boolean locked) { + return false; + } + + /** + * This method is called before a lock is refreshed on a resource. It may be invoked + * repeatedly to extend the time that a lock is held. + * + * @param resourceId resource id + * @param owner owner + * @param holdSec the amount of time, in seconds, that the lock should be held + * @return the result, where OPER_DENIED indicates that the resource is not + * currently locked by the given owner + */ + public default OperResult beforeRefresh(String resourceId, String owner, int holdSec) { + return OperResult.OPER_UNHANDLED; + } + + /** + * This method is called after a lock for a resource has been refreshed (or after the + * refresh has been denied). + * + * @param resourceId resource id + * @param owner owner + * @param locked {@code true} if the lock was acquired, {@code false} if it was denied + * @return {@code true} if the implementer handled the request, {@code false} + * otherwise + */ + public default boolean afterRefresh(String resourceId, String owner, boolean locked) { + return false; + } + + /** + * This method is called before a lock on a resource is released. + * + * @param resourceId resource id + * @param owner owner + * @return the result, where OPER_DENIED indicates that the lock is not + * currently held by the given owner + */ + public default OperResult beforeUnlock(String resourceId, String owner) { + return OperResult.OPER_UNHANDLED; + } + + /** + * This method is called after a lock on a resource is released. + * + * @param resourceId resource id + * @param owner owner + * @param unlocked {@code true} if the lock was released, {@code false} if the owner + * did not have a lock on the resource + * @return {@code true} if the implementer handled the request, {@code false} + * otherwise + */ + public default boolean afterUnlock(String resourceId, String owner, boolean unlocked) { + return false; + } + + /** + * This method is called before a check is made to determine if a resource is locked. + * + * @param resourceId resource id + * @return the result, where OPER_ACCEPTED indicates that the resource is + * locked, while OPER_DENIED indicates that it is not + */ + public default OperResult beforeIsLocked(String resourceId) { + return OperResult.OPER_UNHANDLED; + } + + /** + * This method is called before a check is made to determine if a particular owner + * holds the lock on a resource. + * + * @param resourceId resource id + * @param owner owner + * @return the result, where OPER_ACCEPTED indicates that the resource is + * locked by the given owner, while OPER_DENIED indicates that it is + * not + */ + public default OperResult beforeIsLockedBy(String resourceId, String owner) { + return OperResult.OPER_UNHANDLED; + } +} 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 3612b29d..33f4668c 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 @@ -23,7 +23,7 @@ package org.onap.policy.drools.core.lock; import java.util.List; import java.util.function.Function; import java.util.function.Supplier; -import org.onap.policy.drools.core.lock.PolicyResourceLockFeatureAPI.OperResult; +import org.onap.policy.drools.core.lock.PolicyResourceLockFeatureApi.OperResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -184,7 +184,7 @@ public class PolicyResourceLockManager extends SimpleLockManager { * @param defaultFunc default function * @return {@code true} if success, {@code false} otherwise */ - private boolean doBoolIntercept(Function interceptFunc, + private boolean doBoolIntercept(Function interceptFunc, Supplier defaultFunc) { OperResult result = doIntercept(OperResult.OPER_UNHANDLED, interceptFunc); @@ -205,9 +205,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 static T doIntercept(T continueValue, Function func) { - for (PolicyResourceLockFeatureAPI impl : factory.getImplementers()) { + for (PolicyResourceLockFeatureApi impl : factory.getImplementers()) { try { T result = func.apply(impl); if (result != continueValue) { @@ -248,8 +248,8 @@ public class PolicyResourceLockManager extends SimpleLockManager { * * @return the list of feature implementers */ - public List getImplementers() { - return PolicyResourceLockFeatureAPI.impl.getList(); + public List getImplementers() { + return PolicyResourceLockFeatureApi.impl.getList(); } } } diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureAPITest.java b/policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureAPITest.java deleted file mode 100644 index 522a3f51..00000000 --- a/policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureAPITest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * api-resource-locks - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.drools.core.lock; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.drools.core.lock.PolicyResourceLockFeatureAPI.OperResult; - -public class PolicyResourceLockFeatureAPITest { - - private static final String RESOURCE_ID = "the resource"; - private static final String OWNER = "the owner"; - - private PolicyResourceLockFeatureAPI api; - - /** - * set up. - */ - @Before - public void setUp() { - api = new PolicyResourceLockFeatureAPI() { - @Override - public int getSequenceNumber() { - return 0; - } - }; - } - - @Test - public void testBeforeLock() { - assertEquals(OperResult.OPER_UNHANDLED, api.beforeLock(RESOURCE_ID, OWNER, 0)); - } - - @Test - public void testAfterLock() { - assertFalse(api.afterLock(RESOURCE_ID, OWNER, true)); - assertFalse(api.afterLock(RESOURCE_ID, OWNER, false)); - } - - @Test - public void testBeforeRefresh() { - assertEquals(OperResult.OPER_UNHANDLED, api.beforeRefresh(RESOURCE_ID, OWNER, 0)); - } - - @Test - public void testAfterRefresh() { - assertFalse(api.afterRefresh(RESOURCE_ID, OWNER, true)); - assertFalse(api.afterRefresh(RESOURCE_ID, OWNER, false)); - } - - @Test - public void testBeforeUnlock() { - assertEquals(OperResult.OPER_UNHANDLED, api.beforeUnlock(RESOURCE_ID, OWNER)); - } - - @Test - public void testAfterUnlock() { - assertFalse(api.afterUnlock(RESOURCE_ID, OWNER, true)); - assertFalse(api.afterUnlock(RESOURCE_ID, OWNER, false)); - } - - @Test - public void testBeforeIsLocked() { - assertEquals(OperResult.OPER_UNHANDLED, api.beforeIsLocked(RESOURCE_ID)); - } - - @Test - public void testBeforeIsLockedBy() { - assertEquals(OperResult.OPER_UNHANDLED, api.beforeIsLockedBy(RESOURCE_ID, OWNER)); - } -} diff --git a/policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureApiTest.java b/policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureApiTest.java new file mode 100644 index 00000000..999ae50f --- /dev/null +++ b/policy-core/src/test/java/org/onap/policy/drools/core/lock/PolicyResourceLockFeatureApiTest.java @@ -0,0 +1,92 @@ +/* + * ============LICENSE_START======================================================= + * api-resource-locks + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.drools.core.lock; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.drools.core.lock.PolicyResourceLockFeatureApi.OperResult; + +public class PolicyResourceLockFeatureApiTest { + + private static final String RESOURCE_ID = "the resource"; + private static final String OWNER = "the owner"; + + private PolicyResourceLockFeatureApi api; + + /** + * set up. + */ + @Before + public void setUp() { + api = new PolicyResourceLockFeatureApi() { + @Override + public int getSequenceNumber() { + return 0; + } + }; + } + + @Test + public void testBeforeLock() { + assertEquals(OperResult.OPER_UNHANDLED, api.beforeLock(RESOURCE_ID, OWNER, 0)); + } + + @Test + public void testAfterLock() { + assertFalse(api.afterLock(RESOURCE_ID, OWNER, true)); + assertFalse(api.afterLock(RESOURCE_ID, OWNER, false)); + } + + @Test + public void testBeforeRefresh() { + assertEquals(OperResult.OPER_UNHANDLED, api.beforeRefresh(RESOURCE_ID, OWNER, 0)); + } + + @Test + public void testAfterRefresh() { + assertFalse(api.afterRefresh(RESOURCE_ID, OWNER, true)); + assertFalse(api.afterRefresh(RESOURCE_ID, OWNER, false)); + } + + @Test + public void testBeforeUnlock() { + assertEquals(OperResult.OPER_UNHANDLED, api.beforeUnlock(RESOURCE_ID, OWNER)); + } + + @Test + public void testAfterUnlock() { + assertFalse(api.afterUnlock(RESOURCE_ID, OWNER, true)); + assertFalse(api.afterUnlock(RESOURCE_ID, OWNER, false)); + } + + @Test + public void testBeforeIsLocked() { + assertEquals(OperResult.OPER_UNHANDLED, api.beforeIsLocked(RESOURCE_ID)); + } + + @Test + public void testBeforeIsLockedBy() { + assertEquals(OperResult.OPER_UNHANDLED, api.beforeIsLockedBy(RESOURCE_ID, OWNER)); + } +} 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 962fb96a..8acafccf 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 @@ -41,7 +41,7 @@ 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.PolicyResourceLockFeatureApi.OperResult; import org.onap.policy.drools.core.lock.PolicyResourceLockManager.Factory; public class PolicyResourceLockManagerTest { @@ -64,9 +64,9 @@ public class PolicyResourceLockManagerTest { */ private static Factory saveFactory; - private PolicyResourceLockFeatureAPI impl1; - private PolicyResourceLockFeatureAPI impl2; - private List implList; + private PolicyResourceLockFeatureApi impl1; + private PolicyResourceLockFeatureApi impl2; + private List implList; private PolicyResourceLockManager mgr; @@ -85,8 +85,8 @@ public class PolicyResourceLockManagerTest { */ @Before public void setUp() { - impl1 = mock(PolicyResourceLockFeatureAPI.class); - impl2 = mock(PolicyResourceLockFeatureAPI.class); + impl1 = mock(PolicyResourceLockFeatureApi.class); + impl2 = mock(PolicyResourceLockFeatureApi.class); initImplementer(impl1); initImplementer(impl2); @@ -97,7 +97,7 @@ public class PolicyResourceLockManagerTest { PolicyResourceLockManager.setFactory(new Factory() { @Override - public List getImplementers() { + public List getImplementers() { return implList; } }); @@ -110,7 +110,7 @@ public class PolicyResourceLockManagerTest { * * @param impl implementer */ - private void initImplementer(PolicyResourceLockFeatureAPI impl) { + private void initImplementer(PolicyResourceLockFeatureApi impl) { when(impl.beforeLock(anyString(), anyString(), anyInt())).thenReturn(OperResult.OPER_UNHANDLED); when(impl.beforeRefresh(anyString(), anyString(), anyInt())).thenReturn(OperResult.OPER_UNHANDLED); when(impl.beforeUnlock(anyString(), anyString())).thenReturn(OperResult.OPER_UNHANDLED); -- cgit 1.2.3-korg