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