@Test public void testCancelCheckout() { String verId = createDocument(PROP_NAME, fRootFolderId, VersioningState.MAJOR); ObjectData version = fObjSvc.getObject( fRepositoryId, verId, "*", false, IncludeRelationships.NONE, null, false, false, null); String idOfLastVersion = version.getId(); String docId = getVersionSeriesId(verId, version.getProperties().getProperties()); assertTrue(null != docId && docId.length() > 0); assertFalse(isCheckedOut(version.getProperties().getProperties())); Holder<Boolean> contentCopied = new Holder<Boolean>(); Holder<String> idHolder = new Holder<String>(verId); // or should this // be version // series? fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied); String pwcId = idHolder.getValue(); // Set a new content and modify property Properties props = fObjSvc.getProperties(fRepositoryId, pwcId, "*", null); String changeToken = (String) props.getProperties().get(PropertyIds.CHANGE_TOKEN).getFirstValue(); ContentStream altContent = fCreator.createAlternateContent(); idHolder = new Holder<String>(pwcId); Holder<String> tokenHolder = new Holder<String>(changeToken); fObjSvc.setContentStream(fRepositoryId, idHolder, true, tokenHolder, altContent, null); fCreator.updateProperty( idHolder.getValue(), VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW); // cancel checkout fVerSvc.cancelCheckOut(fRepositoryId, pwcId, null); try { // Verify that pwc no longer exists fObjSvc.getObject( fRepositoryId, pwcId, "*", false, IncludeRelationships.NONE, null, false, false, null); fail("Getting pwc after cancel checkout should fail."); } catch (CmisObjectNotFoundException e1) { } catch (Exception e2) { fail( "Expected a CmisObjectNotFoundException after cancel checkin, but got a " + e2.getClass().getName()); } // verify that the old content and properties are still valid assertTrue( fCreator.verifyProperty( idOfLastVersion, VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE)); ContentStream retrievedContent = fObjSvc.getContentStream( fRepositoryId, idOfLastVersion, null, BigInteger.valueOf(-1) /* offset */, BigInteger.valueOf(-1) /* length */, null); assertTrue(fCreator.verifyContent(retrievedContent, fCreator.createContent())); }
@Override public String getDocument(String id) { String returnedId = null; try { ObjectData res = fObjSvc.getObject( fRepositoryId, id, "*", false, IncludeRelationships.NONE, null, false, false, null); assertNotNull(res); testReturnedProperties(res.getProperties().getProperties()); returnedId = res.getId(); assertEquals(id, returnedId); } catch (Exception e) { fail("getObject() failed with exception: " + e); } return returnedId; }
@Test public void testGetLatestVersion() { VersioningState versioningState = VersioningState.MINOR; String verId = createDocument(PROP_NAME, fRootFolderId, versioningState); getDocument(verId); ObjectData version = fObjSvc.getObject( fRepositoryId, verId, "*", false, IncludeRelationships.NONE, null, false, false, null); String docId = getVersionSeriesId(verId, version.getProperties().getProperties()); assertTrue(null != docId && docId.length() > 0); Holder<Boolean> contentCopied = new Holder<Boolean>(); Holder<String> idHolder = new Holder<String>(verId); // or should this // be version // series? fVerSvc.checkOut(fRepositoryId, idHolder, null, contentCopied); String pwcId = idHolder.getValue(); ContentStream altContent = fCreator.createAlternateContent(); Properties newProps = fCreator.getUpdatePropertyList(VersionTestTypeSystemCreator.PROPERTY_ID, PROP_VALUE_NEW); idHolder = new Holder<String>(pwcId); // assertTrue(isCheckedOut(docId)); assertTrue(isCheckedOut(pwcId)); // Test check-in and pass content and properties String checkinComment = "Checkin with content and properties."; fVerSvc.checkIn( fRepositoryId, idHolder, true, newProps, altContent, checkinComment, null, null, null, null); // get latest major version versioningState = VersioningState.MAJOR; boolean isMajor = true; ObjectData objData = fVerSvc.getObjectOfLatestVersion( fRepositoryId, docId, docId, isMajor, "*", false, IncludeRelationships.NONE, null, false, false, null); checkVersionProperties( verId, versioningState, objData.getProperties().getProperties(), checkinComment); ContentStream retrievedContent = fObjSvc.getContentStream( fRepositoryId, objData.getId(), null, BigInteger.valueOf(-1) /* offset */, BigInteger.valueOf(-1) /* length */, null); assertTrue(fCreator.verifyContent(retrievedContent, fCreator.createAlternateContent())); // get latest non-major version, must be the same as before versioningState = VersioningState.MAJOR; isMajor = false; objData = fVerSvc.getObjectOfLatestVersion( fRepositoryId, docId, docId, isMajor, "*", false, IncludeRelationships.NONE, null, false, false, null); checkVersionProperties( verId, versioningState, objData.getProperties().getProperties(), checkinComment); retrievedContent = fObjSvc.getContentStream( fRepositoryId, objData.getId(), null, BigInteger.valueOf(-1) /* offset */, BigInteger.valueOf(-1) /* length */, null); assertTrue(fCreator.verifyContent(retrievedContent, fCreator.createAlternateContent())); }