You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2006/08/30 17:06:53 UTC

svn commit: r438513 - in /incubator/cayenne/main/trunk/integration-test/jpa-unit1/src: main/java/org/apache/cayenne/jpa/itest1/entity/ main/resources/META-INF/ test/java/org/apache/cayenne/jpa/itest/entity/ test/resources/

Author: aadamchik
Date: Wed Aug 30 08:06:53 2006
New Revision: 438513

URL: http://svn.apache.org/viewvc?rev=438513&view=rev
Log:
added embeddable class tests

Added:
    incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/main/java/org/apache/cayenne/jpa/itest1/entity/Embeddable1.java
    incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/main/java/org/apache/cayenne/jpa/itest1/entity/EmbeddedEntity.java
    incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/EntityManagerCase.java
    incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/_2_1_5_EmbeddableTest.java
Modified:
    incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/main/resources/META-INF/persistence.xml
    incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/_2_1_1_PeristentFieldsAndPropertiesTest.java
    incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/_2_1_4_PrimaryKeyAndIdentityTest.java
    incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/resources/unit1-schema-hsqldb.sql

Added: incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/main/java/org/apache/cayenne/jpa/itest1/entity/Embeddable1.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/main/java/org/apache/cayenne/jpa/itest1/entity/Embeddable1.java?rev=438513&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/main/java/org/apache/cayenne/jpa/itest1/entity/Embeddable1.java (added)
+++ incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/main/java/org/apache/cayenne/jpa/itest1/entity/Embeddable1.java Wed Aug 30 08:06:53 2006
@@ -0,0 +1,37 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.jpa.itest1.entity;
+
+import javax.persistence.Basic;
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class Embeddable1 {
+
+    @Basic
+    protected String property1;
+
+    public String getProperty1() {
+        return property1;
+    }
+
+    public void setProperty1(String property1) {
+        this.property1 = property1;
+    }
+}

Added: incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/main/java/org/apache/cayenne/jpa/itest1/entity/EmbeddedEntity.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/main/java/org/apache/cayenne/jpa/itest1/entity/EmbeddedEntity.java?rev=438513&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/main/java/org/apache/cayenne/jpa/itest1/entity/EmbeddedEntity.java (added)
+++ incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/main/java/org/apache/cayenne/jpa/itest1/entity/EmbeddedEntity.java Wed Aug 30 08:06:53 2006
@@ -0,0 +1,41 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.jpa.itest1.entity;
+
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+@Entity
+public class EmbeddedEntity {
+
+    @Id
+    protected int id;
+
+    @Embedded
+    protected Embeddable1 embeddable;
+
+    public Embeddable1 getEmbeddable() {
+        return embeddable;
+    }
+
+    public void setEmbeddable(Embeddable1 embeddable) {
+        this.embeddable = embeddable;
+    }
+}

Modified: incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/main/resources/META-INF/persistence.xml?rev=438513&r1=438512&r2=438513&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/main/resources/META-INF/persistence.xml (original)
+++ incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/main/resources/META-INF/persistence.xml Wed Aug 30 08:06:53 2006
@@ -32,5 +32,7 @@
 		<class>org.apache.cayenne.jpa.itest1.entity.NoPkEntity</class>
 		<class>org.apache.cayenne.jpa.itest1.entity.IdClassEntity</class>
 		<class>org.apache.cayenne.jpa.itest1.entity.EmbeddedIdEntity</class>
+		<class>org.apache.cayenne.jpa.itest1.entity.EmbeddedEntity</class>
+		<class>org.apache.cayenne.jpa.itest1.entity.Embeddable1</class>
 	</persistence-unit>
 </persistence>

Added: incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/EntityManagerCase.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/EntityManagerCase.java?rev=438513&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/EntityManagerCase.java (added)
+++ incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/EntityManagerCase.java Wed Aug 30 08:06:53 2006
@@ -0,0 +1,50 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.jpa.itest.entity;
+
+import javax.persistence.EntityManager;
+
+import org.apache.cayenne.jpa.itest.ItestSetup;
+
+public class EntityManagerCase extends Unit1Case {
+
+    protected EntityManager entityManager;
+
+    @Override
+    protected void setUp() throws Exception {
+        entityManager = ItestSetup.getInstance().createEntityManager();
+        entityManager.getTransaction().begin();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        if (entityManager.getTransaction().isActive()) {
+            entityManager.getTransaction().rollback();
+        }
+        entityManager.close();
+    }
+
+    protected EntityManager getEntityManager() {
+        return entityManager;
+    }
+
+    protected void setEntityManager(EntityManager em) {
+        this.entityManager = em;
+    }
+}

