2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2024 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.no.locking;
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.junit.jupiter.api.Assertions.assertEquals;
26 import static org.junit.jupiter.api.Assertions.assertFalse;
27 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
28 import static org.junit.jupiter.api.Assertions.assertTrue;
29 import static org.mockito.ArgumentMatchers.any;
30 import static org.mockito.Mockito.mock;
31 import static org.mockito.Mockito.never;
32 import static org.mockito.Mockito.verify;
34 import java.util.List;
35 import org.junit.jupiter.api.BeforeAll;
36 import org.junit.jupiter.api.Test;
37 import org.onap.policy.drools.core.lock.AlwaysSuccessLock;
38 import org.onap.policy.drools.core.lock.Lock;
39 import org.onap.policy.drools.core.lock.LockCallback;
40 import org.onap.policy.drools.features.PolicyEngineFeatureApi;
41 import org.onap.policy.drools.features.PolicyEngineFeatureApiConstants;
43 public class NoLockManagerTest {
45 private static NoLockManager nlm;
46 private static LockCallback callback;
52 public static void setUp() {
53 List<PolicyEngineFeatureApi> engineServices = PolicyEngineFeatureApiConstants.getProviders().getList();
54 assertThat(engineServices).hasSize(1);
55 nlm = (NoLockManager) engineServices.get(0);
56 callback = mock(LockCallback.class);
61 assertTrue(nlm.lock());
66 assertTrue(nlm.unlock());
71 assertFalse(nlm.isLocked());
76 assertTrue(nlm.start());
81 assertTrue(nlm.stop());
86 assertTrue(nlm.isAlive());
91 assertEquals(NoLockManager.SEQNO, nlm.getSequenceNumber());
95 void testBeforeCreateLockManager() {
96 assertEquals(nlm, nlm.beforeCreateLockManager(null, null));
100 void testCreateLock() {
101 Lock lock = nlm.createLock("x", "y", 1, callback, false);
102 assertTrue(lock.isActive());
103 assertInstanceOf(AlwaysSuccessLock.class, lock);
104 verify(callback).lockAvailable(lock);
105 verify(callback, never()).lockUnavailable(any());