This project has retired. For details please refer to its Attic page.
CheckedOutTest xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.tck.tests.versioning;
20  
21  import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.FAILURE;
22  import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.WARNING;
23  
24  import java.util.Map;
25  
26  import org.apache.chemistry.opencmis.client.api.Document;
27  import org.apache.chemistry.opencmis.client.api.Folder;
28  import org.apache.chemistry.opencmis.client.api.ItemIterable;
29  import org.apache.chemistry.opencmis.client.api.ObjectId;
30  import org.apache.chemistry.opencmis.client.api.Session;
31  import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
32  import org.apache.chemistry.opencmis.tck.CmisTestResult;
33  import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
34  
35  /**
36   * Checked out test.
37   */
38  public class CheckedOutTest extends AbstractSessionTest {
39  
40      @Override
41      public void init(Map<String, String> parameters) {
42          super.init(parameters);
43          setName("Checked out Test");
44          setDescription("Calls getCheckedOutDocs() and checks the returned objects.");
45      }
46  
47      @Override
48      public void run(Session session) {
49          CmisTestResult f;
50  
51          Document pwc = null;
52          try {
53              // create folder and a checked-out document
54              Folder testFolder = createTestFolder(session);
55              Document doc = createDocument(session, testFolder, "checkedouttest.txt", "checked out");
56              DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
57  
58              if (!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              }
64  
65              // test all checked-out documents
66              int sessionCheckedOut = checkPWCs(session, session.getCheckedOutDocs(SELECT_ALL_NO_CACHE_OC_ORDER_BY_NAME));
67              addResult(createInfoResult(sessionCheckedOut + " checked out document(s) overall."));
68  
69              if (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              }
73  
74              // test checked-out documents in the test folder
75              int 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."));
78  
79              if (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              }
83  
84              // remove the PWC and document
85              if (pwc != null) {
86                  pwc.cancelCheckOut();
87                  pwc = null;
88              }
89              deleteObject(doc);
90          } finally {
91              if (pwc != null) {
92                  pwc.cancelCheckOut();
93              }
94              deleteTestFolder();
95          }
96      }
97  
98      private int checkPWCs(Session session, ItemIterable<Document> pwcs) {
99          if (pwcs == null) {
100             return 0;
101         }
102 
103         CmisTestResult f;
104 
105         int i = 0;
106         int orderByNameIssues = 0;
107         String lastName = null;
108 
109         for (Document pwc : pwcs) {
110             String[] propertiesToCheck = getAllProperties(pwc);
111             addResult(checkObject(session, pwc, propertiesToCheck, "PWC check: " + pwc.getId()));
112 
113             if (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));
119 
120                 if (lastName != null && pwc.getName() != null) {
121                     if (pwc.getName().compareToIgnoreCase(lastName) < 0) {
122                         orderByNameIssues++;
123                     }
124                 }
125 
126                 lastName = pwc.getName();
127             }
128 
129             i++;
130         }
131 
132         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));
135 
136         return i;
137     }
138 }