This project has retired. For details please refer to its Attic page.
DiscoveryServiceTest 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.inmemory;
20  
21  import static org.junit.Assert.assertEquals;
22  
23  import java.math.BigInteger;
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  import org.apache.chemistry.opencmis.commons.data.ObjectList;
28  import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
29  import org.apache.chemistry.opencmis.inmemory.ObjectServiceTest.ObjectTestTypeSystemCreator;
30  import org.apache.chemistry.opencmis.util.repository.ObjectGenerator;
31  import org.apache.commons.logging.Log;
32  import org.apache.commons.logging.LogFactory;
33  import org.junit.Before;
34  import org.junit.Test;
35  
36  public class DiscoveryServiceTest extends AbstractServiceTest {
37  
38      private static final Log log = LogFactory.getLog(DiscoveryServiceTest.class);
39      private static final String TEST_FOLDER_TYPE_ID = ObjectServiceTest.TEST_FOLDER_TYPE_ID;
40      private static final String TEST_DOCUMENT_TYPE_ID = ObjectServiceTest.TEST_DOCUMENT_TYPE_ID;
41      private static final String TEST_FOLDER_STRING_PROP_ID = ObjectServiceTest.TEST_FOLDER_STRING_PROP_ID;
42      private static final String TEST_DOCUMENT_STRING_PROP_ID = ObjectServiceTest.TEST_DOCUMENT_STRING_PROP_ID;
43  
44      @Override
45      @Before
46      public void setUp() {
47          super.setTypeCreatorClass(ObjectTestTypeSystemCreator.class.getName());
48          super.setUp();
49      }
50  
51      @Test
52      public void testQuery() {
53          log.info("starting testQuery() ...");
54  
55          ObjectGenerator gen = new ObjectGenerator(fFactory, fNavSvc, fObjSvc, fRepSvc, fRepositoryId, 
56                  ObjectGenerator.CONTENT_KIND.LoremIpsumText);
57          gen.setNumberOfDocumentsToCreatePerFolder(3);
58          gen.setDocumentTypeId(TEST_DOCUMENT_TYPE_ID);
59          gen.setFolderTypeId(TEST_FOLDER_TYPE_ID);
60  
61          List<String> propsToSet = new ArrayList<String>();
62          propsToSet.add(TEST_DOCUMENT_STRING_PROP_ID);
63          gen.setDocumentPropertiesToGenerate(propsToSet);
64  
65          propsToSet = new ArrayList<String>();
66          propsToSet.add(TEST_FOLDER_STRING_PROP_ID);
67          gen.setFolderPropertiesToGenerate(propsToSet);
68  
69          gen.createFolderHierachy(2, 2, fRootFolderId);
70  
71          Boolean searchAllVersions = Boolean.FALSE;
72          Boolean includeAllowableActions = Boolean.FALSE;
73          IncludeRelationships includeRelationships = IncludeRelationships.NONE;
74          String renditionFilter = null;
75          BigInteger maxItems = null;
76          BigInteger skipCount = null;
77  
78          String statement = "SELECT * FROM " + TEST_DOCUMENT_TYPE_ID + " WHERE " + TEST_DOCUMENT_STRING_PROP_ID + "='My Doc StringProperty 1'";
79          ObjectList res = fDiscSvc.query(fRepositoryId, statement, searchAllVersions, includeAllowableActions,
80                  includeRelationships, renditionFilter, maxItems, skipCount, null);
81          assertEquals(1, res.getObjects().size());
82  
83          statement = "SELECT " + TEST_DOCUMENT_STRING_PROP_ID + " FROM " + TEST_DOCUMENT_TYPE_ID + " WHERE " + TEST_DOCUMENT_STRING_PROP_ID + "='My Doc StringProperty 1'";
84          res = fDiscSvc.query(fRepositoryId, statement, searchAllVersions, includeAllowableActions,
85                  includeRelationships, renditionFilter, maxItems, skipCount, null);
86          assertEquals(1, res.getObjects().size());
87          assertEquals(1, res.getObjects().get(0).getProperties().getProperties().size()); // only one property should be delivered
88  
89          statement = "SELECT * FROM cmis:folder";
90          res = fDiscSvc.query(fRepositoryId, statement, searchAllVersions, includeAllowableActions,
91                  includeRelationships, renditionFilter, maxItems, skipCount, null);
92          // root + 2 at level 1 + 2*2 at level 2 = 7
93          assertEquals(7, res.getObjects().size());
94  
95  
96          /*
97          assertEquals(BigInteger.valueOf(9), res.getNumItems());
98  
99          statement = "SELECT * FROM cmis:folder";
100         res = fDiscSvc.query(fRepositoryId, statement, searchAllVersions, includeAllowableActions,
101                 includeRelationships, renditionFilter, maxItems, skipCount, null);
102         // root + 2 at level 1 + 2*2 at level 2 = 7
103         assertEquals(BigInteger.valueOf(7), res.getNumItems());
104 
105         statement = "SELECT * FROM cmis:folder";
106         res = fDiscSvc.query(fRepositoryId, statement, searchAllVersions, includeAllowableActions,
107                 includeRelationships, renditionFilter, maxItems, skipCount, null);
108         // root + 2 at level 1 + 2*2 at level 2 = 7
109         assertEquals(BigInteger.valueOf(7), res.getNumItems());
110 
111         statement = "SELECT * FROM cmis:folder WHERE name='Jens'";
112         res = fDiscSvc.query(fRepositoryId, statement, searchAllVersions, includeAllowableActions,
113                 includeRelationships, renditionFilter, maxItems, skipCount, null);
114         assertEquals(BigInteger.valueOf(0), res.getNumItems());
115 */
116         log.info("... testQuery() finished.");
117     }
118 
119     @Test
120     public void testQueryPaging() {
121         log.info("starting testQuery() ...");
122 
123         String statement;
124         ObjectList res;
125         ObjectGenerator gen = new ObjectGenerator(fFactory, fNavSvc, fObjSvc, fRepSvc, fRepositoryId,
126                 ObjectGenerator.CONTENT_KIND.LoremIpsumText);
127         gen.setNumberOfDocumentsToCreatePerFolder(3);
128         gen.setDocumentTypeId(TEST_DOCUMENT_TYPE_ID);
129         gen.setFolderTypeId(TEST_FOLDER_TYPE_ID);
130 
131         List<String> propsToSet = new ArrayList<String>();
132         propsToSet.add(TEST_DOCUMENT_STRING_PROP_ID);
133         gen.setDocumentPropertiesToGenerate(propsToSet);
134 
135         propsToSet = new ArrayList<String>();
136         propsToSet.add(TEST_FOLDER_STRING_PROP_ID);
137         gen.setFolderPropertiesToGenerate(propsToSet);
138 
139         gen.createFolderHierachy(2, 2, fRootFolderId);
140 
141         Boolean searchAllVersions = Boolean.FALSE;
142         Boolean includeAllowableActions = Boolean.FALSE;
143         IncludeRelationships includeRelationships = IncludeRelationships.NONE;
144         String renditionFilter = null;
145         BigInteger skipCount = BigInteger.valueOf(0);
146         BigInteger maxItems = BigInteger.valueOf(3);
147 
148         int count = 0;
149         boolean hasMoreItems = true;
150         statement = "SELECT * FROM cmis:document";
151         while (hasMoreItems) {
152             res = fDiscSvc.query(fRepositoryId, statement, searchAllVersions, includeAllowableActions,
153                     includeRelationships, renditionFilter, maxItems, skipCount, null);
154             hasMoreItems = res.hasMoreItems();
155             assertEquals(3, res.getObjects().size());
156             if (res.getNumItems() != null) {
157                 assertEquals(9L, res.getNumItems().longValue());
158             }
159             skipCount = skipCount.add(maxItems);
160             ++count;
161         }
162         assertEquals(3, count);
163     }
164 
165 }