01: /*
02: * TestSerialize.java
03: *
04: * Created on October 13, 2006, 5:13 PM
05: *
06: * To change this template, choose Tools | Template Manager
07: * and open the template in the editor.
08: */
09: /*
10: * Licensed to the Apache Software Foundation (ASF) under one
11: * or more contributor license agreements. See the NOTICE file
12: * distributed with this work for additional information
13: * regarding copyright ownership. The ASF licenses this file
14: * to you under the Apache License, Version 2.0 (the
15: * "License"); you may not use this file except in compliance
16: * with the License. You may obtain a copy of the License at
17: *
18: * http://www.apache.org/licenses/LICENSE-2.0
19: *
20: * Unless required by applicable law or agreed to in writing,
21: * software distributed under the License is distributed on an
22: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23: * KIND, either express or implied. See the License for the
24: * specific language governing permissions and limitations
25: * under the License.
26: */
27: package org.apache.openjpa.persistence.kernel;
28:
29: import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
30:
31: import org.apache.openjpa.persistence.OpenJPAEntityManager;
32:
33: public class TestSerialize extends BaseKernelTest {
34:
35: private int _oid = 0;
36: private Object _oid2 = null;
37:
38: /**
39: * Creates a new instance of TestSerialize
40: */
41: public TestSerialize() {
42: }
43:
44: public TestSerialize(String name) {
45: super (name);
46: }
47:
48: public void setUp() throws Exception {
49: RuntimeTest1 a = new RuntimeTest1("1NAME", 1);
50: a.setSelfOneOne(new RuntimeTest1("2NAME", 2));
51:
52: OpenJPAEntityManager pm = getPM();
53: startTx(pm);
54: pm.persist(a);
55: _oid = a.getIntField();
56:
57: endTx(pm);
58: endEm(pm);
59: }
60:
61: public void testConfigurationSerializable() throws Exception {
62: // validate that the hashCode() and equals() method hold true
63: // for the round-trip.
64: roundtrip(getConfiguration(), true);
65: }
66:
67: public void testSerialize() throws Exception {
68: OpenJPAEntityManager pm = getPM();
69: //FIXME jthomas
70: /*pm.getFetchPlan().setDetachmentOptions
71: (FetchPlan.DETACH_ALL_FIELDS);
72: */
73: RuntimeTest1 a = (RuntimeTest1) pm.find(RuntimeTest1.class,
74: _oid);
75:
76: assertEquals("1NAME", a.getStringField());
77: assertEquals(1, a.getIntField());
78: assertNotNull(a.getSelfOneOne());
79: assertEquals("2NAME", a.getSelfOneOne().getStringField());
80: assertEquals(2, a.getSelfOneOne().getIntField());
81:
82: a = (RuntimeTest1) roundtrip(a, false);
83:
84: assertEquals("1NAME", a.getStringField());
85: assertEquals(1, a.getIntField());
86: assertNotNull(a.getSelfOneOne());
87: assertEquals("2NAME", a.getSelfOneOne().getStringField());
88: assertEquals(2, a.getSelfOneOne().getIntField());
89: }
90: }
|