Adding HEAT map information.
[music.git] / src / test / java / org / onap / music / unittests / TestMusicCore.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
4  * ===================================================================
5  *  Copyright (c) 2017 AT&T Intellectual Property
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
10  * 
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * 
19  * ============LICENSE_END=============================================
20  * ====================================================================
21  */
22 package org.onap.music.unittests;
23
24 import static org.junit.Assert.*;
25 import static org.onap.music.main.MusicCore.mDstoreHandle;
26 import static org.onap.music.main.MusicCore.mLockHandle;
27
28 import org.apache.zookeeper.KeeperException.NoNodeException;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.Mock;
33 import org.mockito.Mockito;
34 import org.mockito.runners.MockitoJUnitRunner;
35 import org.onap.music.exceptions.MusicLockingException;
36 import org.onap.music.exceptions.MusicQueryException;
37 import org.onap.music.exceptions.MusicServiceException;
38 import org.onap.music.lockingservice.MusicLockState;
39 import org.onap.music.lockingservice.MusicLockingService;
40 import org.onap.music.lockingservice.MusicLockState.LockStatus;
41 import org.onap.music.main.MusicCore;
42 import org.onap.music.main.MusicUtil;
43 import org.onap.music.main.ResultType;
44 import org.onap.music.main.ReturnType;
45 import org.onap.music.main.MusicCore.Condition;
46 import org.onap.music.datastore.MusicDataStore;
47 import org.onap.music.datastore.PreparedQueryObject;
48 import com.datastax.driver.core.ResultSet;
49 import com.datastax.driver.core.Session;
50
51 @RunWith(MockitoJUnitRunner.class)
52 public class TestMusicCore {
53
54     @Mock
55     private Condition condition;
56
57     @Mock
58     private ResultSet rs;
59
60     @Mock
61     private PreparedQueryObject preparedQueryObject;
62     
63     @Mock
64     private Session session;
65
66     @Before
67     public void setUp() {
68         mLockHandle = Mockito.mock(MusicLockingService.class);
69
70     }
71
72     @Test
73     public void testCreateLockReferenceforvalidlock() {
74         Mockito.when(mLockHandle.createLockId("/" + "test")).thenReturn("lock");
75         String lockId = MusicCore.createLockReference("test");
76         assertEquals("lock", lockId);
77         Mockito.verify(mLockHandle).createLockId("/" + "test");
78     }
79
80     @Test
81     public void testIsTableOrKeySpaceLock() {
82         Boolean result = MusicCore.isTableOrKeySpaceLock("ks1.tn1");
83         assertTrue(result);
84     }
85
86     @Test
87     public void testIsTableOrKeySpaceLockwithPrimarykey() {
88         Boolean result = MusicCore.isTableOrKeySpaceLock("ks1.tn1.pk1");
89         assertFalse(result);
90     }
91
92     @Test
93     public void testGetMusicLockState() throws MusicLockingException {
94         MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
95         Mockito.when(mLockHandle.getLockState("ks1.tb1.pk1")).thenReturn(musicLockState);
96         MusicLockState mls = MusicCore.getMusicLockState("ks1.tb1.pk1");
97         assertEquals(musicLockState, mls);
98         Mockito.verify(mLockHandle).getLockState("ks1.tb1.pk1");
99     }
100
101     @Test
102     public void testAcquireLockifisMyTurnTrue() throws MusicLockingException {
103         Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
104         ReturnType lock = MusicCore.acquireLock("ks1.tn1", "id1");
105         assertEquals(lock.getResult(), ResultType.SUCCESS);
106         Mockito.verify(mLockHandle).isMyTurn("id1");
107     }
108
109     @Test
110     public void testAcquireLockifisMyTurnFalse() throws MusicLockingException {
111         Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
112         ReturnType lock = MusicCore.acquireLock("ks1.ts1", "id1");
113         assertEquals(lock.getResult(), ResultType.FAILURE);
114         Mockito.verify(mLockHandle).isMyTurn("id1");
115     }
116
117     @Test
118     public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockTrue() throws MusicLockingException {
119         Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
120         ReturnType lock = MusicCore.acquireLock("ks1.tn1", "id1");
121         assertEquals(lock.getResult(), ResultType.SUCCESS);
122         Mockito.verify(mLockHandle).isMyTurn("id1");
123     }
124
125     @Test
126     public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockFalseandHaveLock() throws MusicLockingException {
127         MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
128         Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
129         Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
130         ReturnType lock = MusicCore.acquireLock("ks1.tn1.pk1", "id1");
131         assertEquals(lock.getResult(), ResultType.SUCCESS);
132         Mockito.verify(mLockHandle).isMyTurn("id1");
133         Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
134     }
135
136     @Test
137     public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockFalseandDontHaveLock() throws MusicLockingException {
138         MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id2");
139         Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
140         Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
141         ReturnType lock = MusicCore.acquireLock("ks1.tn1.pk1", "id1");
142         assertEquals(lock.getResult(), ResultType.SUCCESS);
143         Mockito.verify(mLockHandle).isMyTurn("id1");
144         Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
145     }
146     
147     @Test
148     public void testAcquireLockifLockRefDoesntExist() throws MusicLockingException {
149         Mockito.when(mLockHandle.lockIdExists("bs1")).thenReturn(false);
150         ReturnType lock = MusicCore.acquireLock("ks1.ts1", "bs1");
151         assertEquals(lock.getResult(), ResultType.FAILURE);
152         assertEquals(lock.getMessage(), "Lockid doesn't exist");
153         Mockito.verify(mLockHandle).lockIdExists("bs1");
154     }
155     
156     @Test
157     public void testAcquireLockWithLeasewithLease() throws MusicLockingException {
158         MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
159         musicLockState.setLeasePeriod(0);
160         ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
161         Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
162         Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
163         ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
164         assertEquals(expectedResult.getResult(), actualResult.getResult());
165         Mockito.verify(mLockHandle).isMyTurn("id1");
166         Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
167     }
168     
169     @Test
170     public void testAcquireLockWithLeasewithException() throws MusicLockingException {
171         ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "failure");
172         Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenThrow(new MusicLockingException());
173         Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
174         ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
175         assertEquals(expectedResult.getResult(), actualResult.getResult());
176         Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
177     }
178
179     @Test
180     public void testAcquireLockWithLeasewithLockStatusLOCKED() throws MusicLockingException {
181         MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
182         ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
183         Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
184         Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
185         ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
186         assertEquals(expectedResult.getResult(), actualResult.getResult());
187         Mockito.verify(mLockHandle).isMyTurn("id1");
188         Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
189     }
190
191     @Test
192     public void testAcquireLockWithLeasewithLockStatusUNLOCKED() throws MusicLockingException {
193         MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
194         ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
195         Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
196         Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
197         ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
198         assertEquals(expectedResult.getResult(), actualResult.getResult());
199         Mockito.verify(mLockHandle).isMyTurn("id1");
200         Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
201
202     }
203
204     @Test
205     public void testAcquireLockWithLeaseIfNotMyTurn() throws MusicLockingException {
206         MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
207         ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
208         Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
209         Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
210         ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
211         assertEquals(expectedResult.getResult(), actualResult.getResult());
212         Mockito.verify(mLockHandle).isMyTurn("id1");
213         Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
214     }
215
216     @Test
217     public void testQuorumGet() throws MusicServiceException, MusicQueryException {
218         preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
219         mDstoreHandle = Mockito.mock(MusicDataStore.class);
220         rs = Mockito.mock(ResultSet.class);
221         session = Mockito.mock(Session.class);
222         Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
223         Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
224         ResultSet rs1 = MusicCore.quorumGet(preparedQueryObject);
225         assertNotNull(rs1);
226     }
227
228     @Test
229     public void testGetLockNameFromId() {
230         String lockname = MusicCore.getLockNameFromId("lockName$id");
231         assertEquals("lockName", lockname);
232     }
233
234     @Test
235     public void testDestroyLockRef() throws NoNodeException {
236         Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
237         MusicCore.destroyLockRef("id1");
238         Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
239     }
240
241     @Test
242     public void testreleaseLockwithvoluntaryReleaseTrue() throws NoNodeException {
243         MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
244         Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
245         MusicLockState musicLockState1 = MusicCore.releaseLock("id1", true);
246         assertEquals(musicLockState.getLockStatus(), musicLockState1.getLockStatus());
247         Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
248     }
249
250     @Test
251     public void testreleaseLockwithvoluntaryReleaseFalse() throws NoNodeException {
252         MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
253         Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
254         MusicLockState musicLockState1 = MusicCore.releaseLock("id1", false);
255         assertEquals(musicLockState.getLockStatus(), musicLockState1.getLockStatus());
256         Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
257     }
258
259     @Test
260     public void testDeleteLock() throws MusicLockingException {
261         Mockito.doNothing().when(mLockHandle).deleteLock("/" + "id1");
262         MusicCore.deleteLock("id1");
263         Mockito.verify(mLockHandle).deleteLock("/" + "id1");
264     }
265
266     /*
267      * @Test public void testNonKeyRelatedPut() throws Exception { mDstoreHandle =
268      * Mockito.mock(MusicDataStore.class); Mockito.when(mDstoreHandle.executePut("qu1",
269      * "consistency")).thenReturn(true); Boolean result = MusicCore.nonKeyRelatedPut("qu1",
270      * "consistency"); assertTrue(result); Mockito.verify(mDstoreHandle).executePut("qu1",
271      * "consistency"); }
272      */
273
274     @Test
275     public void testEventualPutPreparedQuery() throws MusicServiceException, MusicQueryException {
276         mDstoreHandle = Mockito.mock(MusicDataStore.class);
277         preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
278         ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
279         session = Mockito.mock(Session.class);
280         Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
281         Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(true);
282         ReturnType actualResult = MusicCore.eventualPut(preparedQueryObject);
283         assertEquals(expectedResult.getResult(), actualResult.getResult());
284         Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "eventual");
285     }
286
287     @Test
288     public void testEventualPutPreparedQuerywithResultFalse()
289                     throws MusicServiceException, MusicQueryException {
290         mDstoreHandle = Mockito.mock(MusicDataStore.class);
291         preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
292         ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
293         session = Mockito.mock(Session.class);
294         Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
295         Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(false);
296         ReturnType actualResult = MusicCore.eventualPut(preparedQueryObject);
297         assertEquals(expectedResult.getResult(), actualResult.getResult());
298         Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "eventual");
299         //Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, MusicUtil.EVENTUAL);
300     }
301
302     @Test
303     public void testCriticalPutPreparedQuerywithValidLockId()
304                     throws Exception {
305         mDstoreHandle = Mockito.mock(MusicDataStore.class);
306         preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
307         MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
308         Mockito.when(condition.testCondition()).thenReturn(true);
309         session = Mockito.mock(Session.class);
310         Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
311         ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
312         Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
313                         .thenReturn(musicLockState);
314         Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "critical")).thenReturn(true);
315         ReturnType returnType = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
316                         "id1", condition);
317         assertEquals(expectedResult.getResult(), returnType.getResult());
318         Mockito.verify(condition).testCondition();
319         Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
320         Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "critical");
321     }
322
323     @Test
324     public void testCriticalPutPreparedQuerywithInvalidLockId() throws MusicLockingException {
325         mDstoreHandle = Mockito.mock(MusicDataStore.class);
326         preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
327         MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
328         ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
329         Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
330                         .thenReturn(musicLockState);
331         ReturnType returnType = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
332                         "id1", condition);
333         assertEquals(expectedResult.getResult(), returnType.getResult());
334         Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
335     }
336
337     @Test
338     public void testCriticalPutPreparedQuerywithvalidLockIdandTestConditionFalse() throws Exception {
339         mDstoreHandle = Mockito.mock(MusicDataStore.class);
340         preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
341         MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
342         Mockito.when(condition.testCondition()).thenReturn(false);
343         ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
344         Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
345                         .thenReturn(musicLockState);
346         ReturnType returnType = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
347                         "id1", condition);
348         assertEquals(expectedResult.getResult(), returnType.getResult());
349         Mockito.verify(condition).testCondition();
350         Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
351     }
352
353     @Test
354     public void testNonKeyRelatedPutPreparedQuery() throws Exception {
355         mDstoreHandle = Mockito.mock(MusicDataStore.class);
356         preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
357         session = Mockito.mock(Session.class);
358         Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
359         Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "consistency")).thenReturn(true);
360         ResultType result = MusicCore.nonKeyRelatedPut(preparedQueryObject, "consistency");
361         assertEquals(ResultType.SUCCESS, result);
362         Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "consistency");
363     }
364
365     @Test
366     public void testAtomicPutPreparedQuery() throws Exception {
367         mDstoreHandle = Mockito.mock(MusicDataStore.class);
368         preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
369         Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
370         MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
371         ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
372         session = Mockito.mock(Session.class);
373         Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
374         Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
375         Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
376         Mockito.when(condition.testCondition()).thenReturn(true);
377         Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
378                         .thenReturn(musicLockState);
379         Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "critical")).thenReturn(true);
380         ReturnType returnType =
381                         MusicCore.atomicPut("ks1", "tn1", "pk1", preparedQueryObject, condition);
382         assertEquals(expectedResult.getResult(), returnType.getResult());
383         Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
384         Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
385         Mockito.verify(mLockHandle).isMyTurn("id1");
386         Mockito.verify(condition).testCondition();
387         Mockito.verify(mLockHandle, Mockito.atLeastOnce())
388                         .getLockState("ks1" + "." + "tn1" + "." + "pk1");
389         Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "critical");
390     }
391
392     @Test
393     public void testAtomicPutPreparedQuerywithAcquireLockWithLeaseFalse() throws MusicLockingException {
394         mDstoreHandle = Mockito.mock(MusicDataStore.class);
395         preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
396         Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
397         ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
398         Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
399         ReturnType returnType =
400                         MusicCore.atomicPut("ks1", "tn1", "pk1", preparedQueryObject, condition);
401         assertEquals(expectedResult.getResult(), returnType.getResult());
402         Mockito.verify(mLockHandle).isMyTurn("id1");
403         Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
404     }
405
406     @Test
407     public void testAtomicGetPreparedQuery() throws MusicServiceException, MusicQueryException, MusicLockingException {
408         mDstoreHandle = Mockito.mock(MusicDataStore.class);
409         preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
410         rs = Mockito.mock(ResultSet.class);
411         session = Mockito.mock(Session.class);
412         Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
413         Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
414         MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
415         Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
416         Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
417         Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
418                         .thenReturn(musicLockState);
419         Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
420         ResultSet rs1 = MusicCore.atomicGet("ks1", "tn1", "pk1", preparedQueryObject);
421         assertNotNull(rs1);
422         Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
423         Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
424         Mockito.verify(mLockHandle).isMyTurn("id1");
425         Mockito.verify(mLockHandle, Mockito.atLeastOnce())
426                         .getLockState("ks1" + "." + "tn1" + "." + "pk1");
427         Mockito.verify(mDstoreHandle).executeCriticalGet(preparedQueryObject);
428     }
429
430     @Test
431     public void testAtomicGetPreparedQuerywithAcquireLockWithLeaseFalse()
432                     throws MusicServiceException, MusicLockingException {
433         mDstoreHandle = Mockito.mock(MusicDataStore.class);
434         preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
435         rs = Mockito.mock(ResultSet.class);
436         Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
437         Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
438         ResultSet rs1 = MusicCore.atomicGet("ks1", "tn1", "pk1", preparedQueryObject);
439         assertNull(rs1);
440         Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
441         Mockito.verify(mLockHandle).isMyTurn("id1");
442     }
443
444     @Test
445     public void testGetPreparedQuery() throws MusicServiceException, MusicQueryException {
446         mDstoreHandle = Mockito.mock(MusicDataStore.class);
447         rs = Mockito.mock(ResultSet.class);
448         preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
449         session = Mockito.mock(Session.class);
450         Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
451         Mockito.when(mDstoreHandle.executeEventualGet(preparedQueryObject)).thenReturn(rs);
452         ResultSet rs1 = MusicCore.get(preparedQueryObject);
453         assertNotNull(rs1);
454         Mockito.verify(mDstoreHandle).executeEventualGet(preparedQueryObject);
455
456     }
457
458     @Test
459     public void testcriticalGetPreparedQuery() throws MusicServiceException, MusicQueryException, MusicLockingException {
460         mDstoreHandle = Mockito.mock(MusicDataStore.class);
461         preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
462         MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
463         rs = Mockito.mock(ResultSet.class);
464         session = Mockito.mock(Session.class);
465         Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
466         Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
467                         .thenReturn(musicLockState);
468         Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
469         ResultSet rs1 = MusicCore.criticalGet("ks1", "tn1", "pk1", preparedQueryObject, "id1");
470         assertNotNull(rs1);
471         Mockito.verify(mLockHandle, Mockito.atLeastOnce())
472                         .getLockState("ks1" + "." + "tn1" + "." + "pk1");
473         Mockito.verify(mDstoreHandle).executeCriticalGet(preparedQueryObject);
474     }
475
476     @Test
477     public void testcriticalGetPreparedQuerywithInvalidLockId() throws MusicServiceException, MusicLockingException {
478         mDstoreHandle = Mockito.mock(MusicDataStore.class);
479         preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
480         MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
481         Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
482                         .thenReturn(musicLockState);
483         ResultSet rs1 = MusicCore.criticalGet("ks1", "tn1", "pk1", preparedQueryObject, "id1");
484         assertNull(rs1);
485         Mockito.verify(mLockHandle, Mockito.atLeastOnce())
486                         .getLockState("ks1" + "." + "tn1" + "." + "pk1");
487     }
488
489 }