This project has retired. For details please refer to its
Attic page.
VersioningStateCreateTest 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;
23importstatic org.apache.chemistry.opencmis.tck.CmisTestResultStatus.WARNING;
2425import java.io.ByteArrayInputStream;
26import java.math.BigInteger;
27import java.util.HashMap;
28import java.util.List;
29import java.util.Map;
3031import org.apache.chemistry.opencmis.client.api.Document;
32import org.apache.chemistry.opencmis.client.api.Folder;
33import org.apache.chemistry.opencmis.client.api.Session;
34import org.apache.chemistry.opencmis.commons.PropertyIds;
35import org.apache.chemistry.opencmis.commons.data.ContentStream;
36import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
37import org.apache.chemistry.opencmis.commons.enums.VersioningState;
38import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
39import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
40import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
41import org.apache.chemistry.opencmis.tck.CmisTestResult;
42import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
4344publicclassVersioningStateCreateTestextendsAbstractSessionTest {
4546 @Override
47publicvoid init(Map<String, String> parameters) {
48super.init(parameters);
49 setName("Versioning State Create Test");
50 setDescription("Creates documents in different versioing states.");
51 }
5253 @Override
54publicvoid run(Session session) {
55CmisTestResult f;
5657try {
58// create folder and document59 Folder testFolder = createTestFolder(session);
6061 DocumentTypeDefinition docType = (DocumentTypeDefinition) session
62 .getTypeDefinition(getDocumentTestTypeId());
6364if (!docType.isVersionable()) {
65 addResult(createResult(SKIPPED, "Test type is not versionable. Test skipped!"));
66return;
67 }
6869// major version70 Document docMajor = testFolder.createDocument(getProperties("major.txt"), getContentStream(),
71 VersioningState.MAJOR, null, null, null, SELECT_ALL_NO_CACHE_OC);
72 addResult(checkObject(session, docMajor, getAllProperties(docMajor), "Major version compliance"));
7374 f = createResult(FAILURE, "Document should be major version.");
75 addResult(assertIsTrue(docMajor.isMajorVersion(), null, f));
7677 List<Document> versions = docMajor.getAllVersions();
7879 f = createResult(FAILURE, "Version series should have one version but has " + versions.size() + ".");
80 addResult(assertEquals(1, versions.size(), null, f));
8182 deleteObject(docMajor);
8384// minor version85try {
86 Document docMinor = testFolder.createDocument(getProperties("minor.txt"), getContentStream(),
87 VersioningState.MINOR, null, null, null, SELECT_ALL_NO_CACHE_OC);
88 addResult(checkObject(session, docMinor, getAllProperties(docMinor), "Minor version compliance"));
8990 f = createResult(FAILURE, "Document should be minor version.");
91 addResult(assertIsFalse(docMinor.isMajorVersion(), null, f));
9293 versions = docMinor.getAllVersions();
9495 f = createResult(FAILURE, "Version series should have one version but has " + versions.size() + ".");
96 addResult(assertEquals(1, versions.size(), null, f));
9798 deleteObject(docMinor);
99 } catch (CmisConstraintException ce) {
100 addResult(createResult(WARNING, "Creating a minor version failed! "101 + "The repository might not support minor versions. Exception: " + ce, ce, false));
102 } catch (CmisInvalidArgumentException iae) {
103 addResult(createResult(WARNING, "Creating a minor version failed! "104 + "The repository might not support minor versions. Exception: " + iae, iae, false));
105 }
106107// checked out version108try {
109 Document docCheckedOut = testFolder.createDocument(getProperties("checkout.txt"), getContentStream(),
110 VersioningState.CHECKEDOUT, null, null, null, SELECT_ALL_NO_CACHE_OC);
111 addResult(checkObject(session, docCheckedOut, getAllProperties(docCheckedOut),
112"Checked out version compliance"));
113114 f = createResult(FAILURE, "Version series should be checked out.");
115 addResult(assertIsTrue(docCheckedOut.isVersionSeriesCheckedOut(), null, f));
116117 versions = docCheckedOut.getAllVersions();
118119 f = createResult(FAILURE, "Version series should have one version but has " + versions.size() + ".");
120 addResult(assertEquals(1, versions.size(), null, f));
121122 docCheckedOut.cancelCheckOut();
123 } catch (CmisConstraintException ce) {
124 addResult(createResult(WARNING, "Creating a checked out version failed! "125 + "The repository might not support creating checked out versions. Exception: " + ce, ce, false));
126 } catch (CmisInvalidArgumentException iae) {
127 addResult(createResult(WARNING, "Creating a checked out version failed! "128 + "The repository might not support creating checked out versions. Exception: " + iae, iae,
129 false));
130 }
131132 } finally {
133 deleteTestFolder();
134 }
135 }
136137private Map<String, Object> getProperties(String name) {
138 Map<String, Object> properties = new HashMap<String, Object>();
139 properties.put(PropertyIds.NAME, name);
140 properties.put(PropertyIds.OBJECT_TYPE_ID, getDocumentTestTypeId());
141142return properties;
143 }
144145private ContentStream getContentStream() {
146 byte[] contentBytes = null;
147try {
148 contentBytes = "some content".getBytes("UTF-8");
149 } catch (Exception e) {
150 contentBytes = "some content".getBytes();
151 }
152153returnnew ContentStreamImpl("content.txt", BigInteger.valueOf(contentBytes.length), "text/plain",
154new ByteArrayInputStream(contentBytes));
155 }
156 }