01: /*
02: * TestGetObjectsById.java
03: *
04: * Created on October 12, 2006, 10:49 AM
05: *
06: * To change this template, choose Tools | Template Manager
07: * and open the template in the editor.
08: */
09:
10: /*
11: * Licensed to the Apache Software Foundation (ASF) under one
12: * or more contributor license agreements. See the NOTICE file
13: * distributed with this work for additional information
14: * regarding copyright ownership. The ASF licenses this file
15: * to you under the Apache License, Version 2.0 (the
16: * "License"); you may not use this file except in compliance
17: * with the License. You may obtain a copy of the License at
18: *
19: * http://www.apache.org/licenses/LICENSE-2.0
20: *
21: * Unless required by applicable law or agreed to in writing,
22: * software distributed under the License is distributed on an
23: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
24: * KIND, either express or implied. See the License for the
25: * specific language governing permissions and limitations
26: * under the License.
27: */
28: package org.apache.openjpa.persistence.kernel;
29:
30: import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest4;
31: import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest5;
32:
33: import org.apache.openjpa.persistence.OpenJPAEntityManager;
34:
35: public class TestGetObjectsById extends BaseKernelTest {
36:
37: private Object[] oids;
38:
39: /**
40: * Creates a new instance of TestGetObjectsById
41: */
42: public TestGetObjectsById(String name) {
43: super (name);
44: }
45:
46: public void setUp() {
47: deleteAll(RuntimeTest5.class);
48: deleteAll(RuntimeTest4.class);
49:
50: RuntimeTest4 rt4 = new RuntimeTest4("foo");
51:
52: RuntimeTest5 related0 = new RuntimeTest5("bar");
53: related0.setRuntimeTest4(rt4);
54: rt4.getRuntimeTest5s().add(related0);
55:
56: RuntimeTest5 related1 = new RuntimeTest5("baz");
57: related1.setRuntimeTest4(rt4);
58: rt4.getRuntimeTest5s().add(related1);
59:
60: OpenJPAEntityManager pm = getPM();
61: startTx(pm);
62: pm.persist(rt4);
63: endTx(pm);
64: oids = new Object[] { pm.getObjectId(rt4),
65: pm.getObjectId(related0), pm.getObjectId(related1), };
66: endEm(pm);
67: }
68:
69: public void testGetObjectsByIdInvocation() {
70: OpenJPAEntityManager pm = getPM();
71: try {
72: Object[] pcs = pm.findAll(Object.class, oids);
73: assertEquals(oids.length, pcs.length);
74: for (int i = 0; i < oids.length; i++)
75: assertEquals(oids[i], pm.getObjectId(pcs[i]));
76: } catch (Exception e) {
77: bug(1017, e, "getObjectsById() bug");
78: } finally {
79: endEm(pm);
80: }
81: }
82: }
|