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