KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > node > index > NodeIndexerTest


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.node.index;
18
19 import java.io.Serializable JavaDoc;
20 import java.util.List JavaDoc;
21
22 import org.alfresco.repo.node.BaseNodeServiceTest;
23 import org.alfresco.service.cmr.repository.NodeRef;
24 import org.alfresco.service.cmr.repository.NodeService;
25 import org.alfresco.service.cmr.repository.StoreRef;
26 import org.alfresco.service.cmr.search.ResultSet;
27 import org.alfresco.service.cmr.search.SearchService;
28 import org.alfresco.service.namespace.DynamicNamespacePrefixResolver;
29 import org.alfresco.service.namespace.NamespaceService;
30 import org.alfresco.util.perf.PerformanceMonitor;
31
32 /**
33  * Checks that the indexing of the node hierarchy is working
34  *
35  * @see org.alfresco.repo.node.index.NodeIndexer
36  *
37  * @author Derek Hulley
38  */

39 public class NodeIndexerTest extends BaseNodeServiceTest
40 {
41     private SearchService searchService;
42     private static StoreRef localStoreRef;
43     private static NodeRef localRootNode;
44
45     @Override JavaDoc
46     protected NodeService getNodeService()
47     {
48         return (NodeService) applicationContext.getBean("nodeService");
49     }
50     
51     @Override JavaDoc
52     protected void onSetUpInTransaction() throws Exception JavaDoc
53     {
54         super.onSetUpInTransaction();
55         searchService = (SearchService) applicationContext.getBean("searchService");
56
57         if (localStoreRef == null)
58         {
59             localStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_Persisted" + System.currentTimeMillis());
60             localRootNode = nodeService.getRootNode(localStoreRef);
61         }
62     }
63
64     public void testCommitQueryData() throws Exception JavaDoc
65     {
66         rootNodeRef = localRootNode;
67         buildNodeGraph();
68         setComplete();
69     }
70
71     public void testQuery() throws Exception JavaDoc
72     {
73         rootNodeRef = localRootNode;
74         ResultSet results = searchService.query(rootNodeRef.getStoreRef(), "lucene", "PATH:\"" + BaseNodeServiceTest.TEST_PREFIX + ":root_p_n1\"", null, null);
75         assertEquals(1, results.length());
76         results.close();
77     }
78
79     public void testLikeAndContains() throws Exception JavaDoc
80     {
81         rootNodeRef = localRootNode;
82         
83         DynamicNamespacePrefixResolver namespacePrefixResolver = new DynamicNamespacePrefixResolver(null);
84         namespacePrefixResolver.registerNamespace(NamespaceService.SYSTEM_MODEL_PREFIX, NamespaceService.SYSTEM_MODEL_1_0_URI);
85         namespacePrefixResolver.registerNamespace(NamespaceService.CONTENT_MODEL_PREFIX, NamespaceService.CONTENT_MODEL_1_0_URI);
86         namespacePrefixResolver.registerNamespace(BaseNodeServiceTest.TEST_PREFIX, BaseNodeServiceTest.NAMESPACE);
87    
88         PerformanceMonitor selectNodesPerf = new PerformanceMonitor(getClass().getSimpleName(), "selectNodes");
89         PerformanceMonitor selectPropertiesPerf = new PerformanceMonitor(getClass().getSimpleName(), "selectProperties");
90         
91         List JavaDoc<NodeRef> answer;
92         
93         selectNodesPerf.start();
94         answer = searchService.selectNodes(rootNodeRef, "//*[like(@test:animal, 'm_nkey')]", null, namespacePrefixResolver, false);
95         assertEquals(1, answer.size());
96         selectNodesPerf.stop();
97         
98         selectNodesPerf.start();
99         answer = searchService.selectNodes(rootNodeRef, "//*[like(@test:animal, 'm%key')]", null, namespacePrefixResolver, false);
100         assertEquals(1, answer.size());
101         selectNodesPerf.stop();
102         
103         selectNodesPerf.start();
104         answer = searchService.selectNodes(rootNodeRef, "//*[like(@test:animal, 'monk__')]", null, namespacePrefixResolver, false);
105         assertEquals(1, answer.size());
106         selectNodesPerf.stop();
107         
108         selectNodesPerf.start();
109         answer = searchService.selectNodes(rootNodeRef, "//*[like(@test:animal, 'monk%')]", null, namespacePrefixResolver, false);
110         assertEquals(1, answer.size());
111         selectNodesPerf.stop();
112         
113         selectNodesPerf.start();
114         answer = searchService.selectNodes(rootNodeRef, "//*[like(@test:animal, 'monk\\%')]", null, namespacePrefixResolver, false);
115         assertEquals(0, answer.size());
116         selectNodesPerf.stop();
117         
118         selectNodesPerf.start();
119         answer = searchService.selectNodes(rootNodeRef, "//*[contains('monkey')]", null, namespacePrefixResolver, false);
120         assertEquals(1, answer.size());
121         selectNodesPerf.stop();
122         
123         selectPropertiesPerf.start();
124         List JavaDoc<Serializable JavaDoc> result = searchService.selectProperties(rootNodeRef, "//@*[contains('monkey')]", null, namespacePrefixResolver, false);
125         assertEquals(2, result.size());
126         selectPropertiesPerf.stop();
127         
128         selectNodesPerf.start();
129         answer = searchService.selectNodes(rootNodeRef, "//*[contains('mon?ey')]", null, namespacePrefixResolver, false);
130         assertEquals(1, answer.size());
131         selectNodesPerf.stop();
132         
133         selectPropertiesPerf.start();
134         result = searchService.selectProperties(rootNodeRef, "//@*[contains('mon?ey')]", null, namespacePrefixResolver, false);
135         assertEquals(2, result.size());
136         selectPropertiesPerf.stop();
137         
138         selectNodesPerf.start();
139         answer = searchService.selectNodes(rootNodeRef, "//*[contains('m*y')]", null, namespacePrefixResolver, false);
140         assertEquals(1, answer.size());
141         selectNodesPerf.stop();
142         
143         selectPropertiesPerf.start();
144         result = searchService.selectProperties(rootNodeRef, "//@*[contains('mon*')]", null, namespacePrefixResolver, false);
145         assertEquals(2, result.size());
146         selectPropertiesPerf.stop();
147         
148         selectNodesPerf.start();
149         answer = searchService.selectNodes(rootNodeRef, "//*[contains('*nkey')]", null, namespacePrefixResolver, false);
150         assertEquals(1, answer.size());
151         selectNodesPerf.stop();
152         
153         selectPropertiesPerf.start();
154         result = searchService.selectProperties(rootNodeRef, "//@*[contains('?onkey')]", null, namespacePrefixResolver, false);
155         assertEquals(2, result.size());
156         selectPropertiesPerf.stop();
157     }
158 }
159
Popular Tags