001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.persistence.annotations;
020:
021: import javax.persistence.*;
022:
023: import org.apache.openjpa.persistence.OpenJPAEntityManager;
024:
025: import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.*;
026: import junit.framework.*;
027:
028: import org.apache.openjpa.persistence.common.utils.*;
029:
030: public class TestPropertyAccess extends AnnotationTestCase {
031: public TestPropertyAccess(String name) {
032: super (name, "annotationcactusapp");
033: }
034:
035: public void setUp() {
036: deleteAll(PropertyAccess1.class);
037: }
038:
039: public void testPropertyAccessBasicCreation() {
040: OpenJPAEntityManager em = (OpenJPAEntityManager) currentEntityManager();
041: startTx(em);
042: PropertyAccess1 pa1_1 = new PropertyAccess1(10);
043: pa1_1.setName("foo");
044: em.persist(pa1_1);
045: endTx(em);
046:
047: // getting a new EM should not be necessary once the extended PC stuff
048: // is complete.
049: em = (OpenJPAEntityManager) currentEntityManager();
050:
051: PropertyAccess1 pa1_2 = em.find(PropertyAccess1.class, 10);
052: assertNotSame(pa1_1, pa1_2);
053: assertNotNull(pa1_2);
054: assertEquals(10, pa1_2.getId());
055: assertEquals("foo", pa1_2.getName());
056: }
057:
058: public void testPropertyAccessBasicMutation() {
059: OpenJPAEntityManager em = (OpenJPAEntityManager) currentEntityManager();
060: startTx(em);
061: PropertyAccess1 pa1_1 = new PropertyAccess1(10);
062: pa1_1.setName("foo");
063: em.persist(pa1_1);
064: endTx(em);
065:
066: // getting a new EM should not be necessary once the extended PC stuff
067: // is complete.
068: em = (OpenJPAEntityManager) currentEntityManager();
069:
070: startTx(em);
071: PropertyAccess1 pa1_2 = em.find(PropertyAccess1.class, 10);
072: pa1_2.setName(pa1_2.getName() + "bar");
073: endTx(em);
074:
075: em = (OpenJPAEntityManager) currentEntityManager();
076: PropertyAccess1 pa1_3 = em.find(PropertyAccess1.class, 10);
077: assertNotSame(pa1_2, pa1_3);
078: assertEquals("foobar", pa1_3.getName());
079: }
080:
081: public void testJPQL() {
082: OpenJPAEntityManager em = (OpenJPAEntityManager) currentEntityManager();
083: em.createQuery(
084: "select o from PropertyAccess1 o where "
085: + "o.name = 'foo'").getResultList();
086: em.createQuery(
087: "select o from PropertyAccess1 o order by "
088: + "o.name asc").getResultList();
089: endEm(em);
090: }
091:
092: public void testJPQLWithFieldNameMismatch() {
093: OpenJPAEntityManager em = (OpenJPAEntityManager) currentEntityManager();
094: em.createQuery(
095: "select o from PropertyAccess1 o where "
096: + "o.intValue = 0").getResultList();
097: em.createQuery(
098: "select o from PropertyAccess1 o order by "
099: + "o.intValue asc").getResultList();
100: endEm(em);
101: }
102:
103: /*public void testJDOQL() {
104: PersistenceManager pm = getPM();
105: pm.newQuery("select from persistence.annotations.common.apps.annotApp.annotype.PropertyAccess1 "
106: + "where name == 'foo'").execute();
107: pm.newQuery("select from persistence.annotations.common.apps.annotApp.annotype.PropertyAccess1 "
108: + "order by name ascending").execute();
109: pm.close();
110: }
111:
112: public void testJDOQLWithFieldNameMismatch() {
113: PersistenceManager pm = getPM();
114: pm.newQuery("select from persistence.annotations.common.apps.annotApp.annotype.PropertyAccess1 "
115: + "where intValue == 0").execute();
116: pm.newQuery("select from persistence.annotations.common.apps.annotApp.annotype.PropertyAccess1 "
117: + "order by intValue asc").execute();
118: pm.close();
119: }*/
120: }
|