01: package org.compass.core.test.uid;
02:
03: import org.compass.core.CompassSession;
04: import org.compass.core.CompassTransaction;
05: import org.compass.core.Resource;
06: import org.compass.core.spi.InternalResource;
07: import org.compass.core.test.AbstractTestCase;
08:
09: /**
10: * @author kimchy
11: */
12: public class SimpleUIDTests extends AbstractTestCase {
13:
14: protected String[] getMappings() {
15: return new String[] { "uid/mapping.cpm.xml" };
16: }
17:
18: public void testSingleId() throws Exception {
19: CompassSession session = openSession();
20: CompassTransaction tr = session.beginTransaction();
21:
22: A a = new A();
23: a.id1 = 1;
24: a.id2 = 2;
25: session.save("a1", a);
26:
27: Resource resource = session.loadResource("a1", 1);
28: assertEquals("a1#1#", resource.getUID());
29: // also check that the actual id is stored in the resource
30: assertEquals("a1#1#", resource
31: .getValue(((InternalResource) resource).resourceKey()
32: .getResourceMapping().getUIDPath()));
33:
34: tr.commit();
35: session.close();
36: }
37:
38: public void testMultilpeId() throws Exception {
39: CompassSession session = openSession();
40: CompassTransaction tr = session.beginTransaction();
41:
42: A a = new A();
43: a.id1 = 1;
44: a.id2 = 2;
45: session.save("a2", a);
46:
47: Resource resource = session.loadResource("a2", 1, 2);
48: assertEquals("a2#1#2#", resource.getUID());
49: // also check that the actual id is stored in the resource
50: assertEquals("a2#1#2#", resource
51: .getValue(((InternalResource) resource).resourceKey()
52: .getResourceMapping().getUIDPath()));
53:
54: tr.commit();
55: session.close();
56: }
57: }
|