This project has retired. For details please refer to its
Attic page.
QueryRootFolderTest xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19package org.apache.chemistry.opencmis.tck.tests.query;
2021importstatic org.apache.chemistry.opencmis.tck.CmisTestResultStatus.FAILURE;
22importstatic org.apache.chemistry.opencmis.tck.CmisTestResultStatus.SKIPPED;
2324import java.util.GregorianCalendar;
25import java.util.Map;
2627import org.apache.chemistry.opencmis.client.api.Folder;
28import org.apache.chemistry.opencmis.client.api.QueryResult;
29import org.apache.chemistry.opencmis.client.api.QueryStatement;
30import org.apache.chemistry.opencmis.client.api.Session;
31import org.apache.chemistry.opencmis.commons.PropertyIds;
32import org.apache.chemistry.opencmis.tck.CmisTestResult;
3334/**35 * Root folder query test.36 */37publicclassQueryRootFolderTestextendsAbstractQueryTest {
3839 @Override
40publicvoid init(Map<String, String> parameters) {
41super.init(parameters);
42 setName("Query Root Folder Test");
43 setDescription("Performs a query that should return the root folder name and id.");
44 }
4546 @Override
47publicvoid run(Session session) {
48if (supportsQuery(session)) {
49 queryById(session);
50 queryByDate(session);
51 } else {
52 addResult(createResult(SKIPPED, "Query not supported. Test Skipped!"));
53 }
54 }
5556protectedvoid queryById(Session session) {
57CmisTestResult f;
5859 String testType = "cmis:folder";
6061 Folder rootFolder = session.getRootFolder();
6263 QueryStatement statement = session
64 .createQueryStatement("SELECT ? AS folderName, ? AS folderId FROM ? WHERE ? = ?");
6566 statement.setProperty(1, testType, PropertyIds.NAME);
67 statement.setProperty(2, testType, PropertyIds.OBJECT_ID);
68 statement.setType(3, testType);
69 statement.setProperty(4, testType, PropertyIds.OBJECT_ID);
70 statement.setString(5, rootFolder.getId());
7172 addResult(createInfoResult("Query: " + statement.toQueryString()));
7374int count = 0;
75for (QueryResult qr : statement.query(false)) {
76 count++;
7778 String folderName = qr.getPropertyValueByQueryName("folderName");
79 String folderId = qr.getPropertyValueByQueryName("folderId");
8081 f = createResult(FAILURE, "Query result does not match root folder name!");
82 addResult(assertEquals(rootFolder.getName(), folderName, null, f));
8384 f = createResult(FAILURE, "Query result does not match root folder id!");
85 addResult(assertEquals(rootFolder.getId(), folderId, null, f));
86 }
8788 f = createResult(FAILURE, "The query should return exactly one result but returned " + count + "!");
89 addResult(assertEquals(1, count, null, f));
90 }
9192protectedvoid queryByDate(Session session) {
93CmisTestResult f;
9495 String testType = "cmis:folder";
9697 Folder rootFolder = session.getRootFolder();
9899 GregorianCalendar before = new GregorianCalendar();
100 before.setTimeInMillis(rootFolder.getCreationDate().getTimeInMillis() - (60 * 60 * 1000));
101102 GregorianCalendar after = new GregorianCalendar();
103 after.setTimeInMillis(rootFolder.getCreationDate().getTimeInMillis() + (60 * 60 * 1000));
104105 QueryStatement statement = session
106 .createQueryStatement("SELECT ? AS folderName, ? AS folderId FROM ? WHERE ? > TIMESTAMP ? AND ? < TIMESTAMP ?");
107108 statement.setProperty(1, testType, PropertyIds.NAME);
109 statement.setProperty(2, testType, PropertyIds.OBJECT_ID);
110 statement.setType(3, testType);
111 statement.setProperty(4, testType, PropertyIds.CREATION_DATE);
112 statement.setDateTime(5, before);
113 statement.setProperty(6, testType, PropertyIds.CREATION_DATE);
114 statement.setDateTime(7, after);
115116 addResult(createInfoResult("Query: " + statement.toQueryString()));
117118boolean found = false;
119for (QueryResult qr : statement.query(false)) {
120 String folderId = qr.getPropertyValueByQueryName("folderId");
121122if (rootFolder.getId().equals(folderId)) {
123 found = true;
124125 String folderName = qr.getPropertyValueByQueryName("folderName");
126127 f = createResult(FAILURE, "Query result does not match root folder name!");
128 addResult(assertEquals(rootFolder.getName(), folderName, null, f));
129break;
130 }
131 }
132133 f = createResult(FAILURE, "The query should return the root folder but does not!");
134 addResult(assertIsTrue(found, null, f));
135 }
136 }