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.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.Folder;
28 import org.apache.chemistry.opencmis.client.api.OperationContext;
29 import org.apache.chemistry.opencmis.client.api.Session;
30 import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
31 import org.apache.chemistry.opencmis.tck.CmisTestResult;
32
33
34
35
36 public class QueryLikeTest extends AbstractQueryTest {
37
38 private static final String CONTENT = "TCK test content.";
39 private static final int PAGE_SIZE = 10;
40
41 @Override
42 public void init(Map<String, String> parameters) {
43 super.init(parameters);
44 setName("Query LIKE Test");
45 setDescription("Performs a LIKE query and checks if only matching objects are returned.");
46 }
47
48 @Override
49 public void run(Session session) {
50 if (supportsQuery(session) && !isFulltextOnly(session)) {
51
52 Folder testFolder = createTestFolder(session);
53
54 try {
55 for (char c = 'a'; c <= 'z'; c++) {
56 createDocument(session, testFolder, c + "Document", CONTENT);
57 createFolder(session, testFolder, c + "Folder");
58 }
59
60 OperationContext context = session.createOperationContext();
61 context.setFilterString("cmis:name,cmis:creationDate");
62 context.setCacheEnabled(false);
63 context.setIncludeAcls(false);
64 context.setIncludeAllowableActions(false);
65 context.setIncludePathSegments(false);
66 context.setIncludePolicies(false);
67 context.setIncludeRelationships(IncludeRelationships.NONE);
68 context.setRenditionFilterString("cmis:none");
69 context.setOrderBy("cmis:creationDate");
70
71 CmisTestResult f;
72
73 for (char c = 'a'; c <= 'z'; c++) {
74
75 long timestamp = Long.MIN_VALUE;
76 long count = 0;
77
78 for (CmisObject o : session.queryObjects("cmis:document", "cmis:name LIKE '" + c + "%'", false,
79 context).getPage(PAGE_SIZE)) {
80
81 if (o.getName() == null || o.getName().length() == 0) {
82 addResult(createResult(
83 FAILURE,
84 "Documents without name should not be returned by this query! Document ID: "
85 + o.getId()));
86 } else {
87 f = createResult(FAILURE, "Document name should start with '" + c + "' but the name is '"
88 + o.getName() + "'.");
89 addResult(assertEquals(c, Character.toLowerCase(o.getName().charAt(0)), null, f));
90 }
91
92 if (o.getCreationDate() == null) {
93 addResult(createResult(FAILURE,
94 "Found document without creation date! Document ID: " + o.getId()));
95 } else {
96 f = createResult(FAILURE,
97 "Query results should be ordered by cmis:creationDate but they are not!");
98 addResult(assertIsTrue(timestamp <= o.getCreationDate().getTimeInMillis(), null, f));
99
100 timestamp = o.getCreationDate().getTimeInMillis();
101 }
102
103 count++;
104 }
105
106 f = createResult(FAILURE, "No documents starting with '" + c
107 + "' have been found, but there must be at least one!");
108 addResult(assertIsTrue(count > 0, null, f));
109
110 f = createResult(FAILURE, "A page of " + PAGE_SIZE
111 + " query hits has been requested, but the repository returned " + count + ".");
112 addResult(assertIsTrue(count <= PAGE_SIZE, null, f));
113
114
115 timestamp = Long.MIN_VALUE;
116 count = 0;
117
118 for (CmisObject o : session.queryObjects("cmis:folder", "cmis:name LIKE '" + c + "%'", false,
119 context).getPage(PAGE_SIZE)) {
120
121 if (o.getName() == null || o.getName().length() == 0) {
122 addResult(createResult(FAILURE,
123 "Folder without name should not be returned by this query! Folder ID: " + o.getId()));
124 } else {
125 f = createResult(FAILURE,
126 "Folder name should start with '" + c + "' but the name is '" + o.getName() + "'.");
127 addResult(assertEquals(c, Character.toLowerCase(o.getName().charAt(0)), null, f));
128 }
129
130 if (o.getCreationDate() == null) {
131 addResult(createResult(FAILURE,
132 "Found folder without creation date! Folder ID: " + o.getId()));
133 } else {
134 f = createResult(FAILURE,
135 "Query results should be ordered by cmis:creationDate but they are not!");
136 addResult(assertIsTrue(timestamp <= o.getCreationDate().getTimeInMillis(), null, f));
137
138 timestamp = o.getCreationDate().getTimeInMillis();
139 }
140
141 count++;
142 }
143
144 f = createResult(FAILURE, "No folders starting with '" + c
145 + "' have been found, but there must be at least one!");
146 addResult(assertIsTrue(count > 0, null, f));
147
148 f = createResult(FAILURE, "A page of " + PAGE_SIZE
149 + " query hits has been requested, but the repository returned " + count + ".");
150 addResult(assertIsTrue(count <= PAGE_SIZE, null, f));
151 }
152 } finally {
153
154 deleteTestFolder();
155 }
156 } else {
157 addResult(createResult(SKIPPED, "Metadata query not supported. Test Skipped!"));
158 }
159 }
160 }