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 org.apache.openjpa.persistence.*;
022: import java.util.List;
023: import javax.persistence.*;
024: import junit.framework.*;
025: import org.apache.openjpa.persistence.common.utils.*;
026: import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.*;
027:
028: /**
029: * Test enums and the @Enumerated annotation.
030: *
031: * @author Abe White
032: */
033: public class TestEnumerated extends AnnotationTestCase {
034:
035: public TestEnumerated(String name) {
036: super (name, "annotationcactusapp");
037: }
038:
039: public void setUp() {
040: deleteAll(AnnoTest1.class);
041: }
042:
043: /** public void testMapping() {
044: ClassMapping cls = (ClassMapping) getConfiguration().
045: getMetaDataRepositoryInstance().getMetaData(AnnoTest1.class,
046: null, true);
047: FieldMapping fm = cls.getDeclaredFieldMapping("enumeration");
048: assertNotNull(fm);
049: assertEquals(FieldMapping.MANAGE_PERSISTENT, fm.getManagement());
050: assertEquals(JavaTypes.OBJECT, fm.getTypeCode());
051: assertEquals(JavaTypes.SHORT, fm.getColumns()[0].getJavaType());
052:
053: fm = cls.getDeclaredFieldMapping("ordinalEnumeration");
054: assertNotNull(fm);
055: assertEquals(FieldMapping.MANAGE_PERSISTENT, fm.getManagement());
056: assertEquals(JavaTypes.OBJECT, fm.getTypeCode());
057: assertEquals(JavaTypes.SHORT, fm.getColumns()[0].getJavaType());
058:
059: fm = cls.getDeclaredFieldMapping("stringEnumeration");
060: assertNotNull(fm);
061: assertEquals(FieldMapping.MANAGE_PERSISTENT, fm.getManagement());
062: assertEquals(JavaTypes.OBJECT, fm.getTypeCode());
063: assertEquals(JavaTypes.STRING, fm.getColumns()[0].getJavaType());
064: }*/
065:
066: public void testBehavior() {
067: OpenJPAEntityManager em = (OpenJPAEntityManager) currentEntityManager();
068: startTx(em);
069:
070: AnnoTest1 pc = new AnnoTest1(1);
071: assertNotNull("pc is null", pc);
072: assertNotNull("InheritanceType.TABLE_PER_CLASS is null",
073: InheritanceType.TABLE_PER_CLASS);
074: assertNotNull("InheritanceType.JOINED is null",
075: InheritanceType.JOINED);
076: pc.setEnumeration(InheritanceType.TABLE_PER_CLASS);
077: pc.setOrdinalEnumeration(InheritanceType.TABLE_PER_CLASS);
078: pc.setStringEnumeration(InheritanceType.JOINED);
079: em.persist(pc);
080: endTx(em);
081: endEm(em);
082:
083: em = (OpenJPAEntityManager) currentEntityManager();
084: OpenJPAQuery q = em.createQuery("SELECT o FROM AnnoTest1 o");
085: assertEquals(1, q.getResultList().size());
086:
087: // AnnoTest1 pc2 = em.find(AnnoTest1.class, new Long(1));
088: AnnoTest1 pc2 = (AnnoTest1) q.getSingleResult();
089: assertNotNull("pc2 is null", pc2);
090: assertEquals(InheritanceType.TABLE_PER_CLASS, pc2
091: .getEnumeration());
092: assertEquals(InheritanceType.TABLE_PER_CLASS, pc2
093: .getOrdinalEnumeration());
094: assertEquals(InheritanceType.JOINED, pc2.getStringEnumeration());
095: startTx(em);
096: pc2.setEnumeration(InheritanceType.JOINED);
097: pc2.setOrdinalEnumeration(InheritanceType.JOINED);
098: pc2.setStringEnumeration(InheritanceType.TABLE_PER_CLASS);
099: endTx(em);
100: endEm(em);
101:
102: em = (OpenJPAEntityManager) currentEntityManager();
103: // pc2 = em.find(AnnoTest1.class, new Long(1));
104: q = em.createQuery("SELECT o FROM AnnoTest1 o");
105: pc2 = (AnnoTest1) q.getSingleResult();
106: assertEquals(InheritanceType.JOINED, pc2.getEnumeration());
107: assertEquals(InheritanceType.JOINED, pc2
108: .getOrdinalEnumeration());
109: assertEquals(InheritanceType.TABLE_PER_CLASS, pc2
110: .getStringEnumeration());
111: endEm(em);
112: }
113:
114: }
|