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.annotations.test.property;
018:
019: import java.util.ArrayList;
020:
021: import org.compass.annotations.test.AbstractAnnotationsTestCase;
022: import org.compass.annotations.test.Converted;
023: import org.compass.core.CompassHits;
024: import org.compass.core.CompassSession;
025: import org.compass.core.CompassTransaction;
026: import org.compass.core.config.CompassConfiguration;
027:
028: /**
029: * @author kimchy
030: */
031: public class PropertyTests extends AbstractAnnotationsTestCase {
032:
033: protected void addExtraConf(CompassConfiguration conf) {
034: conf.addClass(A.class).addClass(B.class);
035: }
036:
037: public void testCollectionWithGenericsParameter() {
038: CompassSession session = openSession();
039: CompassTransaction tr = session.beginTransaction();
040:
041: A a = new A();
042: a.id = 1;
043: ArrayList<String> values = new ArrayList<String>();
044: values.add("test1");
045: values.add("test2");
046: a.values = values;
047:
048: session.save(a);
049:
050: a = session.load(A.class, 1);
051: assertEquals(values, a.values);
052:
053: tr.commit();
054: session.close();
055:
056: session = openSession();
057: tr = session.beginTransaction();
058:
059: CompassHits hits = session.find("test1");
060: assertEquals(1, hits.length());
061: a = (A) hits.data(0);
062: assertEquals(1, a.id);
063: hits = session.find("test2");
064: assertEquals(1, hits.length());
065: a = (A) hits.data(0);
066: assertEquals(1, a.id);
067:
068: tr.commit();
069: session.close();
070: }
071:
072: public void testConvertedProperty() {
073: CompassSession session = openSession();
074: CompassTransaction tr = session.beginTransaction();
075:
076: B b = new B();
077: b.id = 1;
078: b.converted1 = new Converted("value1", "value2");
079: b.converted2 = new Converted("value3", "value4");
080:
081: ArrayList<Converted> convertedValues = new ArrayList<Converted>();
082: convertedValues.add(new Converted("value11", "value12"));
083: convertedValues.add(new Converted("value21", "value22"));
084:
085: b.convertedValues = convertedValues;
086: session.save(b);
087:
088: b = session.load(B.class, 1);
089: assertEquals("value1", b.converted1.value1);
090: assertEquals("value2", b.converted1.value2);
091: assertEquals("value3", b.converted2.value1);
092: assertEquals("value4", b.converted2.value2);
093:
094: assertEquals("value11", b.convertedValues.get(0).value1);
095: assertEquals("value12", b.convertedValues.get(0).value2);
096: assertEquals("value21", b.convertedValues.get(1).value1);
097: assertEquals("value22", b.convertedValues.get(1).value2);
098:
099: CompassHits hits = session.find("value1/value2");
100: assertEquals(1, hits.length());
101:
102: hits = session.find("value11/value12");
103: assertEquals(1, hits.length());
104:
105: hits = session.find("value21/value22");
106: assertEquals(1, hits.length());
107:
108: tr.commit();
109: session.close();
110: }
111:
112: }
|