1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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.INFO;
23 import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.WARNING;
24
25 import java.util.Map;
26
27 import org.apache.chemistry.opencmis.client.api.Document;
28 import org.apache.chemistry.opencmis.client.api.Folder;
29 import org.apache.chemistry.opencmis.client.api.ItemIterable;
30 import org.apache.chemistry.opencmis.client.api.ObjectId;
31 import org.apache.chemistry.opencmis.client.api.OperationContext;
32 import org.apache.chemistry.opencmis.client.api.Session;
33 import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
34 import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
35 import org.apache.chemistry.opencmis.tck.CmisTestResult;
36 import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
37
38
39
40
41 public class CheckedOutTest extends AbstractSessionTest {
42
43 @Override
44 public void init(Map<String, String> parameters) {
45 super.init(parameters);
46 setName("Checked out Test");
47 setDescription("Calls getCheckedOutDocs() and checks the returned objects.");
48 }
49
50 @Override
51 public void run(Session session) {
52 CmisTestResult f;
53
54 boolean supportsOrderByName = isOrderByNameSupported(session);
55 OperationContext orderContext = (supportsOrderByName ? SELECT_ALL_NO_CACHE_OC_ORDER_BY_NAME
56 : SELECT_ALL_NO_CACHE_OC);
57
58 Document pwc = null;
59 try {
60
61 Folder testFolder = createTestFolder(session);
62 Document doc = createDocument(session, testFolder, "checkedouttest.txt", "checked out");
63 DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
64
65 if (!docType.isVersionable()) {
66 addResult(createResult(WARNING, "Test type is not versionable. Check out skipped!"));
67 } else {
68 ObjectId pwcId = doc.checkOut();
69 pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
70 }
71
72
73 int sessionCheckedOut = checkPWCs(session, session.getCheckedOutDocs(orderContext), supportsOrderByName);
74 addResult(createInfoResult(sessionCheckedOut + " checked out document(s) overall."));
75
76 if (pwc != null) {
77 f = createResult(FAILURE, "There should be at least one checked out document in the repository!");
78 addResult(assertIsTrue(sessionCheckedOut >= 1, null, f));
79 }
80
81
82 int testFolderCheckedOut = checkPWCs(session, testFolder.getCheckedOutDocs(orderContext),
83 supportsOrderByName);
84 addResult(createInfoResult(testFolderCheckedOut + " checked out document(s) in the test folder."));
85
86 if (pwc != null) {
87 f = createResult(FAILURE, "There should be at least one checked out document in the test folder!");
88 addResult(assertIsTrue(testFolderCheckedOut >= 1, null, f));
89 }
90
91
92 if (pwc != null) {
93 pwc.cancelCheckOut();
94 pwc = null;
95 }
96 deleteObject(doc);
97 } finally {
98 if (pwc != null) {
99 pwc.cancelCheckOut();
100 }
101 deleteTestFolder();
102 }
103 }
104
105 private int checkPWCs(Session session, ItemIterable<Document> pwcs, boolean checkOrder) {
106 if (pwcs == null) {
107 return 0;
108 }
109
110 CmisTestResult f;
111
112 int i = 0;
113 int orderByNameIssues = 0;
114 String lastName = null;
115
116 for (Document pwc : pwcs) {
117 if (pwc == null) {
118 addResult(createResult(FAILURE, "The list of checked out documents contains a null entry!"));
119 continue;
120 }
121
122 String[] propertiesToCheck = getAllProperties(pwc);
123 addResult(checkObject(session, pwc, propertiesToCheck, "PWC check: " + pwc.getId()));
124
125 if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_0) {
126 f = createResult(WARNING, "PWC is not the latest version! Id: " + pwc.getId()
127 + " (Note: The words of the CMIS specification define that the PWC is the latest version."
128 + " But that is not the intention of the spec and will be changed in CMIS 1.1."
129 + " Thus this a warning, not an error.)");
130 addResult(assertIsTrue(pwc.isLatestVersion(), null, f));
131 } else {
132 f = createResult(FAILURE,
133 "The property value of 'cmis:isLatestVersion' is TRUE for a PWC! Id: " + pwc.getId());
134 addResult(assertIsFalse(pwc.isLatestVersion(), null, f));
135 f = createResult(FAILURE, "The property value of 'cmis:isLatestMajorVersion' is TRUE for a PWC! Id: "
136 + pwc.getId());
137 addResult(assertIsFalse(pwc.isLatestMajorVersion(), null, f));
138 }
139
140 if (lastName != null && pwc.getName() != null) {
141 if (pwc.getName().compareToIgnoreCase(lastName) < 0) {
142 orderByNameIssues++;
143 }
144 }
145
146 lastName = pwc.getName();
147
148 i++;
149 }
150
151 if (checkOrder) {
152 f = createResult(WARNING,
153 "Checked-out documents should be ordered by cmis:name, but they are not! (It might be a collation mismatch.)");
154 addResult(assertEquals(0, orderByNameIssues, null, f));
155 } else {
156 addResult(createResult(INFO, "Repository doesn't support Order By for getCheckedOutDocs()."));
157 }
158
159 return i;
160 }
161 }