Repository: tomee
Updated Branches:
  refs/heads/tomee-7.1.x 14cf776d6 -> 4adec2f85


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/73a220b2
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/73a220b2
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/73a220b2

Branch: refs/heads/tomee-7.1.x
Commit: 73a220b2bb2cb09a5dffd678faede14de1313278
Parents: 192bf4d
Author: Jonathan Gallimore <[email protected]>
Authored: Fri Nov 16 12:39:20 2018 +0000
Committer: Otavio Santana <[email protected]>
Committed: Mon Dec 17 13:53:16 2018 -0200

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


http://git-wip-us.apache.org/repos/asf/tomee/blob/73a220b2/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 {

Reply via email to