01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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:
17: package org.compass.core.test.spellcheck.properties;
18:
19: import org.compass.core.CompassSession;
20: import org.compass.core.CompassTransaction;
21: import org.compass.core.config.CompassSettings;
22: import org.compass.core.lucene.LuceneEnvironment;
23: import org.compass.core.test.AbstractTestCase;
24:
25: /**
26: * @author kimchy
27: */
28: public abstract class AbstractGlobalPropertiesSpellCheckTests extends
29: AbstractTestCase {
30:
31: protected String[] getMappings() {
32: return new String[] { "spellcheck/properties/mapping.cpm.xml" };
33: }
34:
35: protected void addSettings(CompassSettings settings) {
36: settings.setBooleanSetting(LuceneEnvironment.SpellCheck.ENABLE,
37: true);
38: settings.setBooleanSetting(
39: LuceneEnvironment.SpellCheck.SCHEDULE, false);
40: }
41:
42: public void testSimplePropertiesSpellCheck() {
43: CompassSession session = openSession();
44: CompassTransaction tr = session.beginTransaction();
45:
46: A a = new A();
47: a.id = 1;
48: a.value1 = "orange";
49: a.value2 = "black";
50: a.value3 = "white";
51: session.save("a1", a);
52:
53: tr.commit();
54: session.close();
55:
56: getCompass().getSpellCheckManager().concurrentRebuild();
57:
58: String[] suggestions = getCompass().getSpellCheckManager()
59: .suggestBuilder("orang").suggest().getSuggestions();
60: assertEquals(1, suggestions.length);
61: assertEquals("orange", suggestions[0]);
62:
63: suggestions = getCompass().getSpellCheckManager()
64: .suggestBuilder("blac").suggest().getSuggestions();
65: assertEquals(1, suggestions.length);
66: assertEquals("black", suggestions[0]);
67:
68: suggestions = getCompass().getSpellCheckManager()
69: .suggestBuilder("whit").suggest().getSuggestions();
70: assertEquals(0, suggestions.length);
71: }
72: }
|