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.converter;
018:
019: import org.compass.core.CompassSession;
020: import org.compass.core.CompassTransaction;
021: import org.compass.core.Resource;
022: import org.compass.core.config.CompassConfiguration;
023: import org.compass.core.config.CompassEnvironment;
024: import org.compass.core.config.CompassSettings;
025: import org.compass.core.test.AbstractTestCase;
026:
027: /**
028: * @author kimchy
029: */
030: public class ConverterTests extends AbstractTestCase {
031:
032: protected String[] getMappings() {
033: return new String[] { "converter/Converter.cpm.xml" };
034: }
035:
036: protected void addSettings(CompassSettings settings) {
037: settings.setGroupSettings(CompassEnvironment.Converter.PREFIX,
038: "sample",
039: new String[] { CompassEnvironment.Converter.TYPE,
040: "seperator" }, new String[] {
041: SampleConverter.class.getName(), "XXX1" });
042: }
043:
044: protected void addExtraConf(CompassConfiguration conf) {
045: SampleConverter sampleConverter = new SampleConverter();
046: sampleConverter.setSeperator("YYY");
047: conf.registerConverter("yyy", sampleConverter);
048: }
049:
050: /**
051: * Here we test the Sample Converter as one set using Compass Settings
052: */
053: public void testConverter() {
054: CompassSession session = openSession();
055: CompassTransaction tr = session.beginTransaction();
056:
057: Long id = new Long(1);
058: A o = new A();
059: o.setId(id);
060: A.TwoStringsValue tsv = new A.TwoStringsValue();
061: tsv.setValue1("test1");
062: tsv.setValue2("test2");
063: o.setValue(tsv);
064:
065: session.save("a", o);
066:
067: o = (A) session.load("a", id);
068: tsv = o.getValue();
069: assertEquals("test1", tsv.getValue1());
070: assertEquals("test2", tsv.getValue2());
071:
072: Resource resource = session.loadResource("a", id);
073: assertEquals("test1XXX1test2", resource.getValue("mvalue"));
074:
075: tr.commit();
076: }
077:
078: /**
079: * Here we test teh Sample Converter as one that was registered.
080: */
081: public void testConverterYYY() {
082: CompassSession session = openSession();
083: CompassTransaction tr = session.beginTransaction();
084:
085: Long id = new Long(1);
086: A o = new A();
087: o.setId(id);
088: A.TwoStringsValue tsv = new A.TwoStringsValue();
089: tsv.setValue1("test1");
090: tsv.setValue2("test2");
091: o.setValue(tsv);
092:
093: session.save("a1", o);
094:
095: o = (A) session.load("a1", id);
096: tsv = o.getValue();
097: assertEquals("test1", tsv.getValue1());
098: assertEquals("test2", tsv.getValue2());
099:
100: Resource resource = session.loadResource("a1", id);
101: assertEquals("test1YYYtest2", resource.getValue("mvalue"));
102:
103: tr.commit();
104: }
105: }
|