01: /*
02: * TestFieldState.java
03: *
04: * Created on October 12, 2006, 10:22 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.RuntimeTest1;
31:
32: import org.apache.openjpa.kernel.OpenJPAStateManager;
33: import org.apache.openjpa.meta.FieldMetaData;
34: import org.apache.openjpa.persistence.OpenJPAEntityManager;
35:
36: public class TestFieldState extends BaseKernelTest {
37:
38: private Object oid;
39:
40: /**
41: * Creates a new instance of TestFieldState
42: */
43: public TestFieldState() {
44: }
45:
46: public TestFieldState(String name) {
47: super (name);
48: }
49:
50: public void setUp() {
51: deleteAll(RuntimeTest1.class);
52:
53: OpenJPAEntityManager pm = getPM();
54: startTx(pm);
55:
56: // create a test object
57: RuntimeTest1 a = new RuntimeTest1("foo", 3);
58: pm.persist(a);
59:
60: endTx(pm);
61:
62: oid = pm.getObjectId(a);
63: endEm(pm);
64: }
65:
66: public void testNotDirtyAfterSameChange() {
67: OpenJPAEntityManager pm = getPM();
68: startTx(pm);
69:
70: RuntimeTest1 a = (RuntimeTest1) pm
71: .find(RuntimeTest1.class, oid);
72: a.setStringField(a.getStringField());
73: OpenJPAStateManager sm = getStateManager(a, pm);
74: FieldMetaData fmd = sm.getMetaData().getField("stringField");
75: assertTrue(sm.getDirty().get(fmd.getIndex()) == false);
76:
77: endTx(pm);
78: endEm(pm);
79: }
80: }
|