[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-be / lib / openecomp-sdc-versioning-lib / openecomp-sdc-versioning-core / src / test / java / org / openecomp / sdc / versioning / impl / VersioningManagerImplTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.versioning.impl;
22
23
24 import org.mockito.ArgumentCaptor;
25 import org.mockito.Captor;
26 import org.mockito.InjectMocks;
27 import org.mockito.Mock;
28 import org.mockito.MockitoAnnotations;
29 import org.openecomp.sdc.common.errors.CoreException;
30 import org.openecomp.sdc.versioning.dao.VersionInfoDao;
31 import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDao;
32 import org.openecomp.sdc.versioning.dao.VersionableEntityDao;
33 import org.openecomp.sdc.versioning.dao.types.UserCandidateVersion;
34 import org.openecomp.sdc.versioning.dao.types.Version;
35 import org.openecomp.sdc.versioning.dao.types.VersionInfoDeletedEntity;
36 import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity;
37 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
38 import org.openecomp.sdc.versioning.types.VersionInfo;
39 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
40 import org.testng.Assert;
41 import org.testng.annotations.BeforeMethod;
42 import org.testng.annotations.Test;
43
44 import java.util.Collections;
45 import java.util.HashSet;
46 import java.util.Map;
47 import java.util.Set;
48
49 import static org.mockito.Matchers.anyObject;
50 import static org.mockito.Mockito.doReturn;
51 import static org.mockito.Mockito.verify;
52
53 public class VersioningManagerImplTest {
54   private static final String USR1 = "usr1";
55   private static final String USR2 = "usr2";
56   private static final String TYPE1 = "Type1";
57 /*  private static final String TYPE2 = "Type2";*/
58   private static final String ID1 = "Id1";
59 /*  private static final String ID2 = "Id2";
60   private static final String ID3 = "Id3";
61   private static final String TYPE1_TABLE_NAME = "vendor_license_model";
62   private static final String TYPE1_ID_NAME = "vlm_id";
63   private static final String TYPE1_VERSION_NAME = "version";
64   private static final String TYPE2_TABLE_NAME = "feature_group";
65   private static final String TYPE2_ID_NAME = "vlm_id";
66   private static final String TYPE2_VERSION_NAME = "version";*/
67   private static final Version VERSION0 = new Version(0, 0);
68   private static final Version VERSION01 = new Version(0, 1);
69   private static final Version VERSION02 = new Version(0, 2);
70   private static final Version VERSION10 = new Version(1, 0);
71   private static final Version VERSION11 = new Version(1, 1);
72
73   /*  private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
74
75     private static UDTMapper<Version> versionMapper =
76         noSqlDb.getMappingManager().udtMapper(Version.class);*/
77   @Mock
78   private VersionInfoDao versionInfoDaoMock;
79   @Mock
80   private VersionInfoDeletedDao versionInfoDeletedDaoMock;
81   @InjectMocks
82   private VersioningManagerImpl versioningManager;
83
84   @Captor
85   private ArgumentCaptor<VersionInfoEntity> versionInfoEntityArg;
86
87   @BeforeMethod
88   public void setUp() throws Exception {
89     MockitoAnnotations.initMocks(this);
90   }
91
92   /*  @BeforeClass
93     private void init() {
94       versionInfoDaoMock.delete(new VersionInfoEntity(TYPE1, ID1));
95       versionInfoDaoMock.delete(new VersionInfoEntity(TYPE1, ID2));
96       versionInfoDaoMock.delete(new VersionInfoEntity(TYPE2, ID3));
97       String deleteFromType1 = String
98           .format("delete from %s where %s=? and %s=?", TYPE1_TABLE_NAME, TYPE1_ID_NAME,
99               TYPE1_VERSION_NAME);
100       noSqlDb.execute(deleteFromType1, ID1, versionMapper.toUDT(VERSION01));
101       noSqlDb.execute(deleteFromType1, ID1, versionMapper.toUDT(VERSION02));
102       noSqlDb.execute(deleteFromType1, ID1, versionMapper.toUDT(VERSION11));
103
104       versioningManager.register(TYPE1,
105           new VersionableEntityMetadata(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME));
106       versioningManager.register(TYPE2,
107           new VersionableEntityMetadata(TYPE2_TABLE_NAME, TYPE2_ID_NAME, TYPE2_VERSION_NAME));
108     }*/
109
110 /*  @Test
111   public void testRegister() throws Exception {
112     VersionableEntityMetadata entityMetadata =
113         new VersionableEntityMetadata(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME);
114     versioningManager.register(TYPE1, entityMetadata);
115
116     Map<String, Set<VersionableEntityMetadata>> versionableEntities =
117         versionableEntitiesCapture.capture();
118     Set<VersionableEntityMetadata> type1Entities = versionableEntities.get(TYPE1);
119     Assert.assertNotNull(type1Entities);
120     Assert.assertTrue(type1Entities.contains(entityMetadata));
121   }*/
122
123   @Test(expectedExceptions = CoreException.class)
124   public void testCreateAlreadyExisting() {
125     doReturn(new VersionInfoEntity()).when(versionInfoDaoMock).get(anyObject());
126     versioningManager.create(TYPE1, ID1, USR1);
127   }
128
129   @Test
130   public void testCreate() {
131     Version version = versioningManager.create(TYPE1, ID1, USR1);
132     Assert.assertEquals(version, VERSION01);
133
134 /*    createVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
135         version);*/
136     verify(versionInfoDaoMock).create(versionInfoEntityArg.capture());
137     VersionInfoEntity versionInfoEntity = versionInfoEntityArg.getValue();
138     assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, new Version(0, 0), VERSION01, USR1,
139         VersionStatus.Locked, new HashSet<>(), null);
140   }
141
142   @Test(expectedExceptions = CoreException.class)
143   public void testDeleteNonExisting() {
144     versioningManager.delete(TYPE1, ID1, USR1);
145   }
146
147   @Test(expectedExceptions = CoreException.class)
148   public void testDeleteLocked() {
149     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION0,
150         new UserCandidateVersion(USR1, VERSION01), Collections.emptySet(), null);
151     versioningManager.delete(TYPE1, ID1, USR1);
152   }
153
154   @Test
155   public void testDelete() {
156     VersionInfoEntity versionInfoEntity = new VersionInfoEntity();
157     versionInfoEntity.setStatus(VersionStatus.Available);
158     doReturn(versionInfoEntity).when(versionInfoDaoMock).get(anyObject());
159
160     versioningManager.delete(TYPE1, ID1, USR1);
161
162     verify(versionInfoDaoMock).delete(versionInfoEntity);
163     ArgumentCaptor<VersionInfoDeletedEntity> versionInfoDeletedEntityArg =
164         ArgumentCaptor.forClass(VersionInfoDeletedEntity.class);
165     verify(versionInfoDeletedDaoMock).create(versionInfoDeletedEntityArg.capture());
166   }
167
168   @Test(expectedExceptions = CoreException.class)
169   public void testUndoDeleteNonExisting() {
170     versioningManager.undoDelete(TYPE1, ID1, USR1);
171   }
172
173   @Test
174   public void testUndoDelete() {
175     VersionInfoDeletedEntity versionInfoDeletedEntity = new VersionInfoDeletedEntity();
176     versionInfoDeletedEntity.setStatus(VersionStatus.Available);
177     doReturn(versionInfoDeletedEntity).when(versionInfoDeletedDaoMock).get(anyObject());
178
179     versioningManager.undoDelete(TYPE1, ID1, USR1);
180
181     verify(versionInfoDeletedDaoMock).delete(versionInfoDeletedEntity);
182     verify(versionInfoDaoMock).create(versionInfoEntityArg.capture());
183 /*
184     VersionInfoDeletedEntity versionInfoDeletedEntity =
185         versionInfoDeletedDaoMock.get(new VersionInfoDeletedEntity(TYPE1, ID1));
186     Assert.assertNotNull(versionInfoDeletedEntity);
187
188     Map<String, VersionInfo> entitiesInfoMap =
189         versioningManager.listDeletedEntitiesVersionInfo(TYPE1, USR2, null);
190     Assert.assertEquals(entitiesInfoMap.size(), 1);
191     VersionInfoEntity versionInfoEntity = versionInfoDaoMock.get(new VersionInfoEntity(TYPE1, ID1));
192     Assert.assertNull(versionInfoEntity);
193     versioningManager.undoDelete(TYPE1, ID1, USR1);
194     versionInfoEntity = versionInfoDaoMock.get(new VersionInfoEntity(TYPE1, ID1));
195     Assert.assertNotNull(versionInfoEntity);*/
196   }
197
198   @Test(expectedExceptions = CoreException.class)
199   public void testCheckoutNonExisting() {
200     versioningManager.checkout(TYPE1, ID1, USR2);
201   }
202
203   @Test(expectedExceptions = CoreException.class)
204   public void testCheckoutOnLockedSameUser() {
205     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION0,
206         new UserCandidateVersion(USR1, VERSION01), Collections.emptySet(), null);
207     versioningManager.checkout(TYPE1, ID1, USR1);
208   }
209
210   @Test(expectedExceptions = CoreException.class)
211   public void testCheckoutOnLockedOtherUser() {
212     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION0,
213         new UserCandidateVersion(USR2, VERSION01), Collections.emptySet(), null);
214     versioningManager.checkout(TYPE1, ID1, USR1);
215   }
216
217   @Test
218   public void testCheckoutOnFinalized() {
219     Set<Version> viewableVersions = new HashSet<>();
220     viewableVersions.add(VERSION10);
221     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Final, VERSION10, null, viewableVersions,
222         VERSION10);
223
224     Version version = versioningManager.checkout(TYPE1, ID1, USR1);
225     Assert.assertEquals(version, VERSION11);
226
227     VersionInfoEntity versionInfoEntity = versionInfoDaoMock.get(new VersionInfoEntity(TYPE1, ID1));
228     assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION10, VERSION11, USR1,
229         VersionStatus.Locked, viewableVersions, VERSION10);
230 /*
231     ResultSet results =
232         loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
233             VERSION11);
234     Assert.assertTrue(results.iterator().hasNext());*/
235   }
236
237   @Test
238   public void testCheckout() {
239     Set<Version> viewableVersions = new HashSet<>();
240     viewableVersions.add(VERSION01);
241     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Available, VERSION01, null, viewableVersions,
242         null);
243
244     Version version = versioningManager.checkout(TYPE1, ID1, USR1);
245     Assert.assertEquals(version, VERSION02);
246
247     verify(versionInfoDaoMock).update(versionInfoEntityArg.capture());
248     VersionInfoEntity versionInfoEntity = versionInfoEntityArg.getValue();
249
250     assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION01, VERSION02, USR1,
251         VersionStatus.Locked, viewableVersions, null);
252
253 /*    ResultSet results =
254         loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
255             VERSION02);
256     Assert.assertTrue(results.iterator().hasNext());*/
257   }
258
259   @Test(expectedExceptions = CoreException.class)
260   public void testUndoCheckoutNonExisting() {
261     versioningManager.undoCheckout(TYPE1, ID1, USR1);
262   }
263
264   @Test(expectedExceptions = CoreException.class)
265   public void testUndoCheckoutOnAvailable() {
266     Set<Version> viewableVersions = new HashSet<>();
267     viewableVersions.add(VERSION01);
268     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Available, VERSION01, null, viewableVersions,
269         null);
270
271     versioningManager.undoCheckout(TYPE1, ID1, USR1);
272   }
273
274   @Test(expectedExceptions = CoreException.class)
275   public void testUndoCheckouOnFinalized() {
276     Set<Version> viewableVersions = new HashSet<>();
277     viewableVersions.add(VERSION10);
278     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Final, VERSION10, null, viewableVersions,
279         VERSION10);
280     versioningManager.undoCheckout(TYPE1, ID1, USR2);
281   }
282
283   @Test(expectedExceptions = CoreException.class)
284   public void testUndoCheckoutOnLockedOtherUser() {
285     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION0,
286         new UserCandidateVersion(USR2, VERSION01), Collections.emptySet(), null);
287
288     versioningManager.undoCheckout(TYPE1, ID1, USR1);
289   }
290
291   @Test
292   public void testUndoCheckout() {
293     HashSet<Version> viewableVersions = new HashSet<>();
294     viewableVersions.add(VERSION01);
295     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION01,
296         new UserCandidateVersion(USR1, VERSION02), viewableVersions, null);
297
298     Version version = versioningManager.undoCheckout(TYPE1, ID1, USR1);
299     Assert.assertEquals(version, VERSION01);
300
301     VersionInfoEntity versionInfoEntity = versionInfoDaoMock.get(new VersionInfoEntity(TYPE1, ID1));
302     assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION01, null, null,
303         VersionStatus.Available, viewableVersions, null);
304
305 /*    ResultSet results =
306         loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
307             VERSION02);
308     Assert.assertFalse(results.iterator().hasNext());*/
309   }
310
311   @Test(expectedExceptions = CoreException.class)
312   public void testCheckinNonExisting() {
313     versioningManager.checkin(TYPE1, ID1, USR1, "");
314   }
315
316   @Test(expectedExceptions = CoreException.class)
317   public void testCheckinOnAvailable() {
318     Set<Version> viewableVersions = new HashSet<>();
319     viewableVersions.add(VERSION01);
320     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Available, VERSION01, null, viewableVersions,
321         null);
322
323     versioningManager.checkin(TYPE1, ID1, USR1, "fail checkin");
324   }
325
326
327   @Test(expectedExceptions = CoreException.class)
328   public void testCheckinOnFinalized() {
329     Set<Version> viewableVersions = new HashSet<>();
330     viewableVersions.add(VERSION10);
331     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Final, VERSION10, null, viewableVersions,
332         VERSION10);
333
334     versioningManager.checkin(TYPE1, ID1, USR1, "failed checkin");
335   }
336
337   @Test(expectedExceptions = CoreException.class)
338   public void testCheckinOnLockedOtherUser() {
339     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION0,
340         new UserCandidateVersion(USR2, VERSION01), Collections.emptySet(), null);
341
342     versioningManager.checkin(TYPE1, ID1, USR1, "");
343   }
344
345   @Test
346   public void testCheckin() {
347     HashSet<Version> viewableVersions = new HashSet<>();
348     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION0,
349         new UserCandidateVersion(USR1, VERSION01), viewableVersions, null);
350
351     Version version = versioningManager.checkin(TYPE1, ID1, USR1, "checkin 0.1");
352     Assert.assertEquals(version, VERSION01);
353
354     verify(versionInfoDaoMock).update(versionInfoEntityArg.capture());
355     VersionInfoEntity versionInfoEntity = versionInfoEntityArg.getValue();
356
357     viewableVersions.add(VERSION01);
358     assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION01, null, null,
359         VersionStatus.Available, viewableVersions, null);
360   }
361
362   @Test(expectedExceptions = CoreException.class)
363   public void testSubmitNonExisting() {
364     versioningManager.submit(TYPE1, ID1, USR2, "failed submit");
365   }
366
367   @Test(expectedExceptions = CoreException.class)
368   public void testSubmitOnLocked() {
369     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION0,
370         new UserCandidateVersion(USR1, VERSION01), Collections.emptySet(), null);
371     versioningManager.submit(TYPE1, ID1, USR2, "failed submit");
372   }
373
374
375   @Test(expectedExceptions = CoreException.class)
376   public void testSubmitOnFinalized() {
377     Set<Version> viewableVersions = new HashSet<>();
378     viewableVersions.add(VERSION10);
379     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Final, VERSION10, null, viewableVersions,
380         VERSION10);
381     versioningManager.submit(TYPE1, ID1, USR2, "failed submit");
382   }
383
384   @Test
385   public void testSubmit() {
386     Version version32 = new Version(3, 2);
387     Version version40 = new Version(4, 0);
388
389     Set<Version> viewableVersions = new HashSet<>();
390     viewableVersions.add(VERSION10);
391     viewableVersions.add(new Version(2, 0));
392     viewableVersions.add(new Version(3, 0));
393     viewableVersions.add(new Version(3, 1));
394     viewableVersions.add(version32);
395     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Available, version32, null, viewableVersions,
396         new Version(3, 0));
397
398     Version version = versioningManager.submit(TYPE1, ID1, USR1, "submit msg");
399     Assert.assertEquals(version, version40);
400     viewableVersions.remove(new Version(3, 1));
401     viewableVersions.remove(version32);
402     viewableVersions.add(version40);
403
404     verify(versionInfoDaoMock).update(versionInfoEntityArg.capture());
405     VersionInfoEntity versionInfoEntity = versionInfoEntityArg.getValue();
406
407     assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, version40, null, null,
408         VersionStatus.Final, viewableVersions, version40);
409
410 /*    ResultSet results =
411         loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
412             VERSION10);
413     Assert.assertTrue(results.iterator().hasNext());*/
414   }
415
416   @Test(expectedExceptions = CoreException.class)
417   public void testGetVersionInfoOnNonExistingEntity() {
418     versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Read);
419   }
420
421   @Test
422   public void testGetVersionInfoForReadOnAvailable() {
423     Set<Version> viewableVersions = new HashSet<>();
424     viewableVersions.add(VERSION01);
425     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Available, VERSION01, null, viewableVersions,
426         null);
427
428     VersionInfo versionInfo =
429         versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Read);
430     assertVersionInfo(versionInfo, VERSION01, VersionStatus.Available, null,
431         viewableVersions, null);
432   }
433
434   @Test(expectedExceptions = CoreException.class)
435   public void testGetVersionInfoForWriteOnAvailable() {
436     Set<Version> viewableVersions = new HashSet<>();
437     viewableVersions.add(VERSION01);
438     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Available, VERSION01, null, viewableVersions,
439         null);
440
441     versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Write);
442   }
443
444   @Test
445   public void testGetVersionInfoForReadOnLockedSameUser() {
446     Set<Version> viewableVersions = new HashSet<>();
447     viewableVersions.add(VERSION01);
448     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION01,
449         new UserCandidateVersion(USR1, VERSION02), viewableVersions, null);
450
451     VersionInfo versionInfo =
452         versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Read);
453     viewableVersions.add(VERSION02);
454     assertVersionInfo(versionInfo, VERSION02, VersionStatus.Locked, USR1, viewableVersions, null);
455   }
456
457   @Test
458   public void testGetVersionInfoForReadOnLockedOtherUser() {
459     Set<Version> viewableVersions = new HashSet<>();
460     viewableVersions.add(VERSION01);
461     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION01,
462         new UserCandidateVersion(USR2, VERSION02), viewableVersions, null);
463
464     VersionInfo versionInfo =
465         versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Read);
466     Assert.assertEquals(versionInfo.getActiveVersion(), VERSION01);
467     assertVersionInfo(versionInfo, VERSION01, VersionStatus.Locked, USR2, viewableVersions, null);
468   }
469
470   @Test(expectedExceptions = CoreException.class)
471   public void testGetVersionInfoForWriteOnLockedOtherUser() {
472     Set<Version> viewableVersions = new HashSet<>();
473     viewableVersions.add(VERSION01);
474     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION01,
475         new UserCandidateVersion(USR2, VERSION02), viewableVersions, null);
476
477     versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Write);
478   }
479
480   @Test
481   public void testGetVersionInfoForWriteOnLockedSameUser() {
482     Set<Version> viewableVersions = new HashSet<>();
483     viewableVersions.add(VERSION01);
484     mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Locked, VERSION01,
485         new UserCandidateVersion(USR1, VERSION02), viewableVersions, null);
486
487     VersionInfo versionInfo =
488         versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Write);
489     viewableVersions.add(VERSION02);
490     assertVersionInfo(versionInfo, VERSION02, VersionStatus.Locked, USR1, viewableVersions, null);
491   }
492
493 /*  private void createVersionableEntityRecord(String tableName, String idName, String versionName,
494                                              String id, Version version) {
495     noSqlDb.execute(
496         String.format("insert into %s (%s,%s) values (?,?)", tableName, idName, versionName), id,
497         versionMapper.toUDT(version));
498   }
499
500   private ResultSet loadVersionableEntityRecord(String tableName, String idName, String versionName,
501                                                 String id, Version version) {
502     return noSqlDb.execute(
503         String.format("select * from %s where %s=? and %s=?", tableName, idName, versionName), id,
504         versionMapper.toUDT(version));
505   }*/
506
507
508   private static void assretVersionInfoEntity(VersionInfoEntity actual, String entityType,
509                                               String entityId, Version activeVersion,
510                                               Version candidateVersion, String candidateUser,
511                                               VersionStatus status, Set<Version> viewbleVersions,
512                                               Version latestFinalVersion) {
513     Assert.assertNotNull(actual);
514     Assert.assertEquals(actual.getEntityType(), entityType);
515     Assert.assertEquals(actual.getEntityId(), entityId);
516     Assert.assertEquals(actual.getActiveVersion(), activeVersion);
517     if (candidateVersion != null && candidateUser != null) {
518       Assert.assertEquals(actual.getCandidate().getVersion(), candidateVersion);
519       Assert.assertEquals(actual.getCandidate().getUser(), candidateUser);
520     } else {
521       Assert.assertNull(actual.getCandidate());
522     }
523     Assert.assertEquals(actual.getStatus(), status);
524     Assert.assertEquals(actual.getViewableVersions().size(), viewbleVersions.size());
525     Assert.assertEquals(actual.getViewableVersions(), viewbleVersions);
526     Assert.assertEquals(actual.getLatestFinalVersion(), latestFinalVersion);
527   }
528
529   private static void assertVersionInfo(VersionInfo actual, Version activeVersion,
530                                         VersionStatus status, String lockingUser,
531                                         Set<Version> viewableVersions, Version latestFinalVersion) {
532     Assert.assertNotNull(actual);
533     Assert.assertEquals(actual.getActiveVersion(), activeVersion);
534     Assert.assertEquals(actual.getStatus(), status);
535     Assert.assertEquals(actual.getLockingUser(), lockingUser);
536     Assert.assertEquals(actual.getViewableVersions().size(), viewableVersions.size());
537     Assert.assertEquals(actual.getViewableVersions(), viewableVersions);
538     Assert.assertEquals(actual.getLatestFinalVersion(), latestFinalVersion);
539   }
540
541   private VersionInfoEntity mockVersionInfoEntity(String entityType, String entityId,
542                                                   VersionStatus status, Version activeVersion,
543                                                   UserCandidateVersion candidate,
544                                                   Set<Version> viewableVersions,
545                                                   Version latestFinalVersion) {
546     VersionInfoEntity mock = new VersionInfoEntity();
547     mock.setEntityType(entityType);
548     mock.setEntityId(entityId);
549     mock.setStatus(status);
550     mock.setActiveVersion(activeVersion);
551     mock.setCandidate(candidate);
552     mock.setViewableVersions(viewableVersions);
553     mock.setLatestFinalVersion(latestFinalVersion);
554
555     doReturn(mock).when(versionInfoDaoMock).get(anyObject());
556     return mock;
557   }
558 }