01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.annotations.test.id;
18:
19: import org.compass.annotations.test.AbstractAnnotationsTestCase;
20: import org.compass.annotations.test.Converted;
21: import org.compass.core.CompassHits;
22: import org.compass.core.CompassSession;
23: import org.compass.core.CompassTransaction;
24: import org.compass.core.config.CompassConfiguration;
25: import org.compass.core.mapping.CompassMapping;
26: import org.compass.core.mapping.ResourcePropertyMapping;
27: import org.compass.core.mapping.osem.ClassIdPropertyMapping;
28: import org.compass.core.mapping.osem.ClassMapping;
29: import org.compass.core.spi.InternalCompassSession;
30:
31: /**
32: * @author kimchy
33: */
34: public class IdTests extends AbstractAnnotationsTestCase {
35:
36: protected void addExtraConf(CompassConfiguration conf) {
37: conf.addClass(A.class).addClass(B.class);
38: }
39:
40: public void testIdsPaths() throws Exception {
41:
42: InternalCompassSession session = (InternalCompassSession) openSession();
43:
44: CompassMapping mapping = session.getMapping();
45: ClassMapping AMApping = (ClassMapping) mapping
46: .getRootMappingByAlias("A");
47: ClassIdPropertyMapping[] idMappings = AMApping
48: .getClassIdPropertyMappings();
49: assertEquals(1, idMappings.length);
50: ResourcePropertyMapping[] resourcePropertyMappings = idMappings[0]
51: .getResourceIdMappings();
52: assertEquals(1, resourcePropertyMappings.length);
53: assertEquals("test", resourcePropertyMappings[0].getPath()
54: .getPath());
55: assertEquals("test", resourcePropertyMappings[0].getName());
56:
57: CompassTransaction tr = session.beginTransaction();
58:
59: A a = new A();
60: a.setId(1);
61: a.setValue("value");
62: session.save(a);
63:
64: a = session.load(A.class, 1);
65: assertEquals("value", a.getValue());
66:
67: CompassHits hits = session.find("value");
68: assertEquals(1, hits.length());
69:
70: tr.commit();
71: session.close();
72: }
73:
74: public void testConvertedId() {
75: CompassSession session = openSession();
76: CompassTransaction tr = session.beginTransaction();
77:
78: B b = new B();
79: b.id = new Converted("value1", "value2");
80:
81: session.save(b);
82:
83: session.load(B.class, b.id);
84:
85: tr.commit();
86: session.close();
87: }
88:
89: }
|