1 17 package org.alfresco.repo.node.index; 18 19 import java.io.Serializable ; 20 import java.util.List ; 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 39 public class NodeIndexerTest extends BaseNodeServiceTest 40 { 41 private SearchService searchService; 42 private static StoreRef localStoreRef; 43 private static NodeRef localRootNode; 44 45 @Override 46 protected NodeService getNodeService() 47 { 48 return (NodeService) applicationContext.getBean("nodeService"); 49 } 50 51 @Override 52 protected void onSetUpInTransaction() throws Exception 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 65 { 66 rootNodeRef = localRootNode; 67 buildNodeGraph(); 68 setComplete(); 69 } 70 71 public void testQuery() throws Exception 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 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 <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 <Serializable > 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 |