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.contract;
018:
019: import org.compass.core.CompassSession;
020: import org.compass.core.CompassTransaction;
021: import org.compass.core.Resource;
022: import org.compass.core.test.AbstractTestCase;
023:
024: /**
025: *
026: * @author kimchy
027: *
028: */
029: public class ContractTests extends AbstractTestCase {
030:
031: protected String[] getMappings() {
032: return new String[] { "contract/Contract.cpm.xml" };
033: }
034:
035: public void testContract() throws Exception {
036: CompassSession session = openSession();
037: CompassTransaction tr = session.beginTransaction();
038:
039: Long id = new Long(1);
040: A a = new A();
041: a.setId(id);
042: a.setValue1("value1");
043: a.setValue2("value2");
044: a.setValueA("valueA");
045:
046: session.save("a", a);
047:
048: Resource r = session.loadResource("a", id);
049: assertNotNull(r.getValue("mvalue1"));
050: assertNotNull(r.getValue("mvalue2"));
051: assertNotNull(r.getValue("mvalueA"));
052:
053: tr.commit();
054: session.close();
055: }
056:
057: public void testContractOverrideTrue() throws Exception {
058: CompassSession session = openSession();
059: CompassTransaction tr = session.beginTransaction();
060:
061: Long id = new Long(1);
062: A a = new A();
063: a.setId(id);
064: a.setValue1("value1");
065: a.setValue2("value2");
066: a.setValueA("valueA");
067:
068: session.save("a1", a);
069:
070: Resource r = session.loadResource("a1", id);
071: assertNull(r.getValue("mvalue1"));
072: assertNotNull(r.getValue("mvalue2"));
073: assertNotNull(r.getValue("mvalueEx"));
074:
075: tr.commit();
076: session.close();
077: }
078:
079: public void testContractOverrideFalse() throws Exception {
080: CompassSession session = openSession();
081: CompassTransaction tr = session.beginTransaction();
082:
083: Long id = new Long(1);
084: A a = new A();
085: a.setId(id);
086: a.setValue1("value1");
087: a.setValue2("value2");
088: a.setValueA("valueA");
089:
090: session.save("a2", a);
091:
092: Resource r = session.loadResource("a2", id);
093: assertNotNull(r.getValue("mvalue1"));
094: assertNotNull(r.getValue("mvalue2"));
095: assertNotNull(r.getValue("mvalueEx"));
096:
097: tr.commit();
098: session.close();
099: }
100: }
|