001: /*
002: * Copyright 2004-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.compass.core.test.analyzer;
018:
019: import org.compass.core.CompassHits;
020: import org.compass.core.CompassSession;
021: import org.compass.core.CompassTransaction;
022: import org.compass.core.engine.SearchEngineException;
023:
024: /**
025: * @author kimchy
026: */
027: public class OsemAnalyzerTests extends AbstractAnalyzerTests {
028:
029: protected String[] getMappings() {
030: return new String[] { "analyzer/osem.cpm.xml" };
031: }
032:
033: public void testClassNoAnalyzer() {
034: CompassSession session = openSession();
035: CompassTransaction tr = session.beginTransaction();
036:
037: Long id = (long) 1;
038: A a = new A();
039: a.setId(id);
040: a.setValue(TEXT);
041: session.save("a1", a);
042:
043: CompassHits hits = session.find("a1.value:the");
044: assertEquals(0, hits.getLength());
045: // test for the all property as well
046: hits = session.find("the");
047: assertEquals(0, hits.getLength());
048:
049: tr.commit();
050: }
051:
052: public void testClassAnalyzerSetForResource() {
053: CompassSession session = openSession();
054: CompassTransaction tr = session.beginTransaction();
055:
056: Long id = (long) 1;
057: A a = new A();
058: a.setId(id);
059: a.setValue(TEXT);
060: session.save("a2", a);
061:
062: CompassHits hits = session.find("a2.value:the");
063: assertEquals(1, hits.getLength());
064: // test for the all property as well
065: hits = session.find("the");
066: assertEquals(1, hits.getLength());
067:
068: tr.commit();
069: }
070:
071: public void testClassAnalyzerSetForProperty() {
072: CompassSession session = openSession();
073: CompassTransaction tr = session.beginTransaction();
074:
075: Long id = (long) 1;
076: A a = new A();
077: a.setId(id);
078: a.setValue(TEXT);
079: a.setValue2(TEXT);
080: session.save("a3", a);
081:
082: CompassHits hits = session.find("a3.value:the");
083: assertEquals(1, hits.getLength());
084: hits = session.find("a3.value2:the");
085: assertEquals(0, hits.getLength());
086: // test for the all property as well
087: hits = session.find("the");
088: assertEquals(1, hits.getLength());
089:
090: tr.commit();
091: }
092:
093: public void testClassAnalyzerSetForResourceAndProperty() {
094: CompassSession session = openSession();
095: CompassTransaction tr = session.beginTransaction();
096:
097: Long id = (long) 1;
098: A a = new A();
099: a.setId(id);
100: a.setValue(TEXT);
101: a.setValue2(TEXT);
102: session.save("a4", a);
103:
104: CompassHits hits = session.find("a4.value:the");
105: assertEquals(0, hits.getLength());
106: hits = session.find("a4.value2:the");
107: assertEquals(1, hits.getLength());
108:
109: tr.commit();
110: }
111:
112: public void testClassAnalyzerController() {
113: CompassSession session = openSession();
114: CompassTransaction tr = session.beginTransaction();
115:
116: Long id = (long) 1;
117: A a = new A();
118: a.setId(id);
119: a.setValue(TEXT);
120: a.setValue2(TEXT);
121: a.setAnalyzer("simple");
122: session.save("a6", a);
123:
124: CompassHits hits = session.find("value:the");
125: assertEquals(1, hits.getLength());
126:
127: a = new A();
128: a.setId((long) 2);
129: a.setValue(TEXT);
130: a.setValue2(TEXT);
131: a.setAnalyzer(null);
132: try {
133: session.save("a6", a);
134: fail();
135: } catch (SearchEngineException e) {
136:
137: }
138:
139: tr.commit();
140: }
141:
142: public void testClassAnalyzerControllerWithNullAnalyzer() {
143: CompassSession session = openSession();
144: CompassTransaction tr = session.beginTransaction();
145:
146: Long id = (long) 1;
147: A a = new A();
148: a.setId(id);
149: a.setValue(TEXT);
150: a.setValue2(TEXT);
151: a.setAnalyzer("simple");
152: session.save("a7", a);
153:
154: CompassHits hits = session.find("value:the");
155: assertEquals(1, hits.getLength());
156:
157: a = new A();
158: a.setId((long) 2);
159: a.setValue(TEXT);
160: a.setValue2(TEXT);
161: a.setAnalyzer(null);
162: session.save("a7", a);
163: hits = session.find("value:the");
164: assertEquals(2, hits.getLength());
165:
166: tr.commit();
167: }
168: }
|