This project has retired. For details please refer to its
Attic page.
VersionDeleteTest xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19package org.apache.chemistry.opencmis.tck.tests.versioning;
2021importstatic org.apache.chemistry.opencmis.tck.CmisTestResultStatus.FAILURE;
22importstatic org.apache.chemistry.opencmis.tck.CmisTestResultStatus.SKIPPED;
2324import java.io.ByteArrayInputStream;
25import java.io.UnsupportedEncodingException;
26import java.math.BigInteger;
27import java.util.List;
28import java.util.Map;
2930import org.apache.chemistry.opencmis.client.api.Document;
31import org.apache.chemistry.opencmis.client.api.Folder;
32import org.apache.chemistry.opencmis.client.api.ObjectId;
33import org.apache.chemistry.opencmis.client.api.Session;
34import org.apache.chemistry.opencmis.commons.data.ContentStream;
35import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
36import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
37import org.apache.chemistry.opencmis.tck.CmisTestResult;
38import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
3940publicclassVersionDeleteTestextendsAbstractSessionTest {
4142 @Override
43publicvoid init(Map<String, String> parameters) {
44super.init(parameters);
45 setName("Versioning Delete Test");
46 setDescription("Creates a document, adds three versions and deletes the current version until the document is gone.");
47 }
4849 @Override
50publicvoid run(Session session) {
51try {
52// create folder and document53 Folder testFolder = createTestFolder(session);
54 Document doc = createDocument(session, testFolder, "versiondeletetest.txt", "v1");
55 DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
5657if (!docType.isVersionable()) {
58 addResult(createResult(SKIPPED, "Test type is not versionable. Test skipped!"));
59 doc.delete(true);
60return;
61 }
6263// add versions64 Document doc2 = createVersion(session, doc, "v2", 2);
65 Document doc3 = createVersion(session, doc2, "v3", 3);
66 Document doc4 = createVersion(session, doc3, "v4", 4);
6768// delete versions69 deleteVersion(doc4, doc3, 4);
70 deleteVersion(doc3, doc2, 3);
71 deleteVersion(doc2, doc, 2);
72 deleteVersion(doc, null, 1);
7374 } finally {
75 deleteTestFolder();
76 }
77 }
7879private Document createVersion(Session session, Document doc, String content, int version) {
80CmisTestResult f;
8182// check out83 ObjectId pwcId = doc.checkOut();
84 Document pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
8586 addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC " + version + " compliance"));
8788// check in89 byte[] contentBytes;
90try {
91 contentBytes = content.getBytes("UTF-8");
92 } catch (UnsupportedEncodingException e) {
93 contentBytes = content.getBytes();
94 }
95 ContentStream contentStream = new ContentStreamImpl(doc.getName(), BigInteger.valueOf(contentBytes.length),
96"text/plain", new ByteArrayInputStream(contentBytes));
9798 ObjectId newVersionId = pwc.checkIn(true, null, contentStream, "test version " + version);
99 Document newVersion = (Document) session.getObject(newVersionId, SELECT_ALL_NO_CACHE_OC);
100101 addResult(checkObject(session, newVersion, getAllProperties(newVersion), "Version " + version + " compliance"));
102103// check version history104 List<Document> versions = doc.getAllVersions();
105106 f = createResult(FAILURE, "Version series should have " + version + " versions but has " + versions.size()
107 + "!");
108 addResult(assertEquals(version, versions.size(), null, f));
109110if (versions.size() > 0) {
111 f = createResult(FAILURE, "Newly created version " + version + " is not the latest version!");
112 addResult(assertEquals(newVersion.getId(), versions.get(0).getId(), null, f));
113114if (versions.size() > 1) {
115 f = createResult(FAILURE, "The previous version of version " + version
116 + " is not the document it has been created from!");
117 addResult(assertEquals(doc.getId(), versions.get(1).getId(), null, f));
118 }
119 }
120121return newVersion;
122 }
123124privatevoid deleteVersion(Document versionDoc, Document previousDoc, int version) {
125CmisTestResult f;
126127// get version history before delete128 List<Document> versionsBefore = versionDoc.getAllVersions();
129130// delete and check131 versionDoc.delete(false);
132133 f = createResult(FAILURE, "Deleted version " + version + " still exists!");
134 addResult(assertIsFalse(exists(versionDoc), null, f));
135136// check version history after delete137if (previousDoc != null) {
138 List<Document> versionsAfter = previousDoc.getAllVersions();
139140 f = createResult(FAILURE, "After version " + version
141 + " has been deleted, the version history should consist of " + (versionsBefore.size() - 1)
142 + " documents but is has " + versionsAfter.size() + " !");
143 addResult(assertEquals(versionsBefore.size() - 1, versionsAfter.size(), null, f));
144 }
145 }
146 }