This project has retired. For details please refer to its
Attic page.
VersioningTest xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.inmemory;
20
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertFalse;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26
27 import java.math.BigInteger;
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.LinkedList;
31 import java.util.List;
32 import java.util.Map;
33
34 import org.apache.chemistry.opencmis.commons.PropertyIds;
35 import org.apache.chemistry.opencmis.commons.data.ContentStream;
36 import org.apache.chemistry.opencmis.commons.data.ObjectData;
37 import org.apache.chemistry.opencmis.commons.data.ObjectList;
38 import org.apache.chemistry.opencmis.commons.data.Properties;
39 import org.apache.chemistry.opencmis.commons.data.PropertyBoolean;
40 import org.apache.chemistry.opencmis.commons.data.PropertyData;
41 import org.apache.chemistry.opencmis.commons.data.PropertyId;
42 import org.apache.chemistry.opencmis.commons.data.PropertyString;
43 import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
44 import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
45 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
46 import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
47 import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
48 import org.apache.chemistry.opencmis.commons.enums.Updatability;
49 import org.apache.chemistry.opencmis.commons.enums.VersioningState;
50 import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
51 import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
52 import org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException;
53 import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertyStringDefinitionImpl;
54 import org.apache.chemistry.opencmis.commons.server.CallContext;
55 import org.apache.chemistry.opencmis.commons.spi.Holder;
56 import org.apache.chemistry.opencmis.inmemory.types.InMemoryDocumentTypeDefinition;
57 import org.apache.chemistry.opencmis.inmemory.types.PropertyCreationHelper;
58 import org.apache.commons.logging.Log;
59 import org.apache.commons.logging.LogFactory;
60 import org.junit.After;
61 import org.junit.Before;
62 import org.junit.Test;
63
64 public class VersioningTest extends AbstractServiceTest {
65 private static final Log log = LogFactory.getLog(ObjectServiceTest.class);
66 private static final String PROP_VALUE = "Mickey Mouse";
67 private static final String PROP_VALUE_NEW = "Donald Duck";
68 private static final String PROP_NAME = "My Versioned Document";
69 private static final String TEST_USER = "TestUser";
70 private static final String TEST_USER_2 = "OtherUser";
71
72 ObjectCreator fCreator;
73
74 @Override
75 @Before
76 public void setUp() {
77 super.setTypeCreatorClass(VersionTestTypeSystemCreator.class.getName());
78 super.setUp();
79 fCreator = new ObjectCreator(fFactory, fObjSvc, fRepositoryId);
80 setRuntimeContext(TEST_USER);
81 }
82
83 @Override
84 @After
85 public void tearDown() {
86 super.tearDown();
87 }
88
89 private void setRuntimeContext(String user) {
90
91
92
93
94
95
96
97 ((DummyCallContext) fTestCallContext).put(CallContext.USERNAME, user);
98 }
99
100 @Test
101 public void testCreateVersionedDocumentMinor() {
102 createVersionedDocument(VersioningState.MINOR);
103 }
104
105 @Test
106 public void testCreateVersionedDocumentCheckedOut() {
107 createVersionedDocument(VersioningState.CHECKEDOUT);
108 }
109
110 @Test
111 public void testCreateVersionedDocumentNone() {
112 try {
113 createVersionedDocument(VersioningState.NONE);
114 fail("creating a document of a versionable type with state VersioningState.NONE should fail.");
115 } catch (Exception e) {
116 assertEquals(CmisConstraintException.class, e.getClass());
117 }
118 }
119
120 @Test
121 public void testCheckOutBasic() {
122 String verId = createDocument(PROP_NAME, fRootFolderId, VersioningState.MAJOR);
123
124 ObjectData version = fObjSvc.getObject(fRepositoryId, verId, "*", false, IncludeRelationships.NONE, null,
125 false, false, null);
126 String docId = getVersionSeriesId(verId, version.getProperties().getProperties());
127 assertTrue(null != docId && docId.length() > 0);
128
129 assertFalse(isCheckedOut(version.getProperties().getProperties()));
130
131 Holder<Boolean> contentCopied = new Holder<Boolean>();
132 Holder<String> idHolder = new Holder<String>(verId);
133
134
135 fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
136 String pwcId = idHolder.getValue();
137
138
139 Properties props = fObjSvc.getProperties(fRepositoryId, pwcId, "*", null);
140 String changeToken = (String) props.getProperties().get(PropertyIds.CHANGE_TOKEN).getFirstValue();
141 checkVersionProperties(pwcId, VersioningState.CHECKEDOUT, props.getProperties(), null);
142
143
144 try {
145 fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
146 fail("Checking out a document that is already checked-out should fail.");
147 } catch (Exception e) {
148 assertTrue(e instanceof CmisUpdateConflictException);
149 }
150
151
152 assertTrue(isCheckedOut(pwcId));
153
154
155 ContentStream altContent = fCreator.createAlternateContent();
156 idHolder = new Holder<String>(pwcId);
157 Holder<String> tokenHolder = new Holder<String>(changeToken);
158 fObjSvc.setContentStream(fRepositoryId, idHolder, true, tokenHolder, altContent, null);
159 fCreator.updateProperty(idHolder.getValue(), VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW);
160
161
162 String checkinComment = "Checkin without content and properties.";
163 fVerSvc.checkIn(fRepositoryId, idHolder, true, null, null, checkinComment, null, null, null, null);
164
165
166 assertFalse(isCheckedOut(idHolder.getValue()));
167
168 ContentStream retrievedContent = fObjSvc.getContentStream(fRepositoryId, idHolder.getValue(), null, BigInteger
169 .valueOf(-1)
170 assertTrue(fCreator.verifyContent(fCreator.createAlternateContent(), retrievedContent));
171 assertTrue(fCreator.verifyProperty(idHolder.getValue(), VersionTestTypeSystemCreator.PROPERTY_ID,
172 PROP_VALUE_NEW));
173
174 List<ObjectData> allVersions = fVerSvc.getAllVersions(fRepositoryId, docId, docId, "*", false, null);
175 assertEquals(2, allVersions.size());
176 }
177
178 @Test
179 public void testCheckInWithContent() {
180 String verId = createDocument(PROP_NAME, fRootFolderId, VersioningState.MAJOR);
181
182 ObjectData version = fObjSvc.getObject(fRepositoryId, verId, "*", false, IncludeRelationships.NONE, null,
183 false, false, null);
184 String docId = getVersionSeriesId(verId, version.getProperties().getProperties());
185 assertTrue(null != docId && docId.length() > 0);
186
187 assertFalse(isCheckedOut(version.getProperties().getProperties()));
188
189 Holder<Boolean> contentCopied = new Holder<Boolean>();
190 Holder<String> idHolder = new Holder<String>(verId);
191
192
193 fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
194 String pwcId = idHolder.getValue();
195
196 ContentStream altContent = fCreator.createAlternateContent();
197 Properties newProps = fCreator.getUpdatePropertyList(VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW);
198 idHolder = new Holder<String>(pwcId);
199
200 assertTrue(isCheckedOut(pwcId));
201
202
203 String checkinComment = "Checkin with content and properties.";
204 fVerSvc.checkIn(fRepositoryId, idHolder, true, newProps, altContent, checkinComment, null, null, null, null);
205
206
207 assertFalse(isCheckedOut(idHolder.getValue()));
208
209 ContentStream retrievedContent = fObjSvc.getContentStream(fRepositoryId, idHolder.getValue(), null, BigInteger
210 .valueOf(-1)
211
212
213 assertTrue(fCreator.verifyContent(fCreator.createAlternateContent(), retrievedContent));
214 assertTrue(fCreator.verifyProperty(idHolder.getValue(), VersionTestTypeSystemCreator.PROPERTY_ID,
215 PROP_VALUE_NEW));
216 }
217
218 @Test
219 public void testCheckOutAndOtherUser() {
220 String verId = createDocument(PROP_NAME, fRootFolderId, VersioningState.MAJOR);
221 ObjectData version = fObjSvc.getObject(fRepositoryId, verId, "*", false, IncludeRelationships.NONE, null,
222 false, false, null);
223 String docId = getVersionSeriesId(verId, version.getProperties().getProperties());
224 assertTrue(null != docId && docId.length() > 0);
225 assertFalse(isCheckedOut(version.getProperties().getProperties()));
226 Holder<Boolean> contentCopied = new Holder<Boolean>();
227 Holder<String> idHolder = new Holder<String>(verId);
228
229
230 fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
231 String pwcId = idHolder.getValue();
232
233
234 setRuntimeContext(TEST_USER_2);
235 try {
236 fVerSvc.checkIn(fRepositoryId, idHolder, true, null, null, "My Comment", null, null, null, null);
237 fail("Checking in a document as another user should fail.");
238 } catch (Exception e) {
239 assertTrue(e instanceof CmisUpdateConflictException);
240 }
241
242
243 try {
244 fVerSvc.cancelCheckOut(fRepositoryId, pwcId, null);
245 fail("Checking in a document as another user should fail.");
246 } catch (Exception e) {
247 assertTrue(e instanceof CmisUpdateConflictException);
248 }
249
250
251 try {
252 fCreator.updateProperty(pwcId, VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW);
253 fail("updateProperty in a document as another user should fail.");
254 } catch (Exception e) {
255 assertTrue(e instanceof CmisUpdateConflictException);
256 }
257
258 ContentStream altContent = fCreator.createAlternateContent();
259 Holder<String> pwcHolder = new Holder<String>(pwcId);
260 try {
261 fObjSvc.setContentStream(fRepositoryId, pwcHolder, true, null, altContent, null);
262 fail("setContentStream in a document as another user should fail.");
263 } catch (Exception e) {
264 assertTrue(e instanceof CmisUpdateConflictException);
265 }
266
267 setRuntimeContext(TEST_USER);
268
269 fVerSvc.checkIn(fRepositoryId, pwcHolder, true, null, null, "testCheckOutAndOtherUser", null, null, null, null);
270
271
272
273 ContentStream retrievedContent = fObjSvc.getContentStream(fRepositoryId, pwcHolder.getValue(), null, BigInteger
274 .valueOf(-1)
275 assertTrue(fCreator.verifyContent(retrievedContent, fCreator.createContent()));
276 assertTrue(fCreator.verifyProperty(idHolder.getValue(), VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE));
277 }
278
279 @Test
280 public void testCancelCheckout() {
281 String verId = createDocument(PROP_NAME, fRootFolderId, VersioningState.MAJOR);
282 ObjectData version = fObjSvc.getObject(fRepositoryId, verId, "*", false, IncludeRelationships.NONE, null,
283 false, false, null);
284 String idOfLastVersion = version.getId();
285 String docId = getVersionSeriesId(verId, version.getProperties().getProperties());
286 assertTrue(null != docId && docId.length() > 0);
287 assertFalse(isCheckedOut(version.getProperties().getProperties()));
288 Holder<Boolean> contentCopied = new Holder<Boolean>();
289 Holder<String> idHolder = new Holder<String>(verId);
290
291
292 fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
293 String pwcId = idHolder.getValue();
294
295
296 Properties props = fObjSvc.getProperties(fRepositoryId, pwcId, "*", null);
297 String changeToken = (String) props.getProperties().get(PropertyIds.CHANGE_TOKEN).getFirstValue();
298 ContentStream altContent = fCreator.createAlternateContent();
299 idHolder = new Holder<String>(pwcId);
300 Holder<String> tokenHolder = new Holder<String>(changeToken);
301 fObjSvc.setContentStream(fRepositoryId, idHolder, true, tokenHolder, altContent, null);
302 fCreator.updateProperty(idHolder.getValue(), VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW);
303
304
305 fVerSvc.cancelCheckOut(fRepositoryId, pwcId, null);
306 try {
307
308 fObjSvc.getObject(fRepositoryId, pwcId, "*", false, IncludeRelationships.NONE, null, false, false, null);
309 fail("Getting pwc after cancel checkout should fail.");
310 } catch (CmisObjectNotFoundException e1) {
311 } catch (Exception e2) {
312 fail("Expected a CmisObjectNotFoundException after cancel checkin, but got a " + e2.getClass().getName());
313 }
314
315
316 assertTrue(fCreator.verifyProperty(idOfLastVersion, VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE));
317 ContentStream retrievedContent = fObjSvc.getContentStream(fRepositoryId, idOfLastVersion, null, BigInteger
318 .valueOf(-1)
319 assertTrue(fCreator.verifyContent(retrievedContent, fCreator.createContent()));
320 }
321
322 @Test
323 public void testGetPropertiesOfLatestVersion() {
324 VersioningState versioningState = VersioningState.MAJOR;
325 String verId = createDocument(PROP_NAME, fRootFolderId, versioningState);
326 getDocument(verId);
327
328 ObjectData version = fObjSvc.getObject(fRepositoryId, verId, "*", false, IncludeRelationships.NONE, null,
329 false, false, null);
330 String docId = getVersionSeriesId(verId, version.getProperties().getProperties());
331 assertTrue(null != docId && docId.length() > 0);
332
333 Holder<Boolean> contentCopied = new Holder<Boolean>();
334 Holder<String> idHolder = new Holder<String>(verId);
335
336
337 fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
338 String pwcId = idHolder.getValue();
339
340 ContentStream altContent = fCreator.createAlternateContent();
341 Properties newProps = fCreator.getUpdatePropertyList(VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW);
342 idHolder = new Holder<String>(pwcId);
343
344 assertTrue(isCheckedOut(pwcId));
345
346
347 String checkinComment = "Checkin with content and properties.";
348 fVerSvc.checkIn(fRepositoryId, idHolder, true, newProps, altContent, checkinComment, null, null, null, null);
349
350 Properties latest = fVerSvc.getPropertiesOfLatestVersion(fRepositoryId, docId, docId, true, "*", null);
351 assertNotNull(latest);
352
353 checkVersionProperties(verId, versioningState, latest.getProperties(), checkinComment);
354 }
355
356 @Test
357 public void testGetLatestVersion() {
358 VersioningState versioningState = VersioningState.MINOR;
359 String verId = createDocument(PROP_NAME, fRootFolderId, versioningState);
360 getDocument(verId);
361
362 ObjectData version = fObjSvc.getObject(fRepositoryId, verId, "*", false, IncludeRelationships.NONE, null,
363 false, false, null);
364 String docId = getVersionSeriesId(verId, version.getProperties().getProperties());
365 assertTrue(null != docId && docId.length() > 0);
366
367 Holder<Boolean> contentCopied = new Holder<Boolean>();
368 Holder<String> idHolder = new Holder<String>(verId);
369
370
371 fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
372 String pwcId = idHolder.getValue();
373
374 ContentStream altContent = fCreator.createAlternateContent();
375 Properties newProps = fCreator.getUpdatePropertyList(VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW);
376 idHolder = new Holder<String>(pwcId);
377
378 assertTrue(isCheckedOut(pwcId));
379
380
381 String checkinComment = "Checkin with content and properties.";
382 fVerSvc.checkIn(fRepositoryId, idHolder, true, newProps, altContent, checkinComment, null, null, null, null);
383
384
385 versioningState = VersioningState.MAJOR;
386 boolean isMajor = true;
387 ObjectData objData = fVerSvc.getObjectOfLatestVersion(fRepositoryId, docId, docId, isMajor, "*", false,
388 IncludeRelationships.NONE, null, false, false, null);
389 checkVersionProperties(verId, versioningState, objData.getProperties().getProperties(), checkinComment);
390 ContentStream retrievedContent = fObjSvc.getContentStream(fRepositoryId, objData.getId(), null, BigInteger
391 .valueOf(-1)
392 assertTrue(fCreator.verifyContent(retrievedContent, fCreator.createAlternateContent()));
393
394
395 versioningState = VersioningState.MAJOR;
396 isMajor = false;
397 objData = fVerSvc.getObjectOfLatestVersion(fRepositoryId, docId, docId, isMajor, "*", false,
398 IncludeRelationships.NONE, null, false, false, null);
399 checkVersionProperties(verId, versioningState, objData.getProperties().getProperties(), checkinComment);
400 retrievedContent = fObjSvc.getContentStream(fRepositoryId, objData.getId(), null,
401 BigInteger.valueOf(-1)
402 assertTrue(fCreator.verifyContent(retrievedContent, fCreator.createAlternateContent()));
403 }
404
405 @Test
406 public void testGetCheckedOutDocuments() {
407
408
409 final int count = 2;
410 String[] folderIds = createLevel1Folders();
411 String[] verSeriesIds = new String[folderIds.length * count];
412 for (int i = 0; i < folderIds.length; i++) {
413 for (int j = 0; j < count; j++) {
414 String verId = createDocument("MyDoc" + j, folderIds[i], VersioningState.MAJOR);
415 ObjectData od = fObjSvc.getObject(fRepositoryId, verId, "*", false, IncludeRelationships.NONE, null,
416 false, false, null);
417 verSeriesIds[i * folderIds.length + j] = verId;
418 }
419 }
420
421 Holder<Boolean> contentCopied = new Holder<Boolean>();
422 Holder<String> idHolder = new Holder<String>(verSeriesIds[0]);
423 fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
424 idHolder = new Holder<String>(verSeriesIds[2]);
425 fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
426
427
428 ObjectList checkedOutDocuments = fNavSvc.getCheckedOutDocs(fRepositoryId, folderIds[0], "*", null, false,
429 IncludeRelationships.NONE, null, BigInteger.valueOf(-1), BigInteger.valueOf(-1), null);
430 assertEquals(1, checkedOutDocuments.getNumItems().longValue());
431 assertEquals(1, checkedOutDocuments.getObjects().size());
432
433
434 checkedOutDocuments = fNavSvc.getCheckedOutDocs(fRepositoryId, folderIds[1], "*", null, false,
435 IncludeRelationships.NONE, null, BigInteger.valueOf(-1), BigInteger.valueOf(-1), null);
436 assertEquals(1, checkedOutDocuments.getNumItems().longValue());
437 assertEquals(1, checkedOutDocuments.getObjects().size());
438
439
440 checkedOutDocuments = fNavSvc.getCheckedOutDocs(fRepositoryId, null, "*", null, false,
441 IncludeRelationships.NONE, null, BigInteger.valueOf(-1), BigInteger.valueOf(-1), null);
442 assertEquals(2, checkedOutDocuments.getNumItems().longValue());
443 assertEquals(2, checkedOutDocuments.getObjects().size());
444 }
445
446 @Test
447 public void testModifyOldVersions() {
448 String versionSeriesId = createVersionSeriesWithThreeVersions();
449 List<ObjectData> allVersions = fVerSvc.getAllVersions(fRepositoryId, null, versionSeriesId, "*", false, null);
450 assertEquals(3, allVersions.size());
451
452 }
453
454 private String[] createLevel1Folders() {
455 final int num = 2;
456 String[] res = new String[num];
457
458 for (int i = 0; i < num; i++) {
459 List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
460 properties.add(fFactory.createPropertyIdData(PropertyIds.NAME, "Folder " + i));
461 properties.add(fFactory.createPropertyIdData(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_FOLDER.value()));
462 Properties props = fFactory.createPropertiesData(properties);
463 String id = fObjSvc.createFolder(fRepositoryId, props, fRootFolderId, null, null, null, null);
464 res[i] = id;
465 }
466 return res;
467 }
468
469 private void createVersionedDocument(VersioningState versioningState) {
470
471
472 String verId = createDocument(PROP_NAME, fRootFolderId, versioningState);
473 getDocument(verId);
474
475 ObjectData version = fObjSvc.getObject(fRepositoryId, verId, "*", false, IncludeRelationships.NONE, null,
476 false, false, null);
477 String docId = getVersionSeriesId(verId, version.getProperties().getProperties());
478 assertTrue(null != docId && docId.length() > 0);
479
480 List<ObjectData> allVersions = fVerSvc.getAllVersions(fRepositoryId, docId, docId, "*", false, null);
481 assertEquals(1, allVersions.size());
482
483 checkVersionProperties(verId, versioningState, allVersions.get(0).getProperties().getProperties(), null);
484 }
485
486 private static String getVersionSeriesId(String docId, Map<String, PropertyData<?>> props) {
487 PropertyId pdid = (PropertyId) props.get(PropertyIds.VERSION_SERIES_ID);
488 assertNotNull(pdid);
489 String sVal = pdid.getFirstValue();
490 assertNotNull(sVal);
491 return sVal;
492 }
493
494 private boolean isCheckedOut(String objectId) {
495 Properties props = fObjSvc.getProperties(fRepositoryId, objectId, "*", null);
496 return isCheckedOut(props.getProperties());
497 }
498
499 private static boolean isCheckedOut(Map<String, PropertyData<?>> props) {
500 PropertyBoolean pdb = (PropertyBoolean) props.get(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT);
501 assertNotNull(pdb);
502 boolean bVal = pdb.getFirstValue();
503 return bVal;
504 }
505
506 private void checkVersionProperties(String docId, VersioningState versioningState,
507 Map<String, PropertyData<?>> props, String checkinComment) {
508 for (PropertyData<?> pd : props.values()) {
509 log.info("return property id: " + pd.getId() + ", value: " + pd.getValues());
510 }
511
512 DocumentTypeDefinition typeDef = (DocumentTypeDefinition) fRepSvc.getTypeDefinition(fRepositoryId,
513 VersionTestTypeSystemCreator.VERSION_TEST_DOCUMENT_TYPE_ID, null);
514 PropertyBoolean pdb = (PropertyBoolean) props.get(PropertyIds.IS_LATEST_VERSION);
515 assertNotNull(pdb);
516 boolean bVal = pdb.getFirstValue();
517 assertEquals(versioningState != VersioningState.CHECKEDOUT, bVal);
518
519
520 pdb = (PropertyBoolean) props.get(PropertyIds.IS_MAJOR_VERSION);
521 assertNotNull(pdb);
522 bVal = pdb.getFirstValue();
523 assertEquals(versioningState == VersioningState.MAJOR, bVal);
524
525 pdb = (PropertyBoolean) props.get(PropertyIds.IS_LATEST_MAJOR_VERSION);
526 assertNotNull(pdb);
527 bVal = pdb.getFirstValue();
528 assertEquals(versioningState == VersioningState.MAJOR, bVal);
529
530 PropertyId pdid = (PropertyId) props.get(PropertyIds.VERSION_SERIES_ID);
531 assertNotNull(pdid);
532 String sVal = pdid.getFirstValue();
533
534
535
536
537
538
539 pdb = (PropertyBoolean) props.get(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT);
540 assertNotNull(pdb);
541 bVal = pdb.getFirstValue();
542 assertEquals(versioningState == VersioningState.CHECKEDOUT, bVal);
543
544 PropertyString pds = (PropertyString) props.get(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY);
545 assertNotNull(pds);
546 sVal = pds.getFirstValue();
547 if (versioningState == VersioningState.CHECKEDOUT) {
548 assertTrue(sVal != null && sVal.length() > 0);
549 } else {
550 assertTrue(null == sVal || sVal.equals(""));
551 }
552
553 pdid = (PropertyId) props.get(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID);
554 assertNotNull(pdid);
555 sVal = pdid.getFirstValue();
556 if (versioningState == VersioningState.CHECKEDOUT) {
557 assertTrue(sVal != null && sVal.length() > 0);
558 } else {
559 assertTrue(null == sVal || sVal.equals(""));
560 }
561
562 pds = (PropertyString) props.get(PropertyIds.CHECKIN_COMMENT);
563 assertNotNull(pdb);
564 sVal = pds.getFirstValue();
565 if (checkinComment == null) {
566 assertTrue(null == sVal);
567 } else {
568 assertEquals(checkinComment, sVal);
569 }
570
571 }
572
573 @Override
574 public String getDocument(String id) {
575 String returnedId = null;
576 try {
577 ObjectData res = fObjSvc.getObject(fRepositoryId, id, "*", false, IncludeRelationships.NONE, null, false,
578 false, null);
579 assertNotNull(res);
580 testReturnedProperties(res.getProperties().getProperties());
581 returnedId = res.getId();
582 assertEquals(id, returnedId);
583 } catch (Exception e) {
584 fail("getObject() failed with exception: " + e);
585 }
586 return returnedId;
587 }
588
589 private static void testReturnedProperties(Map<String, PropertyData<?>> props) {
590 for (PropertyData<?> pd : props.values()) {
591 log.info("return property id: " + pd.getId() + ", value: " + pd.getValues());
592 }
593
594 PropertyData<?> pd = props.get(PropertyIds.NAME);
595 assertNotNull(pd);
596 assertEquals(PROP_NAME, pd.getFirstValue());
597 pd = props.get(PropertyIds.OBJECT_TYPE_ID);
598 assertEquals(VersionTestTypeSystemCreator.VERSION_TEST_DOCUMENT_TYPE_ID, pd.getFirstValue());
599 pd = props.get(VersionTestTypeSystemCreator.PROPERTY_ID);
600 assertEquals(PROP_VALUE, pd.getFirstValue());
601 }
602
603 private String createDocument(String name, String folderId, VersioningState versioningState) {
604
605 String id = null;
606 Map<String, String> properties = new HashMap<String, String>();
607 properties.put(VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE);
608 id = fCreator.createDocument(name, VersionTestTypeSystemCreator.VERSION_TEST_DOCUMENT_TYPE_ID, folderId,
609 versioningState, properties);
610
611 return id;
612 }
613
614 private String createVersionSeriesWithThreeVersions() {
615 String verIdV1 = createDocument(PROP_NAME, fRootFolderId, VersioningState.MAJOR);
616 getDocument(verIdV1);
617
618 ObjectData version = fObjSvc.getObject(fRepositoryId, verIdV1, "*", false, IncludeRelationships.NONE, null,
619 false, false, null);
620 String verSeriesId = getVersionSeriesId(verIdV1, version.getProperties().getProperties());
621
622
623 Holder<String> idHolder = new Holder<String>(verIdV1);
624 Holder<Boolean> contentCopied = new Holder<Boolean>(false);
625 fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
626
627 ContentStream content2 = createContent('a');
628 Properties newProps = fCreator.getUpdatePropertyList(VersionTestTypeSystemCreator.PROPERTY_ID,
629 "PropertyFromVersion2");
630 idHolder = new Holder<String>(verIdV1);
631
632 String checkinComment = "Checkin from Unit Test-2.";
633 fVerSvc.checkIn(fRepositoryId, idHolder, true, newProps, content2, checkinComment, null, null, null, null);
634 String verIdV2 = idHolder.getValue();
635
636
637 contentCopied = new Holder<Boolean>(false);
638 fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied);
639 ContentStream content3 = super.createContent('a');
640 newProps = fCreator.getUpdatePropertyList(VersionTestTypeSystemCreator.PROPERTY_ID, "PropertyFromVersion3");
641
642 checkinComment = "Checkin from Unit Test-3.";
643 fVerSvc.checkIn(fRepositoryId, idHolder, true, newProps, content3, checkinComment, null, null, null, null);
644
645
646
647
648
649 try {
650 fCreator.updateProperty(verIdV2, VersionTestTypeSystemCreator.PROPERTY_ID, "ChangeWithoutCheckout");
651 fail("updateProperty for an older version should fail.");
652 } catch (Exception e) {
653 assertTrue(e instanceof CmisUpdateConflictException);
654 }
655
656 ContentStream content4 = super.createContent('x');
657 idHolder = new Holder<String>(verIdV2);
658 try {
659 fObjSvc.setContentStream(fRepositoryId, idHolder, true, null, content4, null);
660 fail("setContentStream for an older version should fail.");
661 } catch (Exception e) {
662 assertTrue(e instanceof CmisUpdateConflictException);
663 }
664
665 return verSeriesId;
666 }
667
668 }