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.boost.property;
18:
19: import org.compass.core.CompassHits;
20: import org.compass.core.CompassSession;
21: import org.compass.core.CompassTransaction;
22: import org.compass.core.test.AbstractTestCase;
23:
24: /**
25: * @author kimchy
26: */
27: public class BoostPropertyTests extends AbstractTestCase {
28:
29: protected String[] getMappings() {
30: return new String[] { "boost/property/boost.cpm.xml" };
31: }
32:
33: /**
34: * Verify the order when no boosting is done, so in the next test we are sure that
35: * the order is reversed when using boosting
36: */
37: public void testSimplePropertyNoBoost() {
38: CompassSession session = openSession();
39: CompassTransaction tr = session.beginTransaction();
40:
41: A a = new A();
42: a.id = 1;
43: a.value1 = new Float(1f);
44: a.value2 = "test";
45: session.save(a);
46: a = new A();
47: a.id = 2;
48: a.value1 = new Float(1f);
49: a.value2 = "test";
50: session.save(a);
51:
52: CompassHits hits = session.find("test");
53: assertEquals(1, ((A) hits.data(0)).id);
54: assertEquals(2, ((A) hits.data(1)).id);
55:
56: tr.commit();
57: session.close();
58: }
59:
60: public void testSimplePropertyBoost() {
61: CompassSession session = openSession();
62: CompassTransaction tr = session.beginTransaction();
63:
64: A a = new A();
65: a.id = 1;
66: a.value1 = new Float(1f);
67: a.value2 = "test";
68: session.save(a);
69: a = new A();
70: a.id = 2;
71: a.value1 = new Float(2f);
72: a.value2 = "test";
73: session.save(a);
74:
75: CompassHits hits = session.find("test");
76: // order is revered
77: assertEquals(2, ((A) hits.data(0)).id);
78: assertEquals(new Float(2f), ((A) hits.data(0)).value1);
79: assertEquals(1, ((A) hits.data(1)).id);
80: assertEquals(new Float(1f), ((A) hits.data(1)).value1);
81:
82: tr.commit();
83: session.close();
84: }
85: }
|