01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.persistence.kernel;
20:
21: import java.util.Arrays;
22: import java.util.HashSet;
23: import javax.persistence.EntityManager;
24:
25: import org.apache.openjpa.persistence.kernel.common.apps.AllFieldsTypeTest;
26: import org.apache.openjpa.persistence.kernel.common.apps.ObjectCollectionHolder;
27: import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
28:
29: /**
30: * Tests that Collections of type {@link Object} can hold all
31: * sorts of stuff (heterogeneous classes, persistent classes).
32: *
33: * @author <a href="mailto:marc@solarmetric.com">Marc Prud'hommeaux</a>
34: */
35: public class TestEJBObjectCollections extends AbstractTestCase {
36:
37: public TestEJBObjectCollections(String name) {
38: super (name, "kernelcactusapp");
39: }
40:
41: public void testHashSet() {
42: assertEquals(1, add(new Object[] { "Foo" }, 1).getHashSet()
43: .size());
44: assertEquals(1, add(new Object[] { "Foo" }, 2).getHashSet()
45: .size());
46:
47: assertEquals(2, add(
48: new Object[] { "Foo", new AllFieldsTypeTest() }, 3)
49: .getHashSet().size());
50: }
51:
52: public void setUp() {
53: deleteAll(ObjectCollectionHolder.class);
54: deleteAll(AllFieldsTypeTest.class);
55: }
56:
57: public void tearDown() throws Exception {
58: super .tearDown();
59: }
60:
61: @SuppressWarnings("unchecked")
62: public ObjectCollectionHolder add(Object[] objects, int id) {
63: EntityManager pm = currentEntityManager();
64: startTx(pm);
65: ObjectCollectionHolder holder = new ObjectCollectionHolder();
66: holder.setId(id);
67: pm.persist(holder);
68: holder.setHashSet(new HashSet(Arrays.asList(objects)));
69: endTx(pm);
70: endEm(pm);
71:
72: pm = currentEntityManager();
73: startTx(pm);
74: return (ObjectCollectionHolder) pm.find(
75: ObjectCollectionHolder.class, id);
76: }
77: }
|