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.annotations.test.converter;
18:
19: import org.compass.annotations.test.AbstractAnnotationsTestCase;
20: import org.compass.annotations.test.Converted;
21: import org.compass.core.CompassHits;
22: import org.compass.core.CompassSession;
23: import org.compass.core.CompassTransaction;
24: import org.compass.core.Resource;
25: import org.compass.core.config.CompassConfiguration;
26:
27: /**
28: * @author kimchy
29: */
30: public class ConverterTests extends AbstractAnnotationsTestCase {
31:
32: protected void addExtraConf(CompassConfiguration conf) {
33: conf.addClass(A.class).addClass(B.class).addPackage(
34: "org.compass.annotations.test.converter");
35: }
36:
37: public void testCollectionWithGenericsParameter() {
38: CompassSession session = openSession();
39: CompassTransaction tr = session.beginTransaction();
40:
41: A a = new A();
42: a.id = new Converted("id1", "id2");
43: a.value = new Converted("value1", "value2");
44:
45: session.save(a);
46:
47: a = (A) session.load(A.class, a.id);
48: assertEquals("id1", a.id.value1);
49: assertEquals("id2", a.id.value2);
50: assertEquals("value1", a.value.value1);
51: assertEquals("value2", a.value.value2);
52:
53: Resource resource = session.loadResource(A.class, a.id);
54: assertEquals("id1#id2", resource.getValue("$/A/id"));
55: assertEquals("value1#value2", resource.getValue("value"));
56:
57: CompassHits hits = session.find("value1#value2");
58: assertEquals(1, hits.length());
59:
60: tr.commit();
61: session.close();
62: }
63:
64: public void testDoubleConverterBetween() {
65: CompassSession session = openSession();
66: CompassTransaction tr = session.beginTransaction();
67:
68: B b = new B();
69: b.id = 1;
70: b.value = 1001.456;
71: session.save(b);
72: b.id = 2;
73: b.value = 1594;
74: session.save(b);
75:
76: CompassHits hits = session.queryBuilder().between("value",
77: 1000.0, 2000.0, true).hits();
78: assertEquals(2, hits.length());
79:
80: tr.commit();
81: session.close();
82: }
83: }
|