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.component.poly1;
018:
019: import org.compass.core.CompassSession;
020: import org.compass.core.CompassTransaction;
021: import org.compass.core.test.AbstractTestCase;
022:
023: /**
024: */
025: public class PolyComponentTest extends AbstractTestCase {
026:
027: protected String[] getMappings() {
028: return new String[] {
029: "component/poly1/WithPolyComponent.cpm.xml",
030: "component/poly1/WithoutPolyComponent.cpm.xml" };
031: }
032:
033: public void testNotNullComponentHavingInheritanceMappingCanBeIndexed() {
034:
035: Root root = new Poly("component text");
036: WithPolyComponent toIndex = new WithPolyComponent();
037: toIndex.setProperty("root text");
038: toIndex.setId(new Integer(1));
039: toIndex.setRoot(root);
040:
041: // save
042: CompassSession session = openSession();
043: CompassTransaction transaction = session.beginTransaction();
044: session.save(toIndex);
045: transaction.commit();
046: session.close();
047:
048: // fetch
049: session = openSession();
050: transaction = session.beginTransaction();
051:
052: WithPolyComponent retrieved = (WithPolyComponent) session.load(
053: WithPolyComponent.class, toIndex.getId());
054: transaction.commit();
055: session.close();
056:
057: assertEquals(retrieved, toIndex);
058: }
059:
060: public void testNullComponentHavingInheritanceMappingCanBeIndexed()
061: throws Exception {
062: WithPolyComponent toIndex = new WithPolyComponent();
063: toIndex.setProperty("root text");
064: toIndex.setId(new Integer(1));
065: toIndex.setRoot(null);
066:
067: // save
068: CompassSession session = openSession();
069: CompassTransaction transaction = session.beginTransaction();
070: session.create(toIndex);
071: transaction.commit();
072: session.close();
073:
074: // fetch
075: session = openSession();
076: transaction = session.beginTransaction();
077:
078: WithPolyComponent retrieved = (WithPolyComponent) session.load(
079: WithPolyComponent.class, toIndex.getId());
080: transaction.commit();
081: session.close();
082:
083: assertEquals(retrieved, toIndex);
084:
085: }
086:
087: public void testNotNullComponentWithoutInheritanceMappingCanBeIndexed() {
088:
089: SimpleComponent simpleComponent = new SimpleComponent();
090: simpleComponent.setComponentProperty("component text");
091:
092: WithoutPolyComponent toIndex = new WithoutPolyComponent();
093: toIndex.setId(new Integer(1));
094: toIndex.setProperty("text");
095: toIndex.setSimpleComponent(simpleComponent);
096:
097: // save
098: CompassSession session = openSession();
099: CompassTransaction transaction = session.beginTransaction();
100: session.create(toIndex);
101: transaction.commit();
102: session.close();
103:
104: // fetch
105: session = openSession();
106: transaction = session.beginTransaction();
107:
108: WithoutPolyComponent retrieved = (WithoutPolyComponent) session
109: .load(WithoutPolyComponent.class, toIndex.getId());
110: transaction.commit();
111: session.close();
112:
113: assertEquals(retrieved, toIndex);
114: }
115:
116: public void testNullComponentWithoutInheritanceMappingCanBeIndexed() {
117: WithoutPolyComponent toIndex = new WithoutPolyComponent();
118: toIndex.setId(new Integer(1));
119: // save
120: CompassSession session = openSession();
121: CompassTransaction transaction = session.beginTransaction();
122: session.create(toIndex);
123: transaction.commit();
124: session.close();
125:
126: // fetch
127: session = openSession();
128: transaction = session.beginTransaction();
129:
130: WithoutPolyComponent retrieved = (WithoutPolyComponent) session
131: .load(WithoutPolyComponent.class, toIndex.getId());
132: transaction.commit();
133: session.close();
134:
135: assertEquals(retrieved, toIndex);
136:
137: }
138:
139: }
|