chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1185656 - in /chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/versioning: VersionDeleteTest.java VersioningTestGroup.java
Date Tue, 18 Oct 2011 13:50:08 GMT
Author: fmui
Date: Tue Oct 18 13:50:07 2011
New Revision: 1185656

URL: http://svn.apache.org/viewvc?rev=1185656&view=rev
Log:
TCK: added version delete test

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/versioning/VersionDeleteTest.java
  (with props)
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/versioning/VersioningTestGroup.java

Added: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/versioning/VersionDeleteTest.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/versioning/VersionDeleteTest.java?rev=1185656&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/versioning/VersionDeleteTest.java
(added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/versioning/VersionDeleteTest.java
Tue Oct 18 13:50:07 2011
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.tck.tests.versioning;
+
+import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.FAILURE;
+import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.SKIPPED;
+
+import java.io.ByteArrayInputStream;
+import java.io.UnsupportedEncodingException;
+import java.math.BigInteger;
+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.data.ContentStream;
+import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
+import org.apache.chemistry.opencmis.tck.CmisTestResult;
+import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
+
+public class VersionDeleteTest extends AbstractSessionTest {
+
+    @Override
+    public void init(Map<String, String> parameters) {
+        super.init(parameters);
+        setName("Versioning Delete Test");
+        setDescription("Creates a document, adds three versions and deletes the current version
until the document is gone.");
+    }
+
+    @Override
+    public void run(Session session) {
+        try {
+            // create folder and document
+            Folder testFolder = createTestFolder(session);
+            Document doc = createDocument(session, testFolder, "versiondeletetest.txt", "v1");
+            DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
+
+            if (!docType.isVersionable()) {
+                addResult(createResult(SKIPPED, "Test type is not versionable. Test skipped!"));
+                doc.delete(true);
+                return;
+            }
+
+            // add versions
+            Document doc2 = createVersion(session, doc, "v2", 2);
+            Document doc3 = createVersion(session, doc2, "v3", 3);
+            Document doc4 = createVersion(session, doc3, "v4", 4);
+
+            // delete versions
+            deleteVersion(doc4, doc3, 4);
+            deleteVersion(doc3, doc2, 3);
+            deleteVersion(doc2, doc, 2);
+            deleteVersion(doc, null, 1);
+
+        } finally {
+            deleteTestFolder();
+        }
+    }
+
+    private Document createVersion(Session session, Document doc, String content, int version)
{
+        CmisTestResult f;
+
+        // check out
+        ObjectId pwcId = doc.checkOut();
+        Document pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
+
+        addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC " + version + " compliance"));
+
+        // check in
+        byte[] contentBytes;
+        try {
+            contentBytes = content.getBytes("UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            contentBytes = content.getBytes();
+        }
+        ContentStream contentStream = new ContentStreamImpl(doc.getName(), BigInteger.valueOf(contentBytes.length),
+                "text/plain", new ByteArrayInputStream(contentBytes));
+
+        ObjectId newVersionId = pwc.checkIn(true, null, contentStream, "test version " +
version);
+        Document newVersion = (Document) session.getObject(newVersionId, SELECT_ALL_NO_CACHE_OC);
+
+        addResult(checkObject(session, newVersion, getAllProperties(newVersion), "Version
" + version + " compliance"));
+
+        // check version history
+        List<Document> versions = doc.getAllVersions();
+
+        f = createResult(FAILURE, "Version series should have " + version + " versions but
has " + versions.size()
+                + "!");
+        addResult(assertEquals(version, versions.size(), null, f));
+
+        if (versions.size() > 0) {
+            f = createResult(FAILURE, "Newly created version " + version + " is not the latest
version!");
+            addResult(assertEquals(newVersion.getId(), versions.get(0).getId(), null, f));
+
+            if (versions.size() > 1) {
+                f = createResult(FAILURE, "The previous version of version " + version
+                        + " is not the document it has been created from!");
+                addResult(assertEquals(doc.getId(), versions.get(1).getId(), null, f));
+            }
+        }
+
+        return newVersion;
+    }
+
+    private void deleteVersion(Document versionDoc, Document perviousDoc, int version) {
+        CmisTestResult f;
+
+        // get version history before delete
+        List<Document> versionsBefore = versionDoc.getAllVersions();
+
+        // delete and check
+        versionDoc.delete(false);
+
+        f = createResult(FAILURE, "Deleted version " + version + " still exists!");
+        addResult(assertIsFalse(exists(versionDoc), null, f));
+
+        // check version history after delete
+        if (perviousDoc != null) {
+            List<Document> versionsAfter = perviousDoc.getAllVersions();
+
+            f = createResult(FAILURE, "After version " + version
+                    + " has been deleted, the version history should consist of " + (versionsBefore.size()
- 1)
+                    + "  documents but is has " + versionsAfter.size() + " !");
+            addResult(assertEquals(versionsBefore.size() - 1, versionsAfter.size(), null,
f));
+        }
+    }
+}

Propchange: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/versioning/VersionDeleteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/versioning/VersioningTestGroup.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/versioning/VersioningTestGroup.java?rev=1185656&r1=1185655&r2=1185656&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/versioning/VersioningTestGroup.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/versioning/VersioningTestGroup.java
Tue Oct 18 13:50:07 2011
@@ -34,6 +34,7 @@ public class VersioningTestGroup extends
         setDescription("Versioning tests.");
 
         addTest(new VersioningSmokeTest());
+        addTest(new VersionDeleteTest());
         addTest(new CheckedOutTest());
     }
 }



Mime
View raw message