2 * ============LICENSE_START==========================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * ============LICENSE_END=============================================
20 * ====================================================================
23 package org.onap.music.unittests;
25 import static org.junit.Assert.*;
26 import static org.onap.music.main.MusicCore.mDstoreHandle;
27 import static org.onap.music.main.MusicCore.mLockHandle;
29 import org.apache.zookeeper.KeeperException.NoNodeException;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.Mock;
34 import org.mockito.Mockito;
35 import org.mockito.runners.MockitoJUnitRunner;
36 import org.onap.music.exceptions.MusicLockingException;
37 import org.onap.music.exceptions.MusicQueryException;
38 import org.onap.music.exceptions.MusicServiceException;
39 import org.onap.music.lockingservice.MusicLockState;
40 import org.onap.music.lockingservice.MusicLockingService;
41 import org.onap.music.lockingservice.MusicLockState.LockStatus;
42 import org.onap.music.main.MusicCore;
43 import org.onap.music.main.MusicUtil;
44 import org.onap.music.main.ResultType;
45 import org.onap.music.main.ReturnType;
46 import org.onap.music.main.MusicCore.Condition;
47 import org.onap.music.datastore.MusicDataStore;
48 import org.onap.music.datastore.PreparedQueryObject;
49 import com.datastax.driver.core.ResultSet;
50 import com.datastax.driver.core.Session;
52 @RunWith(MockitoJUnitRunner.class)
53 public class TestMusicCore {
56 private Condition condition;
62 private PreparedQueryObject preparedQueryObject;
65 private Session session;
69 mLockHandle = Mockito.mock(MusicLockingService.class);
74 public void testCreateLockReferenceforvalidlock() {
75 Mockito.when(mLockHandle.createLockId("/" + "test")).thenReturn("lock");
76 String lockId = MusicCore.createLockReference("test");
77 assertEquals("lock", lockId);
78 Mockito.verify(mLockHandle).createLockId("/" + "test");
82 public void testIsTableOrKeySpaceLock() {
83 Boolean result = MusicCore.isTableOrKeySpaceLock("ks1.tn1");
88 public void testIsTableOrKeySpaceLockwithPrimarykey() {
89 Boolean result = MusicCore.isTableOrKeySpaceLock("ks1.tn1.pk1");
94 public void testGetMusicLockState() throws MusicLockingException {
95 MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
96 Mockito.when(mLockHandle.getLockState("ks1.tb1.pk1")).thenReturn(musicLockState);
97 MusicLockState mls = MusicCore.getMusicLockState("ks1.tb1.pk1");
98 assertEquals(musicLockState, mls);
99 Mockito.verify(mLockHandle).getLockState("ks1.tb1.pk1");
103 public void testAcquireLockifisMyTurnTrue() throws MusicLockingException {
104 Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
105 ReturnType lock = MusicCore.acquireLock("ks1.tn1", "id1");
106 assertEquals(lock.getResult(), ResultType.SUCCESS);
107 Mockito.verify(mLockHandle).isMyTurn("id1");
111 public void testAcquireLockifisMyTurnFalse() throws MusicLockingException {
112 Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
113 ReturnType lock = MusicCore.acquireLock("ks1.ts1", "id1");
114 assertEquals(lock.getResult(), ResultType.FAILURE);
115 Mockito.verify(mLockHandle).isMyTurn("id1");
119 public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockTrue() throws MusicLockingException {
120 Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
121 ReturnType lock = MusicCore.acquireLock("ks1.tn1", "id1");
122 assertEquals(lock.getResult(), ResultType.SUCCESS);
123 Mockito.verify(mLockHandle).isMyTurn("id1");
127 public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockFalseandHaveLock() throws MusicLockingException {
128 MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
129 Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
130 Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
131 ReturnType lock = MusicCore.acquireLock("ks1.tn1.pk1", "id1");
132 assertEquals(lock.getResult(), ResultType.SUCCESS);
133 Mockito.verify(mLockHandle).isMyTurn("id1");
134 Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
138 public void testAcquireLockifisMyTurnTrueandIsTableOrKeySpaceLockFalseandDontHaveLock() throws MusicLockingException {
139 MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id2");
140 Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
141 Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
142 ReturnType lock = MusicCore.acquireLock("ks1.tn1.pk1", "id1");
143 assertEquals(lock.getResult(), ResultType.SUCCESS);
144 Mockito.verify(mLockHandle).isMyTurn("id1");
145 Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
149 public void testAcquireLockifLockRefDoesntExist() throws MusicLockingException {
150 Mockito.when(mLockHandle.lockIdExists("bs1")).thenReturn(false);
151 ReturnType lock = MusicCore.acquireLock("ks1.ts1", "bs1");
152 assertEquals(lock.getResult(), ResultType.FAILURE);
153 assertEquals(lock.getMessage(), "Lockid doesn't exist");
154 Mockito.verify(mLockHandle).lockIdExists("bs1");
158 public void testAcquireLockWithLeasewithLease() throws MusicLockingException {
159 MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
160 musicLockState.setLeasePeriod(0);
161 ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
162 Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
163 Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
164 ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
165 assertEquals(expectedResult.getResult(), actualResult.getResult());
166 Mockito.verify(mLockHandle).isMyTurn("id1");
167 Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
171 public void testAcquireLockWithLeasewithException() throws MusicLockingException {
172 ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "failure");
173 Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenThrow(new MusicLockingException());
174 Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
175 ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
176 assertEquals(expectedResult.getResult(), actualResult.getResult());
177 Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
181 public void testAcquireLockWithLeasewithLockStatusLOCKED() throws MusicLockingException {
182 MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
183 ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
184 Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
185 Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
186 ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
187 assertEquals(expectedResult.getResult(), actualResult.getResult());
188 Mockito.verify(mLockHandle).isMyTurn("id1");
189 Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
193 public void testAcquireLockWithLeasewithLockStatusUNLOCKED() throws MusicLockingException {
194 MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
195 ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
196 Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
197 Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
198 ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
199 assertEquals(expectedResult.getResult(), actualResult.getResult());
200 Mockito.verify(mLockHandle).isMyTurn("id1");
201 Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
206 public void testAcquireLockWithLeaseIfNotMyTurn() throws MusicLockingException {
207 MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
208 ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
209 Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
210 Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
211 ReturnType actualResult = MusicCore.acquireLockWithLease("ks1.tn1.pk1", "id1", 6000);
212 assertEquals(expectedResult.getResult(), actualResult.getResult());
213 Mockito.verify(mLockHandle).isMyTurn("id1");
214 Mockito.verify(mLockHandle).getLockState("ks1.tn1.pk1");
218 public void testQuorumGet() throws MusicServiceException, MusicQueryException {
219 preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
220 mDstoreHandle = Mockito.mock(MusicDataStore.class);
221 rs = Mockito.mock(ResultSet.class);
222 session = Mockito.mock(Session.class);
223 Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
224 Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
225 ResultSet rs1 = MusicCore.quorumGet(preparedQueryObject);
230 public void testGetLockNameFromId() {
231 String lockname = MusicCore.getLockNameFromId("lockName$id");
232 assertEquals("lockName", lockname);
236 public void testDestroyLockRef() throws NoNodeException {
237 Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
238 MusicCore.destroyLockRef("id1");
239 Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
243 public void testreleaseLockwithvoluntaryReleaseTrue() throws NoNodeException {
244 MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
245 Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
246 MusicLockState musicLockState1 = MusicCore.releaseLock("id1", true);
247 assertEquals(musicLockState.getLockStatus(), musicLockState1.getLockStatus());
248 Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
252 public void testreleaseLockwithvoluntaryReleaseFalse() throws NoNodeException {
253 MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
254 Mockito.doNothing().when(mLockHandle).unlockAndDeleteId("id1");
255 MusicLockState musicLockState1 = MusicCore.releaseLock("id1", false);
256 assertEquals(musicLockState.getLockStatus(), musicLockState1.getLockStatus());
257 Mockito.verify(mLockHandle, Mockito.atLeastOnce()).unlockAndDeleteId("id1");
261 public void testDeleteLock() throws MusicLockingException {
262 Mockito.doNothing().when(mLockHandle).deleteLock("/" + "id1");
263 MusicCore.deleteLock("id1");
264 Mockito.verify(mLockHandle).deleteLock("/" + "id1");
268 * @Test public void testNonKeyRelatedPut() throws Exception { mDstoreHandle =
269 * Mockito.mock(MusicDataStore.class); Mockito.when(mDstoreHandle.executePut("qu1",
270 * "consistency")).thenReturn(true); Boolean result = MusicCore.nonKeyRelatedPut("qu1",
271 * "consistency"); assertTrue(result); Mockito.verify(mDstoreHandle).executePut("qu1",
276 public void testEventualPutPreparedQuery() throws MusicServiceException, MusicQueryException {
277 mDstoreHandle = Mockito.mock(MusicDataStore.class);
278 preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
279 ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
280 session = Mockito.mock(Session.class);
281 Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
282 Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(true);
283 ReturnType actualResult = MusicCore.eventualPut(preparedQueryObject);
284 assertEquals(expectedResult.getResult(), actualResult.getResult());
285 Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "eventual");
289 public void testEventualPutPreparedQuerywithResultFalse()
290 throws MusicServiceException, MusicQueryException {
291 mDstoreHandle = Mockito.mock(MusicDataStore.class);
292 preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
293 ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
294 session = Mockito.mock(Session.class);
295 Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
296 Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "eventual")).thenReturn(false);
297 ReturnType actualResult = MusicCore.eventualPut(preparedQueryObject);
298 assertEquals(expectedResult.getResult(), actualResult.getResult());
299 Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "eventual");
300 //Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, MusicUtil.EVENTUAL);
304 public void testCriticalPutPreparedQuerywithValidLockId()
306 mDstoreHandle = Mockito.mock(MusicDataStore.class);
307 preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
308 MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
309 Mockito.when(condition.testCondition()).thenReturn(true);
310 session = Mockito.mock(Session.class);
311 Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
312 ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
313 Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
314 .thenReturn(musicLockState);
315 Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "critical")).thenReturn(true);
316 ReturnType returnType = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
318 assertEquals(expectedResult.getResult(), returnType.getResult());
319 Mockito.verify(condition).testCondition();
320 Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
321 Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "critical");
325 public void testCriticalPutPreparedQuerywithInvalidLockId() throws MusicLockingException {
326 mDstoreHandle = Mockito.mock(MusicDataStore.class);
327 preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
328 MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
329 ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
330 Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
331 .thenReturn(musicLockState);
332 ReturnType returnType = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
334 assertEquals(expectedResult.getResult(), returnType.getResult());
335 Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
339 public void testCriticalPutPreparedQuerywithvalidLockIdandTestConditionFalse() throws Exception {
340 mDstoreHandle = Mockito.mock(MusicDataStore.class);
341 preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
342 MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
343 Mockito.when(condition.testCondition()).thenReturn(false);
344 ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
345 Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
346 .thenReturn(musicLockState);
347 ReturnType returnType = MusicCore.criticalPut("ks1", "tn1", "pk1", preparedQueryObject,
349 assertEquals(expectedResult.getResult(), returnType.getResult());
350 Mockito.verify(condition).testCondition();
351 Mockito.verify(mLockHandle).getLockState("ks1" + "." + "tn1" + "." + "pk1");
355 public void testNonKeyRelatedPutPreparedQuery() throws Exception {
356 mDstoreHandle = Mockito.mock(MusicDataStore.class);
357 preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
358 session = Mockito.mock(Session.class);
359 Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
360 Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "consistency")).thenReturn(true);
361 ResultType result = MusicCore.nonKeyRelatedPut(preparedQueryObject, "consistency");
362 assertEquals(ResultType.SUCCESS, result);
363 Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "consistency");
367 public void testAtomicPutPreparedQuery() throws Exception {
368 mDstoreHandle = Mockito.mock(MusicDataStore.class);
369 preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
370 Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
371 MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
372 ReturnType expectedResult = new ReturnType(ResultType.SUCCESS, "Succes");
373 session = Mockito.mock(Session.class);
374 Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
375 Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
376 Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
377 Mockito.when(condition.testCondition()).thenReturn(true);
378 Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
379 .thenReturn(musicLockState);
380 Mockito.when(mDstoreHandle.executePut(preparedQueryObject, "critical")).thenReturn(true);
381 ReturnType returnType =
382 MusicCore.atomicPut("ks1", "tn1", "pk1", preparedQueryObject, condition);
383 assertEquals(expectedResult.getResult(), returnType.getResult());
384 Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
385 Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
386 Mockito.verify(mLockHandle).isMyTurn("id1");
387 Mockito.verify(condition).testCondition();
388 Mockito.verify(mLockHandle, Mockito.atLeastOnce())
389 .getLockState("ks1" + "." + "tn1" + "." + "pk1");
390 Mockito.verify(mDstoreHandle).executePut(preparedQueryObject, "critical");
394 public void testAtomicPutPreparedQuerywithAcquireLockWithLeaseFalse() throws MusicLockingException {
395 mDstoreHandle = Mockito.mock(MusicDataStore.class);
396 preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
397 Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
398 ReturnType expectedResult = new ReturnType(ResultType.FAILURE, "Failure");
399 Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
400 ReturnType returnType =
401 MusicCore.atomicPut("ks1", "tn1", "pk1", preparedQueryObject, condition);
402 assertEquals(expectedResult.getResult(), returnType.getResult());
403 Mockito.verify(mLockHandle).isMyTurn("id1");
404 Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
408 public void testAtomicGetPreparedQuery() throws MusicServiceException, MusicQueryException, MusicLockingException {
409 mDstoreHandle = Mockito.mock(MusicDataStore.class);
410 preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
411 rs = Mockito.mock(ResultSet.class);
412 session = Mockito.mock(Session.class);
413 Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
414 Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
415 MusicLockState musicLockState = new MusicLockState(LockStatus.LOCKED, "id1");
416 Mockito.when(mLockHandle.getLockState("ks1.tn1.pk1")).thenReturn(musicLockState);
417 Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(true);
418 Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
419 .thenReturn(musicLockState);
420 Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
421 ResultSet rs1 = MusicCore.atomicGet("ks1", "tn1", "pk1", preparedQueryObject);
423 Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
424 Mockito.verify(mLockHandle, Mockito.atLeastOnce()).getLockState("ks1.tn1.pk1");
425 Mockito.verify(mLockHandle).isMyTurn("id1");
426 Mockito.verify(mLockHandle, Mockito.atLeastOnce())
427 .getLockState("ks1" + "." + "tn1" + "." + "pk1");
428 Mockito.verify(mDstoreHandle).executeCriticalGet(preparedQueryObject);
432 public void testAtomicGetPreparedQuerywithAcquireLockWithLeaseFalse()
433 throws MusicServiceException, MusicLockingException {
434 mDstoreHandle = Mockito.mock(MusicDataStore.class);
435 preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
436 rs = Mockito.mock(ResultSet.class);
437 Mockito.when(mLockHandle.createLockId("/" + "ks1.tn1.pk1")).thenReturn("id1");
438 Mockito.when(mLockHandle.isMyTurn("id1")).thenReturn(false);
439 ResultSet rs1 = MusicCore.atomicGet("ks1", "tn1", "pk1", preparedQueryObject);
441 Mockito.verify(mLockHandle).createLockId("/" + "ks1.tn1.pk1");
442 Mockito.verify(mLockHandle).isMyTurn("id1");
446 public void testGetPreparedQuery() throws MusicServiceException, MusicQueryException {
447 mDstoreHandle = Mockito.mock(MusicDataStore.class);
448 rs = Mockito.mock(ResultSet.class);
449 preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
450 session = Mockito.mock(Session.class);
451 Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
452 Mockito.when(mDstoreHandle.executeEventualGet(preparedQueryObject)).thenReturn(rs);
453 ResultSet rs1 = MusicCore.get(preparedQueryObject);
455 Mockito.verify(mDstoreHandle).executeEventualGet(preparedQueryObject);
460 public void testcriticalGetPreparedQuery() throws MusicServiceException, MusicQueryException, MusicLockingException {
461 mDstoreHandle = Mockito.mock(MusicDataStore.class);
462 preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
463 MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id1");
464 rs = Mockito.mock(ResultSet.class);
465 session = Mockito.mock(Session.class);
466 Mockito.when(mDstoreHandle.getSession()).thenReturn(session);
467 Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
468 .thenReturn(musicLockState);
469 Mockito.when(mDstoreHandle.executeCriticalGet(preparedQueryObject)).thenReturn(rs);
470 ResultSet rs1 = MusicCore.criticalGet("ks1", "tn1", "pk1", preparedQueryObject, "id1");
472 Mockito.verify(mLockHandle, Mockito.atLeastOnce())
473 .getLockState("ks1" + "." + "tn1" + "." + "pk1");
474 Mockito.verify(mDstoreHandle).executeCriticalGet(preparedQueryObject);
478 public void testcriticalGetPreparedQuerywithInvalidLockId() throws MusicServiceException, MusicLockingException {
479 mDstoreHandle = Mockito.mock(MusicDataStore.class);
480 preparedQueryObject = Mockito.mock(PreparedQueryObject.class);
481 MusicLockState musicLockState = new MusicLockState(LockStatus.UNLOCKED, "id2");
482 Mockito.when(mLockHandle.getLockState("ks1" + "." + "tn1" + "." + "pk1"))
483 .thenReturn(musicLockState);
484 ResultSet rs1 = MusicCore.criticalGet("ks1", "tn1", "pk1", preparedQueryObject, "id1");
486 Mockito.verify(mLockHandle, Mockito.atLeastOnce())
487 .getLockState("ks1" + "." + "tn1" + "." + "pk1");