You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2019/06/02 20:29:58 UTC

[tomee] branch tomee-7.0.x updated: Backporting CMP/JPA unit test

This is an automated email from the ASF dual-hosted git repository.

jgallimore pushed a commit to branch tomee-7.0.x
in repository https://gitbox.apache.org/repos/asf/tomee.git


The following commit(s) were added to refs/heads/tomee-7.0.x by this push:
     new 761ded1  Backporting CMP/JPA unit test
761ded1 is described below

commit 761ded1d4e0ada4c03fed7cfbfd33748ec85eacc
Author: Jonathan Gallimore <jo...@jrg.me.uk>
AuthorDate: Sun Jun 2 21:29:39 2019 +0100

    Backporting CMP/JPA unit test
---
 .../apache/openejb/core/LegacyInterfaceTest.java   | 66 ++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/container/openejb-core/src/test/java/org/apache/openejb/core/LegacyInterfaceTest.java b/container/openejb-core/src/test/java/org/apache/openejb/core/LegacyInterfaceTest.java
index 07eb69c..49f4ee3 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/core/LegacyInterfaceTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/core/LegacyInterfaceTest.java
@@ -24,6 +24,7 @@ import org.apache.openejb.assembler.classic.TransactionServiceInfo;
 import org.apache.openejb.config.AppModule;
 import org.apache.openejb.config.ConfigurationFactory;
 import org.apache.openejb.config.EjbModule;
+import org.apache.openejb.config.PersistenceModule;
 import org.apache.openejb.core.ivm.naming.InitContextFactory;
 import org.apache.openejb.jee.CmpField;
 import org.apache.openejb.jee.ContainerTransaction;
@@ -41,6 +42,9 @@ import org.apache.openejb.jee.jpa.Entity;
 import org.apache.openejb.jee.jpa.EntityMappings;
 import org.apache.openejb.jee.jpa.Id;
 import org.apache.openejb.jee.jpa.NamedQuery;
+import org.apache.openejb.jee.jpa.unit.Persistence;
+import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
+import org.apache.openejb.jee.jpa.unit.TransactionType;
 import org.junit.AfterClass;
 
 import javax.ejb.CreateException;
@@ -221,6 +225,68 @@ public class LegacyInterfaceTest extends TestCase {
         assertEquals("wNAME", basicList.get(0).getColumn().getName());
     }
 
+    public void testCustomCmpMappingsWithMappingFileDefinedInPersistenceXml() throws Exception {
+
+        System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
+
+        final ConfigurationFactory config = new ConfigurationFactory();
+        final Assembler assembler = new Assembler();
+
+        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+
+        final EjbJar ejbJar = new EjbJar();
+        ejbJar.addEnterpriseBean(new SingletonBean(MySingletonBean.class));
+        ejbJar.addEnterpriseBean(new EntityBean(MyBmpBean.class, PersistenceType.BEAN));
+
+        final EntityBean cmp = ejbJar.addEnterpriseBean(new EntityBean(MyCmpBean.class, PersistenceType.CONTAINER));
+        cmp.setPrimKeyClass(Integer.class.getName());
+        cmp.setPrimkeyField("id");
+        cmp.getCmpField().add(new CmpField("id"));
+        cmp.getCmpField().add(new CmpField("name"));
+        final Query query = new Query();
+        query.setQueryMethod(new QueryMethod("findByPrimaryKey", Integer.class.getName()));
+        query.setEjbQl("SELECT OBJECT(DL) FROM License DL");
+        cmp.getQuery().add(query);
+        final List<ContainerTransaction> transactions = ejbJar.getAssemblyDescriptor().getContainerTransaction();
+
+        transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MyBmpBean", "*"));
+        transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MyCmpBean", "*"));
+        transactions.add(new ContainerTransaction(TransAttribute.SUPPORTS, null, "MySingletonBean", "*"));
+
+        final File f = new File("test").getAbsoluteFile();
+        if (!f.exists() && !f.mkdirs()) {
+            throw new Exception("Failed to create test directory: " + f);
+        }
+
+        final AppModule module = new AppModule(this.getClass().getClassLoader(), f.getAbsolutePath());
+        final EjbModule ejbModule = new EjbModule(ejbJar);
+
+        Persistence persistence = new Persistence();
+        PersistenceUnit pu = persistence.addPersistenceUnit("cmp");
+        pu.setTransactionType(TransactionType.JTA);
+        pu.setJtaDataSource("fake");
+        pu.setNonJtaDataSource("fake");
+        pu.getMappingFile().add("test-orm.xml");
+        pu.getClazz().add("openejb.org.apache.openejb.core.MyCmpBean");
+        module.addPersistenceModule(new PersistenceModule("pu", persistence));
+
+        module.getEjbModules().add(ejbModule);
+
+        assertNull(module.getCmpMappings());
+        assembler.createApplication(config.configureApplication(module));
+        assertNotNull(module.getCmpMappings());
+
+        // no mapping should be automatically generated
+        assertTrue(module.getCmpMappings().getEntityMap().isEmpty());
+
+        // pu should not be modified, no duplicate classes
+        assertEquals(1, pu.getClazz().size());
+        assertEquals("openejb.org.apache.openejb.core.MyCmpBean", pu.getClazz().get(0));
+        assertEquals(1, pu.getMappingFile().size());
+        assertEquals("test-orm.xml", pu.getMappingFile().get(0));
+    }
+
     @LocalHome(MyLocalHome.class)
     @RemoteHome(MyRemoteHome.class)
     public static abstract class MyCmpBean implements javax.ejb.EntityBean {