01: package org.apache.lucene.search;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: import java.io.IOException;
21: import java.util.BitSet;
22:
23: import junit.framework.TestCase;
24:
25: import org.apache.lucene.index.IndexReader;
26:
27: /**
28: * A unit test helper class to help with RemoteCachingWrapperFilter testing and
29: * assert that it is working correctly.
30: * @author Matt Ericson
31: */
32: public class RemoteCachingWrapperFilterHelper extends
33: RemoteCachingWrapperFilter {
34:
35: private boolean shouldHaveCache;
36:
37: public RemoteCachingWrapperFilterHelper(Filter filter,
38: boolean shouldHaveCache) {
39: super (filter);
40: this .shouldHaveCache = shouldHaveCache;
41: }
42:
43: public void shouldHaveCache(boolean shouldHaveCache) {
44: this .shouldHaveCache = shouldHaveCache;
45: }
46:
47: public BitSet bits(IndexReader reader) throws IOException {
48: Filter cachedFilter = FilterManager.getInstance().getFilter(
49: filter);
50:
51: TestCase.assertNotNull("Filter should not be null",
52: cachedFilter);
53: if (!shouldHaveCache) {
54: TestCase.assertSame(
55: "First time filter should be the same ", filter,
56: cachedFilter);
57: } else {
58: TestCase.assertNotSame(
59: "We should have a cached version of the filter",
60: filter, cachedFilter);
61: }
62:
63: if (filter instanceof CachingWrapperFilterHelper) {
64: ((CachingWrapperFilterHelper) cachedFilter)
65: .setShouldHaveCache(shouldHaveCache);
66: }
67: return cachedFilter.bits(reader);
68: }
69: }
|