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.nounmarshall.component.simple2;
018:
019: import org.compass.core.CompassSession;
020: import org.compass.core.CompassTransaction;
021: import org.compass.core.Resource;
022: import org.compass.core.mapping.ResourceMapping;
023: import org.compass.core.mapping.ResourcePropertyMapping;
024: import org.compass.core.spi.InternalCompass;
025: import org.compass.core.test.AbstractTestCase;
026:
027: /**
028: * @author kimchy
029: */
030: public class SimpleNoUnmarshallComonentTests extends AbstractTestCase {
031:
032: protected String[] getMappings() {
033: return new String[] { "nounmarshall/component/simple2/mapping.cpm.xml" };
034: }
035:
036: public void testMappingsA() {
037: ResourceMapping aMapping = ((InternalCompass) getCompass())
038: .getMapping().getRootMappingByAlias("a");
039: ResourcePropertyMapping[] aPropertyMappings = aMapping
040: .getResourcePropertyMappings();
041: assertEquals(5, aPropertyMappings.length);
042: assertNotNull(aMapping.getResourcePropertyMapping("value"));
043: assertNotNull(aMapping.getResourcePropertyMapping("value2"));
044: assertNotNull(aMapping.getResourcePropertyMapping("id"));
045: }
046:
047: public void testBSingleValue() throws Exception {
048: CompassSession session = openSession();
049: CompassTransaction tr = session.beginTransaction();
050:
051: A a = new A();
052: a.id = 1;
053: a.value = "value";
054: B b = new B();
055: b.value = "bvalue";
056: a.b = b;
057: session.save("a", a);
058:
059: Resource resource = session.loadResource("a", new Long(1));
060: assertNotNull(resource);
061: assertEquals(5, resource.getProperties().length);
062: assertEquals("a", resource.getAlias());
063: assertEquals(2, resource.getProperties("value").length);
064:
065: // make sure no unmarshall returns A only with its ids set
066: a = (A) session.load("a", 1);
067: assertEquals(1, a.id);
068: assertNull(a.b);
069:
070: tr.commit();
071: session.close();
072: }
073:
074: public void testBwoValues() throws Exception {
075: CompassSession session = openSession();
076: CompassTransaction tr = session.beginTransaction();
077:
078: A a = new A();
079: a.id = 1;
080: a.value = "value";
081: B b = new B();
082: b.value = "bvalue";
083: b.value2 = "bvalue2";
084: a.b = b;
085: session.save("a", a);
086:
087: Resource resource = session.loadResource("a", new Long(1));
088: assertNotNull(resource);
089: assertEquals(7, resource.getProperties().length);
090: assertEquals("a", resource.getAlias());
091: assertEquals(3, resource.getProperties("value").length);
092:
093: // make sure no unmarshall returns A only with its ids set
094: a = (A) session.load("a", 1);
095: assertEquals(1, a.id);
096: assertNull(a.b);
097:
098: tr.commit();
099: session.close();
100: }
101: }
|