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.accessor;
018:
019: import org.compass.core.CompassSession;
020: import org.compass.core.CompassTransaction;
021: import org.compass.core.Resource;
022: import org.compass.core.accessor.DirectPropertyAccessor;
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 AccessorTests extends AbstractTestCase {
031:
032: protected String[] getMappings() {
033: return new String[] { "accessor/Accessor.cpm.xml" };
034: }
035:
036: protected void addSettings(CompassSettings settings) {
037: settings
038: .setGroupSettings(
039: CompassEnvironment.PropertyAccessor.PREFIX,
040: "myAccessor", new String[] { "type" },
041: new String[] { DirectPropertyAccessor.class
042: .getName() });
043: }
044:
045: public void testAccessor() {
046: CompassSession session = openSession();
047: CompassTransaction tr = session.beginTransaction();
048:
049: Long id = new Long(1);
050: A o = new A();
051: o.setId(id);
052: o.setPropertyValue("propVal");
053: o.packagePropertyValue = "packagePropVal";
054: o.privatePropertyValue = "privatePropVal";
055: o.protectedPropertyValue = "protectedPropVal";
056: o.updateFieldValue("fieldVal");
057: o.updateProtectedFieldValue("protectedFieldVal");
058: o.updatePublicFieldValue("publicFieldVal");
059: o.packageFieldValue = "packageFieldVal";
060: session.save(o);
061:
062: tr.commit();
063: session.close();
064:
065: session = openSession();
066: tr = session.beginTransaction();
067: o = (A) session.load(A.class, id);
068: assertEquals("propVal", o.getPropertyValue());
069: assertEquals("packagePropVal", o.packagePropertyValue);
070: assertEquals("privatePropVal", o.privatePropertyValue);
071: assertEquals("protectedPropVal", o.protectedPropertyValue);
072: assertEquals("fieldVal", o.checkFieldValue());
073: assertEquals("protectedFieldVal", o.checkProtectedFieldValue());
074: assertEquals("publicFieldVal", o.checkPublicFieldValue());
075: assertEquals("packageFieldVal", o.packageFieldValue);
076:
077: tr.commit();
078: session.close();
079: }
080:
081: public void testProtectedConstructor() {
082: CompassSession session = openSession();
083: CompassTransaction tr = session.beginTransaction();
084:
085: Long id = new Long(1);
086: B o = new B(id);
087: session.save(o);
088: tr.commit();
089: session.close();
090:
091: session = openSession();
092: tr = session.beginTransaction();
093: o = (B) session.load(B.class, id);
094: tr.commit();
095: session.close();
096: }
097:
098: public void testNoSetter() {
099: CompassSession session = openSession();
100: CompassTransaction tr = session.beginTransaction();
101:
102: Long id = new Long(1);
103: C o = new C(id);
104: o.setValue("value");
105: session.save("c", o);
106: tr.commit();
107: session.close();
108:
109: session = openSession();
110: tr = session.beginTransaction();
111:
112: o = (C) session.load("c", id);
113: Resource resource = session.loadResource("c", id);
114: assertEquals("value special", resource.getValue("special"));
115:
116: tr.commit();
117: session.close();
118: }
119:
120: public void testCustomPropertyAccessor() {
121: CompassSession session = openSession();
122: CompassTransaction tr = session.beginTransaction();
123:
124: Long id = new Long(1);
125: C c = new C(id);
126: c.setValue("value");
127: session.save("d", c);
128:
129: session.load("d", id);
130:
131: tr.commit();
132: session.close();
133: }
134: }
|