2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.controlloop.eventmanager;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertSame;
25 import static org.mockito.Matchers.any;
26 import static org.mockito.Mockito.verify;
27 import static org.mockito.Mockito.when;
29 import org.drools.core.WorkingMemory;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.kie.api.runtime.rule.FactHandle;
33 import org.mockito.Mock;
34 import org.mockito.MockitoAnnotations;
35 import org.onap.policy.drools.core.lock.Lock;
37 public class LockCallbackWorkingMemoryTest {
38 private static final String MY_NAME = "my-name";
41 private WorkingMemory workingMemory;
47 private FactHandle fact;
49 private LockCallbackWorkingMemory callback;
53 * Initializes mocks and creates a call-back.
57 MockitoAnnotations.initMocks(this);
59 when(workingMemory.getFactHandle(lock)).thenReturn(fact);
61 callback = new LockCallbackWorkingMemory(MY_NAME, workingMemory);
65 public void testLockCallbackWorkingMemory() {
66 assertEquals(MY_NAME, callback.getName());
67 assertSame(workingMemory, callback.getWorkingMemory());
71 public void testLockAvailable() {
72 callback.lockAvailable(lock);
73 verify(workingMemory).update(fact, lock);
75 // "remove" from working memory
76 when(workingMemory.getFactHandle(lock)).thenReturn(null);
77 callback.lockAvailable(lock);
79 // should be no additional calls
80 verify(workingMemory).update(any(), any());
84 public void testLockUnavailable() {
85 callback.lockUnavailable(lock);
86 verify(workingMemory).update(fact, lock);
88 // "remove" from working memory
89 when(workingMemory.getFactHandle(lock)).thenReturn(null);
90 callback.lockUnavailable(lock);
92 // should be no additional calls
93 verify(workingMemory).update(any(), any());