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 java.util.*;
022:
023: import org.apache.openjpa.conf.*;
024: import org.apache.openjpa.meta.*;
025: import org.apache.openjpa.persistence.OpenJPAEntityManager;
026:
027: import org.apache.openjpa.persistence.annotations.common.apps.annotApp.annotype.*;
028: import org.apache.openjpa.persistence.common.utils.*;
029:
030: import junit.framework.*;
031:
032: /**
033: * <p>Test @OrderBy annotation support.</p>
034: *
035: * @author Abe White
036: */
037: public class TestEntityOrderBy extends AnnotationTestCase {
038:
039: public TestEntityOrderBy(String name) {
040: super (name, "annotationcactusapp");
041: }
042:
043: // private ClassMetaData _meta;
044:
045: public void setUp() {
046: // _meta = ((OpenJPAConfiguration) getConfiguration()).
047: // getMetaDataRepositoryInstance().getMetaData(OrderByEntity.class,
048: // null, true);
049: }
050:
051: /* public void testEmptyOrderBy() {
052: String dec = Order.ELEMENT + " asc";
053: assertEquals(dec, _meta.getField("strings").getOrderDeclaration());
054: assertEquals(dec, _meta.getField("pkRels").getOrderDeclaration());
055: }
056:
057: public void testSpecifiedOrderBy() {
058: assertEquals("string desc", _meta.getField("stringRels").
059: getOrderDeclaration());
060: }
061: */
062: public void testUse() {
063: // note: functionality thoroughly tested in kodo.meta.TestOrderBy;
064: // this is just a sanity check on JPA use
065: deleteAll(OrderByEntity.class);
066:
067: OrderByEntity pc = new OrderByEntity();
068: pc.setId(1L);
069: pc.getStrings().add("2");
070: pc.getStrings().add("1");
071: pc.getStrings().add("3");
072:
073: OrderByEntity rel1 = new OrderByEntity();
074: rel1.setId(102L);
075: rel1.setString("2");
076: OrderByEntity rel2 = new OrderByEntity();
077: rel2.setId(101L);
078: rel2.setString("1");
079: OrderByEntity rel3 = new OrderByEntity();
080: rel3.setId(103L);
081: rel3.setString("3");
082: pc.getPKRels().add(rel1);
083: pc.getPKRels().add(rel2);
084: pc.getPKRels().add(rel3);
085: pc.getStringRels().add(rel1);
086: pc.getStringRels().add(rel2);
087: pc.getStringRels().add(rel3);
088:
089: OpenJPAEntityManager em = (OpenJPAEntityManager) currentEntityManager();
090: startTx(em);
091: em.persistAll(pc, rel1, rel2, rel3);
092: endTx(em);
093: endEm(em);
094:
095: em = (OpenJPAEntityManager) currentEntityManager();
096: pc = em.find(OrderByEntity.class, 1L);
097: List<String> strings = pc.getStrings();
098: assertEquals("1", strings.get(0));
099: assertEquals("2", strings.get(1));
100: assertEquals("3", strings.get(2));
101:
102: List<OrderByEntity> pkRels = pc.getPKRels();
103: assertEquals(101L, pkRels.get(0).getId());
104: assertEquals(102L, pkRels.get(1).getId());
105: assertEquals(103L, pkRels.get(2).getId());
106:
107: List<OrderByEntity> stringRels = pc.getStringRels();
108: assertEquals("3", stringRels.get(0).getString());
109: assertEquals("2", stringRels.get(1).getString());
110: assertEquals("1", stringRels.get(2).getString());
111: endEm(em);
112: }
113: }
|