This project has retired. For details please refer to its Attic page.
QueryLikeTest 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.query;
20  
21  import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.FAILURE;
22  import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.SKIPPED;
23  
24  import java.util.Map;
25  
26  import org.apache.chemistry.opencmis.client.api.CmisObject;
27  import org.apache.chemistry.opencmis.client.api.OperationContext;
28  import org.apache.chemistry.opencmis.client.api.Session;
29  import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
30  import org.apache.chemistry.opencmis.tck.CmisTestResult;
31  
32  public class QueryLikeTest extends AbstractQueryTest {
33  
34      @Override
35      public void init(Map<String, String> parameters) {
36          super.init(parameters);
37          setName("Query LIKE Test");
38          setDescription("Performs a query that should return the root folder name and id.");
39      }
40  
41      @Override
42      public void run(Session session) {
43          if (supportsQuery(session)) {
44  
45              OperationContext context = session.createOperationContext();
46              context.setFilterString("cmis:name,cmis:creationDate");
47              context.setCacheEnabled(false);
48              context.setIncludeAcls(false);
49              context.setIncludeAllowableActions(false);
50              context.setIncludePathSegments(false);
51              context.setIncludePolicies(false);
52              context.setIncludeRelationships(IncludeRelationships.NONE);
53              context.setRenditionFilterString("cmis:none");
54              context.setOrderBy("cmis:creationDate");
55  
56              CmisTestResult f;
57  
58              for (char c = 'a'; c <= 'z'; c++) {
59                  long timestamp = Long.MIN_VALUE;
60  
61                  for (CmisObject o : session
62                          .queryObjects("cmis:document", "cmis:name LIKE '" + c + "%'", false, context).getPage(10)) {
63  
64                      if (o.getName() == null) {
65                          addResult(createResult(
66                                  FAILURE,
67                                  "Documents without name should not be returned by this query! Document id: "
68                                          + o.getId()));
69                      } else {
70                          f = createResult(FAILURE,
71                                  "Document name should start with '" + c + "' but the name is '" + o.getName() + "'");
72                          addResult(assertIsTrue(o.getName().startsWith("" + c), null, f));
73                      }
74  
75                      if (o.getCreationDate() == null) {
76                          addResult(createResult(FAILURE,
77                                  "Found document without creation date! Document id: " + o.getId()));
78                      } else {
79                          f = createResult(FAILURE,
80                                  "Query results should be ordered by cmis:creationDate but they are not!");
81                          addResult(assertIsTrue(timestamp <= o.getCreationDate().getTimeInMillis(), null, f));
82  
83                          timestamp = o.getCreationDate().getTimeInMillis();
84                      }
85                  }
86              }
87  
88          } else {
89              addResult(createResult(SKIPPED, "Query not supported. Test Skipped!"));
90          }
91      }
92  }