View Javadoc

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.crud;
20  
21  import java.math.BigInteger;
22  import java.util.HashSet;
23  import java.util.List;
24  import java.util.Map;
25  import java.util.Set;
26  
27  import org.apache.chemistry.opencmis.client.api.CmisObject;
28  import org.apache.chemistry.opencmis.client.api.Document;
29  import org.apache.chemistry.opencmis.client.api.Folder;
30  import org.apache.chemistry.opencmis.client.api.OperationContext;
31  import org.apache.chemistry.opencmis.client.api.Property;
32  import org.apache.chemistry.opencmis.client.api.Session;
33  import org.apache.chemistry.opencmis.commons.data.ObjectData;
34  import org.apache.chemistry.opencmis.commons.data.ObjectInFolderData;
35  import org.apache.chemistry.opencmis.commons.data.ObjectInFolderList;
36  import org.apache.chemistry.opencmis.commons.data.ObjectParentData;
37  import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
38  import org.apache.chemistry.opencmis.tck.CmisTestResult;
39  import org.apache.chemistry.opencmis.tck.CmisTestResultStatus;
40  import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
41  
42  public class OperationContextTest extends AbstractSessionTest {
43  
44      private static final String CONTENT = "TCK test content.";
45  
46      @Override
47      public void init(Map<String, String> parameters) {
48          super.init(parameters);
49          setName("Operation Context");
50          setDescription("Creates a document, retrieves a minimal set of details, checks it, and finally deletes the document.");
51      }
52  
53      @Override
54      public void run(Session session) {
55  
56          // create a test folder
57          Folder testFolder = createTestFolder(session);
58  
59          try {
60              // create a test document
61              Document document = createDocument(session, testFolder, "testdoc.txt", CONTENT);
62  
63              // high-level API tests
64              runHighLevelApiTests(session, testFolder, document);
65  
66              // low-level API tests
67              runLowLevelApiTests(session, testFolder, document);
68  
69              // clean up
70              document.delete(true);
71          } finally {
72              // delete the test folder
73              deleteTestFolder();
74          }
75      }
76  
77      /**
78       * Checks for not requested properties, Allowable Actions, ACLs, renditions,
79       * relationships, and policies.
80       */
81      public void runHighLevelApiTests(Session session, Folder testFolder, Document testDocument) {
82          CmisTestResult f;
83  
84          // only select some base properties
85          Set<String> properties = new HashSet<String>();
86          properties.add("cmis:objectId");
87          properties.add("cmis:baseTypeId");
88          properties.add("cmis:objectTypeId");
89  
90          OperationContext context = session.createOperationContext();
91          context.setCacheEnabled(false);
92          context.setFilter(properties);
93          context.setIncludeAcls(false);
94          context.setIncludeAllowableActions(false);
95          context.setIncludePathSegments(false);
96          context.setIncludePolicies(false);
97          context.setIncludeRelationships(IncludeRelationships.NONE);
98          context.setLoadSecondaryTypeProperties(false);
99          context.setRenditionFilterString("cmis:none");
100 
101         // get the object with the OperationContext
102         Document doc1 = (Document) session.getObject(testDocument, context);
103 
104         // check properties
105         for (Property<?> prop : doc1.getProperties()) {
106             if (!properties.contains(prop.getDefinition().getQueryName())) {
107                 addResult(createResult(CmisTestResultStatus.WARNING,
108                         "getObject() delivered the property '" + prop.getId()
109                                 + "', although it has not been requested."));
110             }
111         }
112 
113         // check other details
114         f = createResult(CmisTestResultStatus.WARNING,
115                 "getObject() delivered ACLs, although they have not been requested.");
116         addResult(assertNull(doc1.getAcl(), null, f));
117 
118         f = createResult(CmisTestResultStatus.WARNING,
119                 "getObject() delivered Allowable Actions, although they have not been requested.");
120         addResult(assertNull(doc1.getAllowableActions(), null, f));
121 
122         f = createResult(CmisTestResultStatus.WARNING,
123                 "getObject() delivered policies, although they have not been requested.");
124         addResult(assertListNullOrEmpty(doc1.getPolicies(), null, f));
125 
126         f = createResult(CmisTestResultStatus.WARNING,
127                 "getObject() delivered relationships, although they have not been requested.");
128         addResult(assertListNullOrEmpty(doc1.getRelationships(), null, f));
129 
130         f = createResult(CmisTestResultStatus.WARNING,
131                 "getObject() delivered renditions, although they have not been requested.");
132         addResult(assertListNullOrEmpty(doc1.getRenditions(), null, f));
133 
134         // get the test folder children with the OperationContext
135         for (CmisObject child : testFolder.getChildren(context)) {
136             if (child.getId().equals(testDocument.getId())) {
137                 // check properties
138                 for (Property<?> prop : child.getProperties()) {
139                     if (!properties.contains(prop.getDefinition().getQueryName())) {
140                         addResult(createResult(CmisTestResultStatus.WARNING, "getChildren() delivered the property '"
141                                 + prop.getId() + "', although it has not been requested."));
142                     }
143                 }
144 
145                 // check other details
146                 f = createResult(CmisTestResultStatus.INFO, "getChildren() delivered ACLs, which is not required.");
147                 addResult(assertNull(child.getAcl(), null, f));
148 
149                 f = createResult(CmisTestResultStatus.WARNING,
150                         "getChildren() delivered Allowable Actions, although they have not been requested.");
151                 addResult(assertNull(child.getAllowableActions(), null, f));
152 
153                 f = createResult(CmisTestResultStatus.INFO, "getChildren() delivered policies, which is not required.");
154                 addResult(assertListNullOrEmpty(child.getPolicies(), null, f));
155 
156                 f = createResult(CmisTestResultStatus.WARNING,
157                         "getChildren() delivered relationships, although they have not been requested.");
158                 addResult(assertListNullOrEmpty(child.getRelationships(), null, f));
159 
160                 f = createResult(CmisTestResultStatus.WARNING,
161                         "getChildren() delivered renditions, although they have not been requested.");
162                 addResult(assertListNullOrEmpty(child.getRenditions(), null, f));
163 
164                 break;
165             }
166         }
167     }
168 
169     /**
170      * Checks for change events and path segments.
171      */
172     public void runLowLevelApiTests(Session session, Folder testFolder, Document testDocument) {
173         CmisTestResult f;
174 
175         String repositoryId = session.getRepositoryInfo().getId();
176         String filter = "cmis:objectId,cmis:baseTypeId,cmis:objectTypeId";
177 
178         // get the object
179         ObjectData doc1 = session
180                 .getBinding()
181                 .getObjectService()
182                 .getObject(repositoryId, testDocument.getId(), filter, Boolean.FALSE, IncludeRelationships.NONE,
183                         "cmis:none", Boolean.FALSE, Boolean.FALSE, null);
184 
185         // check for change events
186         f = createResult(CmisTestResultStatus.WARNING,
187                 "getObject() delivered a change event, which doesn't make sense.");
188         addResult(assertNull(doc1.getChangeEventInfo(), null, f));
189 
190         // get the test folder children
191         ObjectInFolderList children = session
192                 .getBinding()
193                 .getNavigationService()
194                 .getChildren(repositoryId, testFolder.getId(), filter, null, Boolean.FALSE, IncludeRelationships.NONE,
195                         "cmis:none", Boolean.FALSE, null, BigInteger.ZERO, null);
196 
197         // check for path segments
198         for (ObjectInFolderData child : children.getObjects()) {
199             f = createResult(CmisTestResultStatus.WARNING,
200                     "getChildren() delivered a path segment, although it hasn't been requested.");
201             addResult(assertNull(child.getPathSegment(), null, f));
202         }
203 
204         // get the document parent
205         List<ObjectParentData> parents = session
206                 .getBinding()
207                 .getNavigationService()
208                 .getObjectParents(repositoryId, testDocument.getId(), filter, Boolean.FALSE, IncludeRelationships.NONE,
209                         "cmis:none", Boolean.FALSE, null);
210 
211         // check for relative path segments
212         for (ObjectParentData parent : parents) {
213             f = createResult(CmisTestResultStatus.WARNING,
214                     "getObjectParents() delivered a relative path segment, although it hasn't been requested.");
215             addResult(assertNull(parent.getRelativePathSegment(), null, f));
216         }
217     }
218 }