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 2018/12/19 22:10:50 UTC
[06/30] tomee git commit: TOMEE-2295 test for element
being ignored
TOMEE-2295 test for <mapping-file> element being ignored
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/bf6a58b1
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/bf6a58b1
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/bf6a58b1
Branch: refs/heads/tomee-7.1.x
Commit: bf6a58b158c82c9b1c52709d640c3aa3d167ac64
Parents: 8cf808a
Author: Jonathan Gallimore <jo...@jrg.me.uk>
Authored: Wed Nov 28 11:51:18 2018 +0000
Committer: Otavio Santana <ot...@gmail.com>
Committed: Mon Dec 17 13:55:47 2018 -0200
----------------------------------------------------------------------
.../src/main/resources/test-orm.xml | 32 +++++++
.../openejb/core/LegacyInterfaceTest.java | 89 ++++++++++++++++++++
2 files changed, 121 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/bf6a58b1/container/openejb-core/src/main/resources/test-orm.xml
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/resources/test-orm.xml b/container/openejb-core/src/main/resources/test-orm.xml
new file mode 100644
index 0000000..0646b30
--- /dev/null
+++ b/container/openejb-core/src/main/resources/test-orm.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+-->
+<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" version="1.0">
+ <entity class="openejb.org.apache.openejb.core.MyCmpBean" name="MyCmpBean">
+ <description>MyCmpBean</description>
+ <named-query name="MyCmpBean.findByPrimaryKey(java.lang.Integer)">
+ <query>SELECT OBJECT(DL) FROM License DL</query>
+ </named-query>
+ <attributes>
+ <id name="id"/>
+ <basic name="name">
+ <column name="wNAME" length="300"/>
+ </basic>
+ </attributes>
+ </entity>
+</entity-mappings>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tomee/blob/bf6a58b1/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 f450f2c..0b4b73f 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
@@ -36,6 +36,9 @@ 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.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;
@@ -216,6 +219,92 @@ 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 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);
+
+
+ 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.addClass("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());
+ assertEquals(1, pu.getClazz().size());
+ assertEquals("openejb.org.apache.openejb.core.MyCmpBean", pu.getClazz().get(0));
+ 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 {