tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgallim...@apache.org
Subject [1/5] tomee git commit: Add simple test to ensure overrides from openejb-cmp-orm.xml work
Date Mon, 19 Nov 2018 15:09:25 GMT
Repository: tomee
Updated Branches:
  refs/heads/master 511db23be -> 9939dff9f


Add simple test to ensure overrides from openejb-cmp-orm.xml work


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/e8ef7742
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/e8ef7742
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/e8ef7742

Branch: refs/heads/master
Commit: e8ef7742ea599f2506abac821dacb242b83919b4
Parents: 60ef186
Author: Jonathan Gallimore <jon@jrg.me.uk>
Authored: Fri Nov 16 12:39:20 2018 +0000
Committer: Jonathan Gallimore <jon@jrg.me.uk>
Committed: Fri Nov 16 12:39:20 2018 +0000

----------------------------------------------------------------------
 .../openejb/core/LegacyInterfaceTest.java       | 76 ++++++++++++++++++++
 1 file changed, 76 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/e8ef7742/container/openejb-core/src/test/java/org/apache/openejb/core/LegacyInterfaceTest.java
----------------------------------------------------------------------
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 a7f7494..f450f2c 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;
@@ -34,6 +35,7 @@ import org.apache.openejb.jee.Query;
 import org.apache.openejb.jee.QueryMethod;
 import org.apache.openejb.jee.SingletonBean;
 import org.apache.openejb.jee.TransAttribute;
+import org.apache.openejb.jee.jpa.*;
 import org.junit.AfterClass;
 
 import javax.ejb.CreateException;
@@ -140,6 +142,80 @@ public class LegacyInterfaceTest extends TestCase {
 
     }
 
+    public void testCustomCmpMappings() 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 EntityMappings entityMappings = new EntityMappings();
+
+        final Entity entity = new Entity();
+        entity.setClazz("openejb.org.apache.openejb.core.MyCmpBean");
+        entity.setName("MyCmpBean");
+        entity.setDescription("MyCmpBean");
+        entity.setAttributes(new Attributes());
+
+        final NamedQuery namedQuery = new NamedQuery();
+        namedQuery.setQuery("SELECT OBJECT(DL) FROM License DL");
+        entity.getNamedQuery().add(namedQuery);
+
+        final Id id = new Id();
+        id.setName("id");
+        entity.getAttributes().getId().add(id);
+
+        final Basic basic = new Basic();
+        basic.setName("name");
+        final Column column = new Column();
+        column.setName("wNAME");
+        column.setLength(300);
+        basic.setColumn(column);
+        entity.getAttributes().getBasic().add(basic);
+
+        entityMappings.getEntity().add(entity);
+
+        final AppModule module = new AppModule(this.getClass().getClassLoader(), f.getAbsolutePath());
+        final EjbModule ejbModule = new EjbModule(ejbJar);
+        ejbModule.getAltDDs().put("openejb-cmp-orm.xml", entityMappings);
+        module.getEjbModules().add(ejbModule);
+
+        assertNull(module.getCmpMappings());
+        assembler.createApplication(config.configureApplication(module));
+        assertNotNull(module.getCmpMappings());
+        final List<Basic> basicList = module.getCmpMappings().getEntityMap().get("openejb.org.apache.openejb.core.MyCmpBean").getAttributes().getBasic();
+        assertEquals(1, basicList.size());
+        assertEquals(300, basicList.get(0).getColumn().getLength().intValue());
+        assertEquals("wNAME", basicList.get(0).getColumn().getName());
+    }
+
     @LocalHome(MyLocalHome.class)
     @RemoteHome(MyRemoteHome.class)
     public static abstract class MyCmpBean implements javax.ejb.EntityBean {


Mime
View raw message