[jboss-cvs] JBossAS SVN: r70455 - in branches/JBPAPP_4_2_0_GA_CP/ejb3: src/resources/test and 9 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Mar 5 17:28:18 EST 2008
Author: bdecoste
Date: 2008-03-05 17:28:17 -0500 (Wed, 05 Mar 2008)
New Revision: 70455
Added:
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test-configs/externalpersistenceunit/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test-configs/externalpersistenceunit/conf/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test-configs/externalpersistenceunit/conf/META-INF/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test-configs/externalpersistenceunit/conf/META-INF/persistence.xml
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/externalpersistenceunit/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/externalpersistenceunit/META-INF/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/externalpersistenceunit/META-INF/persistence.xml
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/Entity1.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/EntityTest.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/EntityTestBean.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/JPATestBean.java
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/unit/
branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/unit/ExternalPUTestCase.java
Modified:
branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
Log:
[JBPAPP-666] test for external persistence.xml with straight JPA
Modified: branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml 2008-03-05 20:54:46 UTC (rev 70454)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/build-test.xml 2008-03-05 22:28:17 UTC (rev 70455)
@@ -2481,6 +2481,25 @@
</zipfileset>
</ear>
</target>
+
+ <target name="externalpersistenceunit"
+ description="Builds all jar files."
+ depends="compile-classes">
+
+ <mkdir dir="${build.lib}"/>
+
+ <jar jarfile="${build.lib}/externalpersistenceunit-test.jar">
+ <fileset dir="${build.classes}">
+ <include name="org/jboss/ejb3/test/externalpersistenceunit/*.class"/>
+ </fileset>
+ </jar>
+
+ <jar jarfile="${build.lib}/externalpersistenceunit-pu.jar">
+ <fileset dir="${resources}/test/externalpersistenceunit">
+ <include name="META-INF/persistence.xml"/>
+ </fileset>
+ </jar>
+ </target>
<target name="mdbtransactions"
description="Builds all jar files."
@@ -3679,7 +3698,7 @@
ejbthree959, ejbthree963, ejbthree994, ejbthree1023, ejbthree1025, ejbthree1062,
jbas4489, epcpropagation, jaccpropagation,
aspectdomain, ejbcontext, schema, mail, scopedclassloader, dependency, jaxws,
- pkg, securitydomain, enventry,
+ pkg, securitydomain, enventry, externalpersistenceunit,
jms/managed, naming, bmt, jca/inflowmdb, pool, jms, security, reference21_30, factory, dd/web, txexceptions,
exception, dd/override, stateless, dd/mdb, bank, dd, longlived, xmlcfg, hbm, regressionHHH275,
entityexception, asynchronous, consumer, clusteredentity, secondary, stateful, service, lob, cache, initial,
@@ -3980,6 +3999,7 @@
<antcall target="invoker-test" inheritRefs="true"/>
<antcall target="iiop-tests" inheritRefs="true"/>
<antcall target="libdeployment-test" inheritRefs="true"/>
+ <antcall target="externalpersistenceunit-test" inheritRefs="true"/>
<antcall target="multi-instance-localfromremote-test" inheritRefs="true"/>
<antcall target="statelesscreation-test" inheritRefs="true"/>
<antcall target="removedislocal-test" inheritRefs="true"/>
@@ -4454,6 +4474,26 @@
<stop-jboss jboss.dist="${ejb3.dist}"/>
<wait-on-shutdown conf="libdeployment"/>
</target>
+
+ <target name="externalpersistenceunit-test" depends="init">
+ <create-config baseconf="all" newconf="externalpersistenceunit" jboss.dist="${ejb3.dist}">
+ <patternset>
+ <include name="conf/**"/>
+ <include name="deploy*/**"/>
+ <include name="lib/**"/>
+ </patternset>
+ </create-config>
+
+ <start-jboss conf="externalpersistenceunit" host="${node0}" jboss.dist="${ejb3.dist}" jvmargs="${ejb3.jboss.jvmargs}"/>
+ <wait-on-host/>
+
+ <antcall target="test" inheritRefs="true">
+ <param name="test" value="externalpersistenceunit"/>
+ </antcall>
+
+ <stop-jboss jboss.dist="${ejb3.dist}"/>
+ <wait-on-shutdown conf="externalpersistenceunit"/>
+ </target>
<target name="mdbsessionpoolclear-test" depends="init">
<create-config baseconf="all" newconf="mdbsessionpoolclear" jboss.dist="${ejb3.dist}">
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/externalpersistenceunit/META-INF/persistence.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/externalpersistenceunit/META-INF/persistence.xml (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test/externalpersistenceunit/META-INF/persistence.xml 2008-03-05 22:28:17 UTC (rev 70455)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence>
+ <persistence-unit name="Entity1">
+ <jta-data-source>java:/DefaultDS</jta-data-source>
+ <properties>
+ <property name="hibernate.hbm2ddl.auto" value="create"/>
+ <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
+ <property name="hibernate.transaction.factory_class" value="org.hibernate.ejb.transaction.JoinableCMTTransactionFactory" />
+ <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />
+ </properties>
+ <class>org.jboss.ejb3.test.externalpersistenceunit.Entity1</class>
+ </persistence-unit>
+</persistence>
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test-configs/externalpersistenceunit/conf/META-INF/persistence.xml
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test-configs/externalpersistenceunit/conf/META-INF/persistence.xml (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/resources/test-configs/externalpersistenceunit/conf/META-INF/persistence.xml 2008-03-05 22:28:17 UTC (rev 70455)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence>
+ <persistence-unit name="Entity1">
+ <jta-data-source>java:/DefaultDS</jta-data-source>
+ <properties>
+ <property name="hibernate.hbm2ddl.auto" value="create"/>
+ <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
+ <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
+ <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />
+ <property name="hibernate.jndi.java.naming.factory.initial" value="org.jnp.interfaces.NamingContextFactory" />
+ <property name="hibernate.jndi.java.naming.factory.url.pkgs" value="org.jboss.naming:org.jnp.interfaces" />
+ <property name="hibernate.bytecode.use_reflection_optimizer" value="false" />
+ </properties>
+ <class>org.jboss.ejb3.test.externalpersistenceunit.Entity1</class>
+ </persistence-unit>
+</persistence>
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/Entity1.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/Entity1.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/Entity1.java 2008-03-05 22:28:17 UTC (rev 70455)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.externalpersistenceunit;
+
+import javax.persistence.Entity;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Entity
+ at Table(name = "ENTITY1")
+ at NamedQueries({
+ @NamedQuery(name = "findAll", query = "from Entity1")
+ })
+public class Entity1 implements java.io.Serializable
+{
+ public static final String FIND_ALL = "findAll";
+
+ private Long id;
+ private String data;
+
+ @Id
+ @GeneratedValue(strategy= GenerationType.IDENTITY)
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ public String getData()
+ {
+ return data;
+ }
+
+ public void setData(String data)
+ {
+ this.data = data;
+ }
+
+ public String toString()
+ {
+ return "Entity1:id=" + id + ",data=" + data;
+ }
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/EntityTest.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/EntityTest.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/EntityTest.java 2008-03-05 22:28:17 UTC (rev 70455)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.externalpersistenceunit;
+
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public interface EntityTest
+{
+ Long persistEntity1(Entity1 entity1);
+ Entity1 loadEntity1(Long id);
+ void remove();
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/EntityTestBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/EntityTestBean.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/EntityTestBean.java 2008-03-05 22:28:17 UTC (rev 70455)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.externalpersistenceunit;
+
+import org.jboss.logging.Logger;
+
+import javax.ejb.Remote;
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateful
+ at Remote(EntityTest.class)
+public class EntityTestBean implements EntityTest
+{
+ private static final Logger log = Logger.getLogger(EntityTestBean.class);
+
+ private @PersistenceContext(unitName="Entity1") EntityManager manager;
+
+ public Long persistEntity1(Entity1 entity1)
+ {
+ manager.persist(entity1);
+ return entity1.getId();
+ }
+
+ public Entity1 loadEntity1(Long id)
+ {
+ return manager.find(Entity1.class, id);
+ }
+
+ @Remove
+ public void remove()
+ {
+
+ }
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/JPATestBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/JPATestBean.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/JPATestBean.java 2008-03-05 22:28:17 UTC (rev 70455)
@@ -0,0 +1,116 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.externalpersistenceunit;
+
+import java.util.HashMap;
+
+import javax.annotation.Resource;
+import javax.ejb.Remote;
+import javax.ejb.Remove;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import javax.transaction.UserTransaction;
+
+import org.jboss.logging.Logger;
+
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+ at Stateful
+ at Remote(EntityTest.class)
+ at TransactionManagement(TransactionManagementType.BEAN)
+public class JPATestBean implements EntityTest
+{
+ private static final Logger log = Logger.getLogger(JPATestBean.class);
+
+ @Resource UserTransaction tx;
+
+ protected EntityManagerFactory factory = Persistence.createEntityManagerFactory("Entity1");
+ protected EntityManager manager = factory.createEntityManager();
+
+ public Long persistEntity1(Entity1 entity1)
+ {
+ try
+ {
+ tx.begin();
+ manager.joinTransaction();
+
+ manager.persist(entity1);
+ tx.commit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ try
+ {
+ tx.rollback();
+ }
+ catch (Exception se)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ return entity1.getId();
+ }
+
+ public Entity1 loadEntity1(Long id)
+ {
+ Entity1 entity1 = null;
+
+ try
+ {
+ tx.begin();
+ manager.joinTransaction();
+
+ entity1 = manager.find(Entity1.class, id);
+
+ tx.commit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ try
+ {
+ tx.rollback();
+ }
+ catch (Exception se)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ return entity1;
+ }
+
+ @Remove
+ public void remove()
+ {
+ manager.close();
+ factory.close();
+ }
+}
Added: branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/unit/ExternalPUTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/unit/ExternalPUTestCase.java (rev 0)
+++ branches/JBPAPP_4_2_0_GA_CP/ejb3/src/test/org/jboss/ejb3/test/externalpersistenceunit/unit/ExternalPUTestCase.java 2008-03-05 22:28:17 UTC (rev 70455)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.externalpersistenceunit.unit;
+
+import org.jboss.ejb3.test.externalpersistenceunit.Entity1;
+import org.jboss.ejb3.test.externalpersistenceunit.EntityTest;
+
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossTestCase;
+import junit.framework.Test;
+
+/**
+ * @author <a href="mailto:bdecoste at jboss.com">William DeCoste</a>
+ */
+public class ExternalPUTestCase
+extends JBossTestCase
+{
+ private static final Logger log = Logger.getLogger(ExternalPUTestCase.class);
+
+ public ExternalPUTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testJPAPersistenceUnits() throws Exception
+ {
+ EntityTest test = (EntityTest) getInitialContext().lookup("JPATestBean/remote");
+
+ Entity1 entity1 = new Entity1();
+ entity1.setData("ONE");
+ Long id1 = test.persistEntity1(entity1);
+
+ entity1 = test.loadEntity1(id1);
+ assertEquals("ONE", entity1.getData());
+
+ test.remove();
+
+ System.out.println("************ sleeping ...");
+ Thread.sleep(60 * 1000);
+
+ test = (EntityTest) getInitialContext().lookup("JPATestBean/remote");
+
+ entity1 = new Entity1();
+ entity1.setData("TWO");
+ id1 = test.persistEntity1(entity1);
+ }
+
+ public void atestEJB3PersistenceUnits() throws Exception
+ {
+ EntityTest test = (EntityTest) getInitialContext().lookup("EntityTestBean/remote");
+
+ Entity1 entity1 = new Entity1();
+ entity1.setData("ONE");
+ Long id1 = test.persistEntity1(entity1);
+
+ entity1 = test.loadEntity1(id1);
+ assertEquals("ONE", entity1.getData());
+ }
+
+ public static Test suite() throws Exception
+ {
+// return getDeploySetup(ExternalPUTestCase.class, "externalpersistenceunit-pu.jar, externalpersistenceunit-test.jar");
+ return getDeploySetup(ExternalPUTestCase.class, "externalpersistenceunit-test.jar");
+ }
+
+}
More information about the jboss-cvs-commits
mailing list