Removing deprecated DMAAP library
[policy/drools-pdp.git] / feature-no-locking / src / test / java / org / onap / policy / no / locking / NoLockManagerTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.policy.no.locking;
23
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;
33
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;
42
43 public class NoLockManagerTest {
44
45     private static NoLockManager nlm;
46     private static LockCallback callback;
47
48     /**
49      * Set up Junits.
50      */
51     @BeforeAll
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);
57     }
58
59     @Test
60     void testLock() {
61         assertTrue(nlm.lock());
62     }
63
64     @Test
65     void testUnlock() {
66         assertTrue(nlm.unlock());
67     }
68
69     @Test
70     void testIsLocked() {
71         assertFalse(nlm.isLocked());
72     }
73
74     @Test
75     void testStart() {
76         assertTrue(nlm.start());
77     }
78
79     @Test
80     void testStop() {
81         assertTrue(nlm.stop());
82     }
83
84     @Test
85     void testIsAlive() {
86         assertTrue(nlm.isAlive());
87     }
88
89     @Test
90     void testGetSeqNo() {
91         assertEquals(NoLockManager.SEQNO, nlm.getSequenceNumber());
92     }
93
94     @Test
95     void testBeforeCreateLockManager() {
96         assertEquals(nlm, nlm.beforeCreateLockManager(null, null));
97     }
98
99     @Test
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());
106     }
107 }