Modified: incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/_2_1_1_PeristentFieldsAndPropertiesTest.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/_2_1_1_PeristentFieldsAndPropertiesTest.java?rev=438513&r1=438512&r2=438513&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/_2_1_1_PeristentFieldsAndPropertiesTest.java (original)
+++ incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/_2_1_1_PeristentFieldsAndPropertiesTest.java Wed Aug 30 08:06:53 2006
@@ -20,10 +20,7 @@
 
 import java.util.Collections;
 
-import javax.persistence.EntityManager;
-
 import org.apache.cayenne.jpa.itest.ItestDBUtils;
-import org.apache.cayenne.jpa.itest.ItestSetup;
 import org.apache.cayenne.jpa.itest1.entity.CollectionFieldPersistenceEntity;
 import org.apache.cayenne.jpa.itest1.entity.FieldPersistenceEntity;
 import org.apache.cayenne.jpa.itest1.entity.HelperEntity1;
@@ -33,31 +30,15 @@
 import org.apache.cayenne.jpa.itest1.entity.PropertyPersistenceEntity;
 import org.apache.cayenne.jpa.itest1.entity.TransientFieldsEntity;
 
-public class _2_1_1_PeristentFieldsAndPropertiesTest extends Unit1Case {
-
-    protected EntityManager em;
-
-    @Override
-    protected void setUp() throws Exception {
-        em = ItestSetup.getInstance().createEntityManager();
-        em.getTransaction().begin();
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        if (em.getTransaction().isActive()) {
-            em.getTransaction().rollback();
-        }
-        em.close();
-    }
+public class _2_1_1_PeristentFieldsAndPropertiesTest extends EntityManagerCase {
 
     public void testFieldBasedPersistence() throws Exception {
 
         ItestDBUtils.deleteAll("FieldPersistenceEntity");
 
         FieldPersistenceEntity o1 = new FieldPersistenceEntity();
-        em.persist(o1);
-        em.getTransaction().commit();
+        getEntityManager().persist(o1);
+        getEntityManager().getTransaction().commit();
 
         assertEquals(FieldPersistenceEntity.INITIAL_VALUE, ItestDBUtils.getSingleValue(
                 "FieldPersistenceEntity",
@@ -69,14 +50,14 @@
         PropertyPersistenceEntity o1 = new PropertyPersistenceEntity();
         o1.setProperty1("p1");
         o1.setProperty2(true);
-        em.persist(o1);
-        em.getTransaction().commit();
+        getEntityManager().persist(o1);
+        getEntityManager().getTransaction().commit();
     }
 
     public void testSkipTransientProperties() {
         TransientFieldsEntity o1 = new TransientFieldsEntity();
-        em.persist(o1);
-        em.getTransaction().commit();
+        getEntityManager().persist(o1);
+        getEntityManager().getTransaction().commit();
     }
 
     // TODO: andrus 8/30/2006 - fails
@@ -87,11 +68,11 @@
         o1.setList(Collections.singletonList(new HelperEntity3()));
         o1.setMap(Collections.singletonMap(new Object(), new HelperEntity4()));
 
-        em.persist(o1);
-        em.getTransaction().commit();
+        getEntityManager().persist(o1);
+        getEntityManager().getTransaction().commit();
     }
 
-    // TODO: andrus 8/30/2006 - implement me
+    // TODO: andrus 8/30/2006 - implement
     public void testExceptionInPropertyAccessors() {
         // Runtime exceptions thrown by property accessor methods cause the current
         // transaction to be rolled back.

Modified: incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/_2_1_4_PrimaryKeyAndIdentityTest.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/_2_1_4_PrimaryKeyAndIdentityTest.java?rev=438513&r1=438512&r2=438513&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/_2_1_4_PrimaryKeyAndIdentityTest.java (original)
+++ incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/_2_1_4_PrimaryKeyAndIdentityTest.java Wed Aug 30 08:06:53 2006
@@ -18,39 +18,21 @@
  ****************************************************************/
 package org.apache.cayenne.jpa.itest.entity;
 
-import javax.persistence.EntityManager;
 import javax.persistence.PersistenceException;
 
 import org.apache.cayenne.jpa.itest.ItestDBUtils;
-import org.apache.cayenne.jpa.itest.ItestSetup;
 import org.apache.cayenne.jpa.itest1.entity.EmbeddedIdEntity;
 import org.apache.cayenne.jpa.itest1.entity.FieldPersistenceEntity;
 import org.apache.cayenne.jpa.itest1.entity.IdClassEntity;
 import org.apache.cayenne.jpa.itest1.entity.NoPkEntity;
 
-public class _2_1_4_PrimaryKeyAndIdentityTest extends Unit1Case {
-
-    protected EntityManager em;
-
-    @Override
-    protected void setUp() throws Exception {
-        em = ItestSetup.getInstance().createEntityManager();
-        em.getTransaction().begin();
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        if (em.getTransaction().isActive()) {
-            em.getTransaction().rollback();
-        }
-        em.close();
-    }
+public class _2_1_4_PrimaryKeyAndIdentityTest extends EntityManagerCase {
 
     public void testNoPkEntity() {
         NoPkEntity o1 = new NoPkEntity();
 
         try {
-            em.persist(o1);
+            getEntityManager().persist(o1);
 
         }
         catch (IllegalArgumentException e) {
@@ -58,7 +40,7 @@
         }
 
         try {
-            em.getTransaction().commit();
+            getEntityManager().getTransaction().commit();
         }
         catch (PersistenceException e) {
             return;
@@ -70,15 +52,15 @@
 
     public void testSimplePk() throws Exception {
         FieldPersistenceEntity o1 = new FieldPersistenceEntity();
-        em.persist(o1);
+        getEntityManager().persist(o1);
     }
 
     // TODO: andrus 8/10/2006 - fails
     public void _testIdClassPk() throws Exception {
         IdClassEntity o1 = new IdClassEntity();
         o1.setProperty1("p1");
-        em.persist(o1);
-        em.getTransaction().commit();
+        getEntityManager().persist(o1);
+        getEntityManager().getTransaction().commit();
 
         assertEquals("p1", ItestDBUtils.getSingleValue("IdClassEntity", "property1"));
     }
@@ -87,8 +69,8 @@
     public void _testEmbeddedIdPk() throws Exception {
         EmbeddedIdEntity o1 = new EmbeddedIdEntity();
         o1.setProperty1("p1");
-        em.persist(o1);
-        em.getTransaction().commit();
+        getEntityManager().persist(o1);
+        getEntityManager().getTransaction().commit();
 
         assertEquals("p1", ItestDBUtils.getSingleValue("EmbeddedIdEntity", "property1"));
     }

Added: incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/_2_1_5_EmbeddableTest.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/_2_1_5_EmbeddableTest.java?rev=438513&view=auto
==============================================================================
--- incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/_2_1_5_EmbeddableTest.java (added)
+++ incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/java/org/apache/cayenne/jpa/itest/entity/_2_1_5_EmbeddableTest.java Wed Aug 30 08:06:53 2006
@@ -0,0 +1,38 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.jpa.itest.entity;
+
+import org.apache.cayenne.jpa.itest1.entity.Embeddable1;
+import org.apache.cayenne.jpa.itest1.entity.EmbeddedEntity;
+
+public class _2_1_5_EmbeddableTest extends EntityManagerCase {
+
+    public void testEmbeddable() throws Exception {
+        EmbeddedEntity o1 = new EmbeddedEntity();
+        Embeddable1 o2 = new Embeddable1();
+        o2.setProperty1("p1");
+        o1.setEmbeddable(o2);
+
+        getEntityManager().persist(o1);
+        getEntityManager().getTransaction().commit();
+
+        // TODO: andrus 8/10/2006 - fails
+        // assertEquals("p1", ItestDBUtils.getSingleValue("EmbeddedEntity", "property1"));
+    }
+}

Modified: incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/resources/unit1-schema-hsqldb.sql
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/resources/unit1-schema-hsqldb.sql?rev=438513&r1=438512&r2=438513&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/resources/unit1-schema-hsqldb.sql (original)
+++ incubator/cayenne/main/trunk/integration-test/jpa-unit1/src/test/resources/unit1-schema-hsqldb.sql Wed Aug 30 08:06:53 2006
@@ -7,6 +7,7 @@
 insert into AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('HelperEntity2', 1);
 insert into AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('HelperEntity3', 1);
 insert into AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('HelperEntity4', 1);
+insert into AUTO_PK_SUPPORT (TABLE_NAME, NEXT_ID) VALUES ('EmbeddedEntity', 1);
 
 create table FieldPersistenceEntity (id int not null, property1 VARCHAR(100), primary key(id));
 create table PropertyPersistenceEntity (id int not null, property1 VARCHAR(100), property2 BOOLEAN, primary key(id));
@@ -18,4 +19,5 @@
 create table HelperEntity4 (id int not null, entity_id int, primary key(id));
 create table NoPkEntity (property1 VARCHAR(100));
 create table IdClassEntity (id1 int not null, id2 int not null, property1 VARCHAR(100), primary key(id1, id2));
-create table EmbeddedIdEntity (id1 int not null, id2 int not null, property1 VARCHAR(100), primary key(id1, id2));
\ No newline at end of file
+create table EmbeddedIdEntity (id1 int not null, id2 int not null, property1 VARCHAR(100), primary key(id1, id2));
+create table EmbeddedEntity (id int not null, property1 VARCHAR(100), primary key(id));
\ No newline at end of file