01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.lenya.cms.lucene;
19:
20: import org.apache.cocoon.components.search.Index;
21: import org.apache.cocoon.components.search.LuceneCocoonSearcher;
22: import org.apache.cocoon.components.search.components.IndexManager;
23: import org.apache.lenya.ac.impl.AbstractAccessControlTest;
24: import org.apache.lucene.index.Term;
25: import org.apache.lucene.search.Hits;
26: import org.apache.lucene.search.Query;
27: import org.apache.lucene.search.TermQuery;
28:
29: /**
30: * Test for search functionality.
31: */
32: public class SearchTest extends AbstractAccessControlTest {
33:
34: public void testSearch() throws Exception {
35: LuceneCocoonSearcher searcher = null;
36: IndexManager indexManager = null;
37: try {
38: searcher = (LuceneCocoonSearcher) getManager().lookup(
39: LuceneCocoonSearcher.ROLE);
40: indexManager = (IndexManager) getManager().lookup(
41: IndexManager.ROLE);
42: Index index = indexManager.getIndex("test-authoring");
43: searcher.setDirectory(index.getDirectory());
44:
45: Term term = new Term("body", "tutorial");
46: Query query = new TermQuery(term);
47:
48: Hits hits = searcher.search(query);
49:
50: /*
51: * The indexing doesn't work at the moment when the tests are executed because the
52: * cocoon:// protocol is not supported in the test environment.
53: *
54: * assertTrue(hits.length() > 0);
55: */
56:
57: } finally {
58: if (searcher != null) {
59: getManager().release(searcher);
60: }
61: if (indexManager != null) {
62: getManager().release(indexManager);
63: }
64: }
65: }
66:
67: }
|