Adding further basic CMP tests
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/c320aa00 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/c320aa00 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/c320aa00 Branch: refs/heads/tomee-7.1.x Commit: c320aa00893e926c4d1b37573592f17f75865d5a Parents: 73a220b Author: Jonathan Gallimore <[email protected]> Authored: Fri Nov 16 15:06:17 2018 +0000 Committer: Otavio Santana <[email protected]> Committed: Mon Dec 17 13:53:51 2018 -0200 ---------------------------------------------------------------------- .gitignore | 2 +- .../arquillian/tests/cmp/CmpMappingTest.java | 58 ++++++++++++++++++++ .../arquillian/tests/cmp/CmpServlet.java | 30 ++++++++++ .../openejb/arquillian/tests/cmp/MyCmpBean.java | 53 ++++++++++++++++++ .../arquillian/tests/cmp/MyLocalHome.java | 14 +++++ .../arquillian/tests/cmp/MyLocalObject.java | 7 +++ .../arquillian/tests/cmp/MyRemoteHome.java | 14 +++++ .../arquillian/tests/cmp/MyRemoteObject.java | 9 +++ .../openejb/arquillian/tests/cmp/ejb-jar.xml | 54 ++++++++++++++++++ .../arquillian/tests/cmp/openejb-cmp-orm.xml | 32 +++++++++++ .../apache/openejb/config/ReadDescriptors.java | 3 +- .../openejb/config/ReadDescriptorsTest.java | 10 ++++ .../openejb/config/test-openejb-cmp-orm.xml | 32 +++++++++++ 13 files changed, 316 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/c320aa00/.gitignore ---------------------------------------------------------------------- diff --git a/.gitignore b/.gitignore index 0fa9ed4..fa39aa3 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,4 @@ quick.bat /temp /report.txt nb-configuration.xml - +.factorypath http://git-wip-us.apache.org/repos/asf/tomee/blob/c320aa00/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/CmpMappingTest.java ---------------------------------------------------------------------- diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/CmpMappingTest.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/CmpMappingTest.java new file mode 100644 index 0000000..4c8cf41 --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/CmpMappingTest.java @@ -0,0 +1,58 @@ +/* + * 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.openejb.arquillian.tests.cmp; + +import org.apache.ziplock.IO; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.net.URL; + +/** + * @version $Rev$ $Date$ + */ +@RunWith(Arquillian.class) +public class CmpMappingTest { + + @ArquillianResource + private URL url; + + @Deployment(testable = false) + public static WebArchive createDeployment() { + WebArchive archive = ShrinkWrap.create(WebArchive.class, CmpMappingTest.class.getSimpleName() + ".war") + .addClasses(CmpServlet.class, MyCmpBean.class, MyLocalHome.class, MyLocalObject.class, MyRemoteHome.class, MyRemoteObject.class) + .addAsWebInfResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/openejb-cmp-orm.xml"), "openejb-cmp-orm.xml") + .addAsWebInfResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/ejb-jar.xml"), "ejb-jar.xml"); + + System.out.println(archive.toString(true)); + return archive; + } + + @Test + @RunAsClient + public void checkCmpJpaEntityORMMappings() throws Exception { + final String output = IO.readString(new URL(url.toExternalForm())); + System.out.println(output); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/c320aa00/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/CmpServlet.java ---------------------------------------------------------------------- diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/CmpServlet.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/CmpServlet.java new file mode 100644 index 0000000..c843a9c --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/CmpServlet.java @@ -0,0 +1,30 @@ +package org.apache.openejb.arquillian.tests.cmp; + +import org.apache.openejb.assembler.classic.AppInfo; +import org.apache.openejb.assembler.classic.Assembler; +import org.apache.openejb.loader.SystemInstance; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Collection; + +@WebServlet(name="Cmp", urlPatterns = "/*") +public class CmpServlet extends HttpServlet { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + + final Assembler assembler = SystemInstance.get().getComponent(Assembler.class); + final Collection<AppInfo> deployedApplications = assembler.getDeployedApplications(); + + for (final AppInfo deployedApplication : deployedApplications) { + if ("CmpMappingTest".equals(deployedApplication.appId)) { + final String cmpMappingsXml = deployedApplication.cmpMappingsXml; + resp.getWriter().write(cmpMappingsXml == null ? "null" : cmpMappingsXml); + } + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/c320aa00/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyCmpBean.java ---------------------------------------------------------------------- diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyCmpBean.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyCmpBean.java new file mode 100644 index 0000000..20ecd76 --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyCmpBean.java @@ -0,0 +1,53 @@ +package org.apache.openejb.arquillian.tests.cmp; + +import javax.ejb.CreateException; +import javax.ejb.EntityBean; +import javax.ejb.EntityContext; +import javax.ejb.LocalHome; +import javax.ejb.RemoteHome; +import javax.ejb.RemoveException; + +@LocalHome(MyLocalHome.class) +@RemoteHome(MyRemoteHome.class) +public abstract class MyCmpBean implements EntityBean { + + // CMP + public abstract Integer getId(); + + public abstract void setId(Integer id); + + public abstract String getName(); + + public abstract void setName(String number); + + public void doit() { + } + + public Integer ejbCreateObject(final String id) throws CreateException { + return null; + } + + public void ejbPostCreateObject(final String id) { + } + + public void setEntityContext(final EntityContext ctx) { + } + + public void unsetEntityContext() { + } + + public void ejbActivate() { + } + + public void ejbPassivate() { + } + + public void ejbLoad() { + } + + public void ejbStore() { + } + + public void ejbRemove() throws RemoveException { + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/c320aa00/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyLocalHome.java ---------------------------------------------------------------------- diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyLocalHome.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyLocalHome.java new file mode 100644 index 0000000..8eb489e --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyLocalHome.java @@ -0,0 +1,14 @@ +package org.apache.openejb.arquillian.tests.cmp; + +public interface MyLocalHome extends javax.ejb.EJBLocalHome { + + public MyLocalObject createObject(String name) + throws javax.ejb.CreateException; + + public MyLocalObject findByPrimaryKey(Integer primarykey) + throws javax.ejb.FinderException; + + public java.util.Collection findEmptyCollection() + throws javax.ejb.FinderException; + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/c320aa00/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyLocalObject.java ---------------------------------------------------------------------- diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyLocalObject.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyLocalObject.java new file mode 100644 index 0000000..c007571 --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyLocalObject.java @@ -0,0 +1,7 @@ +package org.apache.openejb.arquillian.tests.cmp; + +public interface MyLocalObject extends javax.ejb.EJBLocalObject { + + public void doit(); + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/c320aa00/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyRemoteHome.java ---------------------------------------------------------------------- diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyRemoteHome.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyRemoteHome.java new file mode 100644 index 0000000..9153ad6 --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyRemoteHome.java @@ -0,0 +1,14 @@ +package org.apache.openejb.arquillian.tests.cmp; + +public interface MyRemoteHome extends javax.ejb.EJBHome { + + public MyRemoteObject createObject(String name) + throws javax.ejb.CreateException, java.rmi.RemoteException; + + public MyRemoteObject findByPrimaryKey(Integer primarykey) + throws javax.ejb.FinderException, java.rmi.RemoteException; + + public java.util.Collection findEmptyCollection() + throws javax.ejb.FinderException, java.rmi.RemoteException; + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/c320aa00/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyRemoteObject.java ---------------------------------------------------------------------- diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyRemoteObject.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyRemoteObject.java new file mode 100644 index 0000000..c745289 --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/MyRemoteObject.java @@ -0,0 +1,9 @@ +package org.apache.openejb.arquillian.tests.cmp; + +import java.rmi.RemoteException; + +public interface MyRemoteObject extends javax.ejb.EJBObject { + + public void doit() throws RemoteException; + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/c320aa00/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/ejb-jar.xml ---------------------------------------------------------------------- diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/ejb-jar.xml b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/ejb-jar.xml new file mode 100644 index 0000000..d9b2065 --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/ejb-jar.xml @@ -0,0 +1,54 @@ +<?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. +--> +<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + version="3.1" + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"> + <enterprise-beans> + <entity> + <ejb-name>MyCmpBean</ejb-name> + <ejb-class>org.apache.openejb.arquillian.tests.cmp.MyCmpBean</ejb-class> + <persistence-type>Container</persistence-type> + <prim-key-class>java.lang.Integer</prim-key-class> + <reentrant>false</reentrant> + <cmp-field> + <field-name>name</field-name> + </cmp-field> + <primkey-field>id</primkey-field> + <query> + <query-method> + <method-name>findByPrimaryKey</method-name> + <method-params> + <method-param>java.lang.Integer</method-param> + </method-params> + </query-method> + <ejb-ql>SELECT OBJECT(DL) FROM License DL</ejb-ql> + </query> + </entity> + </enterprise-beans> + <assembly-descriptor> + <container-transaction> + <method> + <ejb-name>MyCmpBean</ejb-name> + <method-name>*</method-name> + </method> + <trans-attribute>Supports</trans-attribute> + </container-transaction> + </assembly-descriptor> +</ejb-jar> http://git-wip-us.apache.org/repos/asf/tomee/blob/c320aa00/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/openejb-cmp-orm.xml ---------------------------------------------------------------------- diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/openejb-cmp-orm.xml b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/openejb-cmp-orm.xml new file mode 100644 index 0000000..19cf79d --- /dev/null +++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/openejb-cmp-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="org.apache.openejb.arquillian.tests.cmp.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/c320aa00/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java b/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java index b3942a0..683ca91 100644 --- a/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java +++ b/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java @@ -538,7 +538,8 @@ public class ReadDescriptors implements DynamicDeployer { return current; } - private void readCmpOrm(final EjbModule ejbModule) throws OpenEJBException { + // package scoped for testing + void readCmpOrm(final EjbModule ejbModule) throws OpenEJBException { final Object data = ejbModule.getAltDDs().get("openejb-cmp-orm.xml"); if (data != null && !(data instanceof EntityMappings)) { if (data instanceof URL) { http://git-wip-us.apache.org/repos/asf/tomee/blob/c320aa00/container/openejb-core/src/test/java/org/apache/openejb/config/ReadDescriptorsTest.java ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/java/org/apache/openejb/config/ReadDescriptorsTest.java b/container/openejb-core/src/test/java/org/apache/openejb/config/ReadDescriptorsTest.java index c8d029d..a46e9a9 100644 --- a/container/openejb-core/src/test/java/org/apache/openejb/config/ReadDescriptorsTest.java +++ b/container/openejb-core/src/test/java/org/apache/openejb/config/ReadDescriptorsTest.java @@ -19,6 +19,8 @@ package org.apache.openejb.config; import org.apache.openejb.config.sys.Resource; import org.apache.openejb.config.sys.Resources; +import org.apache.openejb.jee.EjbJar; +import org.apache.openejb.jee.jpa.EntityMappings; import org.junit.Assert; import org.junit.Test; @@ -92,4 +94,12 @@ public class ReadDescriptorsTest { Assert.assertNull(res.getProperties().getProperty("InitializeAfterDeployment")); } + @Test + public void testReadCmpOrmDescriptor() throws Exception { + final EjbModule ejbModule = new EjbModule(new EjbJar()); + ejbModule.getAltDDs().put("openejb-cmp-orm.xml", getClass().getResource("test-openejb-cmp-orm.xml")); + new ReadDescriptors().readCmpOrm(ejbModule); + Assert.assertNotNull(ejbModule.getAltDDs().get("openejb-cmp-orm.xml")); + Assert.assertTrue(EntityMappings.class.isInstance(ejbModule.getAltDDs().get("openejb-cmp-orm.xml"))); + } } http://git-wip-us.apache.org/repos/asf/tomee/blob/c320aa00/container/openejb-core/src/test/resources/org/apache/openejb/config/test-openejb-cmp-orm.xml ---------------------------------------------------------------------- diff --git a/container/openejb-core/src/test/resources/org/apache/openejb/config/test-openejb-cmp-orm.xml b/container/openejb-core/src/test/resources/org/apache/openejb/config/test-openejb-cmp-orm.xml new file mode 100644 index 0000000..f26eb72 --- /dev/null +++ b/container/openejb-core/src/test/resources/org/apache/openejb/config/test-openejb-cmp-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="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
