KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > repository > test > AbstractFacetedQueryTest


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.repository.test;
17
18 import org.outerj.daisy.repository.testsupport.AbstractDaisyTestCase;
19 import org.outerj.daisy.repository.*;
20 import org.outerj.daisy.repository.schema.RepositorySchema;
21 import org.outerj.daisy.repository.schema.FieldType;
22 import org.outerj.daisy.repository.schema.DocumentType;
23 import org.outerj.daisy.repository.user.Role;
24 import org.outerj.daisy.repository.query.QueryManager;
25 import org.outerj.daisy.repository.query.FacetConf;
26 import org.outerx.daisy.x10.FacetedQueryResultDocument;
27
28 import java.util.Locale JavaDoc;
29
30 public abstract class AbstractFacetedQueryTest extends AbstractDaisyTestCase {
31     protected boolean resetDataStores() {
32         return true;
33     }
34
35     protected abstract RepositoryManager getRepositoryManager() throws Exception JavaDoc;
36
37     public void testFacetedQuery() throws Exception JavaDoc {
38         RepositoryManager repositoryManager = getRepositoryManager();
39         Repository repository = repositoryManager.getRepository(new Credentials("testuser", "testuser"));
40         repository.setActiveRoleIds(new long[] {Role.ADMINISTRATOR});
41
42         RepositorySchema schema = repository.getRepositorySchema();
43         FieldType fieldType1 = schema.createFieldType("testfield1", ValueType.STRING);
44         fieldType1.save();
45         FieldType fieldType2 = schema.createFieldType("testfield2", ValueType.STRING, true);
46         fieldType2.save();
47         DocumentType documentType = schema.createDocumentType("doctype");
48         documentType.addFieldType(fieldType1, false);
49         documentType.addFieldType(fieldType2, false);
50         documentType.save();
51
52         Document document1 = repository.createDocument("mydoc1", documentType.getId());
53         document1.setField("testfield1", "cow");
54         document1.setField("testfield2", new String JavaDoc[] {"blue", "black", "green"});
55         document1.save();
56
57         Document document2 = repository.createDocument("mydoc2", documentType.getId());
58         document2.setField("testfield1", "rabbit");
59         document2.setField("testfield2", new String JavaDoc[] {"blue", "purple", "green"});
60         document2.save();
61
62
63
64         QueryManager queryManager = repository.getQueryManager();
65         FacetConf[] facetConfs = new FacetConf[] {new FacetConf(), new FacetConf(), new FacetConf()};
66         FacetedQueryResultDocument result = queryManager.performFacetedQuery("select documentType, $testfield1, $testfield2 where true", facetConfs, 0, 10, Locale.US);
67         System.out.println(result);
68     }
69 }
70
Popular Tags