This project has retired. For details please refer to its
Attic page.
CheckedOutTest 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.WARNING;
2324import java.util.Map;
2526import org.apache.chemistry.opencmis.client.api.Document;
27import org.apache.chemistry.opencmis.client.api.Folder;
28import org.apache.chemistry.opencmis.client.api.ItemIterable;
29import org.apache.chemistry.opencmis.client.api.ObjectId;
30import org.apache.chemistry.opencmis.client.api.Session;
31import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
32import org.apache.chemistry.opencmis.tck.CmisTestResult;
33import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
3435/**36 * Checked out test.37 */38publicclassCheckedOutTestextendsAbstractSessionTest {
3940 @Override
41publicvoid init(Map<String, String> parameters) {
42super.init(parameters);
43 setName("Checked out Test");
44 setDescription("Calls getCheckedOutDocs() and checks the returned objects.");
45 }
4647 @Override
48publicvoid run(Session session) {
49CmisTestResult f;
5051 Document pwc = null;
52try {
53// create folder and a checked-out document54 Folder testFolder = createTestFolder(session);
55 Document doc = createDocument(session, testFolder, "checkedouttest.txt", "checked out");
56 DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
5758if (!docType.isVersionable()) {
59 addResult(createResult(WARNING, "Test type is not versionable. Check out skipped!"));
60 } else {
61 ObjectId pwcId = doc.checkOut();
62 pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
63 }
6465// test all checked-out documents66int sessionCheckedOut = checkPWCs(session, session.getCheckedOutDocs(SELECT_ALL_NO_CACHE_OC_ORDER_BY_NAME));
67 addResult(createInfoResult(sessionCheckedOut + " checked out document(s) overall."));
6869if (pwc != null) {
70 f = createResult(FAILURE, "There should be at least one checked out document in the repository!");
71 addResult(assertIsTrue(sessionCheckedOut >= 1, null, f));
72 }
7374// test checked-out documents in the test folder75int testFolderCheckedOut = checkPWCs(session,
76 testFolder.getCheckedOutDocs(SELECT_ALL_NO_CACHE_OC_ORDER_BY_NAME));
77 addResult(createInfoResult(testFolderCheckedOut + " checked out document(s) in the test folder."));
7879if (pwc != null) {
80 f = createResult(FAILURE, "There should be at least one checked out document in the test folder!");
81 addResult(assertIsTrue(testFolderCheckedOut >= 1, null, f));
82 }
8384// remove the PWC and document85if (pwc != null) {
86 pwc.cancelCheckOut();
87 pwc = null;
88 }
89 deleteObject(doc);
90 } finally {
91if (pwc != null) {
92 pwc.cancelCheckOut();
93 }
94 deleteTestFolder();
95 }
96 }
9798privateint checkPWCs(Session session, ItemIterable<Document> pwcs) {
99if (pwcs == null) {
100return 0;
101 }
102103CmisTestResult f;
104105int i = 0;
106int orderByNameIssues = 0;
107 String lastName = null;
108109for (Document pwc : pwcs) {
110 String[] propertiesToCheck = getAllProperties(pwc);
111 addResult(checkObject(session, pwc, propertiesToCheck, "PWC check: " + pwc.getId()));
112113if (pwc != null) {
114 f = createResult(WARNING, "PWC is not the latest version! Id: " + pwc.getId()
115 + " (Note: The words of the CMIS specification define that the PWC is the latest version."116 + " But that is not the intention of the spec and will be changed in CMIS 1.1."117 + " Thus this a warning, not an error.)");
118 addResult(assertIsTrue(pwc.isLatestVersion(), null, f));
119120if (lastName != null && pwc.getName() != null) {
121if (pwc.getName().compareToIgnoreCase(lastName) < 0) {
122 orderByNameIssues++;
123 }
124 }
125126 lastName = pwc.getName();
127 }
128129 i++;
130 }
131132 f = createResult(WARNING,
133"Checked-out documents should be ordered by cmis:name, but they are not! (It might be a collation mismatch.)");
134 addResult(assertEquals(0, orderByNameIssues, null, f));
135136return i;
137 }
138 }