You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2013/09/13 17:07:43 UTC
svn commit: r1522964 -
/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/ChangeTokenTest.java
Author: fmui
Date: Fri Sep 13 15:07:42 2013
New Revision: 1522964
URL: http://svn.apache.org/r1522964
Log:
CMIS-720: TCK: improved change token test
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/ChangeTokenTest.java
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/ChangeTokenTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/ChangeTokenTest.java?rev=1522964&r1=1522963&r2=1522964&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/ChangeTokenTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/ChangeTokenTest.java Fri Sep 13 15:07:42 2013
@@ -19,15 +19,18 @@
package org.apache.chemistry.opencmis.tck.tests.crud;
import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.FAILURE;
+import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.INFO;
import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.SKIPPED;
import java.io.ByteArrayInputStream;
import java.math.BigInteger;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.chemistry.opencmis.client.api.Document;
import org.apache.chemistry.opencmis.client.api.Folder;
+import org.apache.chemistry.opencmis.client.api.ObjectId;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.data.ContentStream;
@@ -86,17 +89,24 @@ public class ChangeTokenTest extends Abs
// the first update should succeed
Map<String, Object> properties2 = new HashMap<String, Object>();
properties2.put(PropertyIds.NAME, "update2.txt");
- doc.updateProperties(properties2, false);
+ ObjectId newId = doc.updateProperties(properties2, false);
- try {
- Map<String, Object> properties3 = new HashMap<String, Object>();
- properties3.put(PropertyIds.NAME, "update3.txt");
- doc.updateProperties(properties3, false);
-
- addResult(createResult(FAILURE, "Updating properties a second time with the same change token "
- + "should result in an UpdateConflict exception!"));
- } catch (CmisUpdateConflictException e) {
- // expected exception
+ if (!doc.getId().equals(newId.getId())) {
+ // the repository created a new version
+ // -> a change token test does not make sense
+ addResult(createResult(INFO,
+ "The repository created a new version. Change tokens are not relevant here."));
+ } else {
+ try {
+ Map<String, Object> properties3 = new HashMap<String, Object>();
+ properties3.put(PropertyIds.NAME, "update3.txt");
+ doc.updateProperties(properties3, false);
+
+ addResult(createResult(FAILURE, "Updating properties a second time with the same change token "
+ + "should result in an UpdateConflict exception!"));
+ } catch (CmisUpdateConflictException e) {
+ // expected exception
+ }
}
} finally {
deleteObject(doc);
@@ -126,15 +136,42 @@ public class ChangeTokenTest extends Abs
ContentStream contentStream = new ContentStreamImpl("content2.txt",
BigInteger.valueOf(contentBytes.length), "text/plain", new ByteArrayInputStream(contentBytes));
- doc.setContentStream(contentStream, true, false);
+ ObjectId newId = doc.setContentStream(contentStream, true, false);
- try {
- doc.setContentStream(contentStream, true, false);
-
- addResult(createResult(FAILURE, "Updating content a second time with the same change token "
- + "should result in an UpdateConflict exception!"));
- } catch (CmisUpdateConflictException e) {
- // expected exception
+ if (newId == null) {
+ // the AtomPub binding does not return an id here
+ // -> get the latest id from the version series
+ if (Boolean.TRUE.equals(((DocumentTypeDefinition) doc.getType()).isVersionable())) {
+ List<Document> versions = doc.getAllVersions();
+ if (versions == null || versions.size() < 1) {
+ addResult(createResult(FAILURE, "Repository returned an empty list of document versions!"));
+ } else {
+ // the latest document is at the top of the list
+ newId = versions.get(0);
+ }
+ } else {
+ // the document type is not versionable
+ // -> the repository couldn't create a new version
+ newId = doc;
+ }
+ }
+
+ if (newId != null) {
+ if (!doc.getId().equals(newId.getId())) {
+ // the repository created a new version
+ // -> a change token test does not make sense
+ addResult(createResult(INFO,
+ "The repository created a new version. Change tokens are not relevant here."));
+ } else {
+ try {
+ doc.setContentStream(contentStream, true, false);
+
+ addResult(createResult(FAILURE, "Updating content a second time with the same change token "
+ + "should result in an UpdateConflict exception!"));
+ } catch (CmisUpdateConflictException uce) {
+ // expected exception
+ }
+ }
}
} finally {
deleteObject(doc);