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