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.engine;
018:
019: import junit.framework.TestCase;
020: import org.compass.core.Property;
021: import org.compass.core.Resource;
022: import org.compass.core.ResourceFactory;
023: import org.compass.core.config.CompassSettings;
024: import org.compass.core.engine.naming.StaticPropertyPath;
025: import org.compass.core.mapping.CompassMapping;
026: import org.compass.core.mapping.ResourceMapping;
027: import org.compass.core.mapping.ResourcePropertyMapping;
028: import org.compass.core.spi.InternalResource;
029:
030: /**
031: * @author kimchy
032: */
033: public abstract class AbstractEngineTests extends TestCase {
034:
035: public static final String PROPERTY_ID1 = "id1";
036:
037: public static final String PROPERTY_ID2 = "id2";
038:
039: public static final String PROPERTY_ID3 = "id3";
040:
041: public static final String VALUE_ID1 = "id1value";
042:
043: public static final String VALUE_ID2 = "id2value";
044:
045: public static final String VALUE_ID3 = "id3value";
046:
047: public static final String VALUE_ID1_2 = "id1value_2";
048:
049: public static final String VALUE_ID2_2 = "id2value_2";
050:
051: public static final String VALUE_ID3_2 = "id3value_2";
052:
053: public static final String PROPERTY_VAL1 = "val1";
054:
055: public static final String PROPERTY_VAL2 = "val2";
056:
057: public static final String PROPERTY_VAL3 = "val3";
058:
059: public static final String PROPERTY_VAL4 = "val4";
060:
061: public static final String VALUE_VAL1 = "val1value";
062:
063: public static final String VALUE_VAL2 = "val2value";
064:
065: public static final String VALUE_VAL3 = "val3value";
066:
067: public static final String VALUE_VAL4 = "val4value";
068:
069: public static final String ALIAS_SINGLE = "singleid";
070:
071: public static final String ALIAS_MUTLI = "multiid";
072:
073: private CompassSettings settings;
074:
075: private CompassMapping mapping;
076:
077: public CompassSettings getSettings() {
078: return settings;
079: }
080:
081: public CompassMapping getMapping() {
082: return this .mapping;
083: }
084:
085: protected CompassMapping buildCompassMapping() {
086: ResourcePropertyMapping id1 = new MockPropertyMapping(
087: PROPERTY_ID1, new StaticPropertyPath(PROPERTY_ID1));
088: ResourcePropertyMapping id2 = new MockPropertyMapping(
089: PROPERTY_ID2, new StaticPropertyPath(PROPERTY_ID2));
090: ResourcePropertyMapping id3 = new MockPropertyMapping(
091: PROPERTY_ID3, new StaticPropertyPath(PROPERTY_ID3));
092:
093: // PropertyMapping val1 = new MockPropertyMapping(PROPERTY_VAL1, PROPERTY_VAL1);
094: // PropertyMapping val2 = new MockPropertyMapping(PROPERTY_VAL2, PROPERTY_VAL2);
095: // PropertyMapping val3 = new MockPropertyMapping(PROPERTY_VAL3, PROPERTY_VAL3);
096: // PropertyMapping val4 = new MockPropertyMapping(PROPERTY_VAL4, PROPERTY_VAL4);
097:
098: ResourceMapping singleIdMapping = new MockResourceMapping(
099: ALIAS_SINGLE);
100: ((MockResourceMapping) singleIdMapping).addId(id1);
101:
102: ResourceMapping multipleIdMapping = new MockResourceMapping(
103: ALIAS_MUTLI);
104: ((MockResourceMapping) multipleIdMapping).addId(id2);
105: ((MockResourceMapping) multipleIdMapping).addId(id3);
106:
107: CompassMapping mapping = new CompassMapping();
108: mapping.addMapping(singleIdMapping);
109: mapping.addMapping(multipleIdMapping);
110:
111: return mapping;
112: }
113:
114: protected void setUp() throws Exception {
115: super .setUp();
116: buildCompassSettings();
117: mapping = buildCompassMapping();
118: }
119:
120: protected void tearDown() throws Exception {
121: super .tearDown();
122: }
123:
124: protected CompassSettings buildCompassSettings() {
125: settings = new CompassSettings();
126: return settings;
127: }
128:
129: protected Resource getSingleIdResource(SearchEngine searchEngine) {
130: return searchEngine.get(createSingleIdResource(searchEngine));
131: }
132:
133: protected void assertSingleIdResourceExists(
134: SearchEngine searchEngine) {
135: Resource r = getSingleIdResource(searchEngine);
136: assertNotNull("single resource id don't exists", r);
137: }
138:
139: protected Resource getSingleId2Resource(SearchEngine searchEngine) {
140: return searchEngine.get(createSingleIdResource2(searchEngine));
141: }
142:
143: protected void assertSingleId2ResourceExists(
144: SearchEngine searchEngine) {
145: Resource r = getSingleId2Resource(searchEngine);
146: assertNotNull("single resource id exists", r);
147: }
148:
149: protected Resource getMulitIdResource(SearchEngine searchEngine) {
150: return searchEngine.get(createMultiIdResource(searchEngine));
151: }
152:
153: protected void assertMulitIdResourceExists(SearchEngine searchEngine) {
154: Resource r = getMulitIdResource(searchEngine);
155: assertNotNull("multi resource id exists", r);
156: }
157:
158: protected Resource getMulitId2Resource(SearchEngine searchEngine) {
159: return searchEngine.get(createMultiIdResource2(searchEngine));
160: }
161:
162: protected void assertMulitId2ResourceExists(
163: SearchEngine searchEngine) {
164: Resource r = getMulitId2Resource(searchEngine);
165: assertNotNull("multi resource 2 id exists", r);
166: }
167:
168: protected void assertSingleIdResourceNotExists(
169: SearchEngine searchEngine) {
170: Resource r = getSingleIdResource(searchEngine);
171: assertNull("single resource id don't exists", r);
172: }
173:
174: protected void assertSingleId2ResourceNotExists(
175: SearchEngine searchEngine) {
176: Resource r = getSingleId2Resource(searchEngine);
177: assertNull("single resource id don't exists", r);
178: }
179:
180: protected void assertMulitIdResourceNotExists(
181: SearchEngine searchEngine) {
182: Resource r = getMulitIdResource(searchEngine);
183: assertNull("multi resource id don't exists", r);
184: }
185:
186: protected void assertMulitId2ResourceNotExists(
187: SearchEngine searchEngine) {
188: Resource r = getMulitId2Resource(searchEngine);
189: assertNull("multi resource id don't exists", r);
190: }
191:
192: protected Resource createSingleIdResource(SearchEngine searchEngine) {
193: ResourceFactory resourceFactory = searchEngine
194: .getSearchEngineFactory().getResourceFactory();
195: Resource singleId = resourceFactory
196: .createResource(ALIAS_SINGLE);
197: singleId.addProperty(resourceFactory.createProperty(
198: PROPERTY_ID1, VALUE_ID1, Property.Store.YES,
199: Property.Index.UN_TOKENIZED));
200: singleId.addProperty(resourceFactory.createProperty(
201: PROPERTY_VAL1, VALUE_VAL1, Property.Store.YES,
202: Property.Index.TOKENIZED));
203: singleId.addProperty(resourceFactory.createProperty(
204: PROPERTY_VAL4, VALUE_VAL4, Property.Store.YES,
205: Property.Index.TOKENIZED));
206: ((InternalResource) singleId).addUID();
207: return singleId;
208: }
209:
210: protected Resource createSingleIdResource2(SearchEngine searchEngine) {
211: ResourceFactory resourceFactory = searchEngine
212: .getSearchEngineFactory().getResourceFactory();
213: Resource singleId = resourceFactory
214: .createResource(ALIAS_SINGLE);
215: singleId.addProperty(resourceFactory.createProperty(
216: PROPERTY_ID1, VALUE_ID1_2, Property.Store.YES,
217: Property.Index.UN_TOKENIZED));
218: singleId.addProperty(resourceFactory.createProperty(
219: PROPERTY_VAL1, VALUE_VAL1, Property.Store.YES,
220: Property.Index.TOKENIZED));
221: singleId.addProperty(resourceFactory.createProperty(
222: PROPERTY_VAL4, VALUE_VAL4, Property.Store.YES,
223: Property.Index.TOKENIZED));
224: ((InternalResource) singleId).addUID();
225: return singleId;
226: }
227:
228: protected Resource createMultiIdResource(SearchEngine searchEngine) {
229: ResourceFactory resourceFactory = searchEngine
230: .getSearchEngineFactory().getResourceFactory();
231: Resource multiId = resourceFactory.createResource(ALIAS_MUTLI);
232: multiId.addProperty(resourceFactory.createProperty(
233: PROPERTY_ID2, VALUE_ID2, Property.Store.YES,
234: Property.Index.UN_TOKENIZED));
235: multiId.addProperty(resourceFactory.createProperty(
236: PROPERTY_ID3, VALUE_ID3, Property.Store.YES,
237: Property.Index.UN_TOKENIZED));
238: multiId.addProperty(resourceFactory.createProperty(
239: PROPERTY_VAL2, VALUE_VAL2, Property.Store.YES,
240: Property.Index.TOKENIZED));
241: multiId.addProperty(resourceFactory.createProperty(
242: PROPERTY_VAL3, VALUE_VAL3, Property.Store.YES,
243: Property.Index.TOKENIZED));
244: multiId.addProperty(resourceFactory.createProperty(
245: PROPERTY_VAL4, VALUE_VAL4, Property.Store.YES,
246: Property.Index.TOKENIZED));
247: ((InternalResource) multiId).addUID();
248: return multiId;
249: }
250:
251: protected Resource createMultiIdResource2(SearchEngine searchEngine) {
252: ResourceFactory resourceFactory = searchEngine
253: .getSearchEngineFactory().getResourceFactory();
254: Resource multiId = resourceFactory.createResource(ALIAS_MUTLI);
255: multiId.addProperty(resourceFactory.createProperty(
256: PROPERTY_ID2, VALUE_ID2_2, Property.Store.YES,
257: Property.Index.UN_TOKENIZED));
258: multiId.addProperty(resourceFactory.createProperty(
259: PROPERTY_ID3, VALUE_ID3_2, Property.Store.YES,
260: Property.Index.UN_TOKENIZED));
261: multiId.addProperty(resourceFactory.createProperty(
262: PROPERTY_VAL2, VALUE_VAL2, Property.Store.YES,
263: Property.Index.TOKENIZED));
264: multiId.addProperty(resourceFactory.createProperty(
265: PROPERTY_VAL3, VALUE_VAL3, Property.Store.YES,
266: Property.Index.TOKENIZED));
267: multiId.addProperty(resourceFactory.createProperty(
268: PROPERTY_VAL4, VALUE_VAL4, Property.Store.YES,
269: Property.Index.TOKENIZED));
270: ((InternalResource) multiId).addUID();
271: return multiId;
272: }
273:
274: }
|