[jboss-cvs] JBossAS SVN: r95444 - in branches/Branch_5_x/testsuite: src/main/org/jboss/test/ejb3 and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Oct 22 16:15:12 EDT 2009


Author: smarlow at redhat.com
Date: 2009-10-22 16:15:12 -0400 (Thu, 22 Oct 2009)
New Revision: 95444

Added:
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/Player.java
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/Soccer.java
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/SoccerBean.java
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/unit/
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/unit/JPAUnitTestCase.java
   branches/Branch_5_x/testsuite/src/resources/ejb3/ejbthree7376/
   branches/Branch_5_x/testsuite/src/resources/ejb3/ejbthree7376/META-INF/
   branches/Branch_5_x/testsuite/src/resources/ejb3/ejbthree7376/META-INF/persistence.xml
Modified:
   branches/Branch_5_x/testsuite/imports/sections/ejb3.xml
Log:
JBAS-7376 started JPA2 unit tests.

Modified: branches/Branch_5_x/testsuite/imports/sections/ejb3.xml
===================================================================
--- branches/Branch_5_x/testsuite/imports/sections/ejb3.xml	2009-10-22 20:13:44 UTC (rev 95443)
+++ branches/Branch_5_x/testsuite/imports/sections/ejb3.xml	2009-10-22 20:15:12 UTC (rev 95444)
@@ -58,6 +58,18 @@
       </jar>
    </target>
    
+
+   <target name="ejbthree7376" depends="compile">
+      <mkdir dir="${build.lib}"/>
+      <jar destfile="${build.lib}/ejbthree7376.jar">
+         <fileset dir="${build.classes}" includes="org/jboss/test/ejb3/ejbthree7376/*.class"></fileset>
+        <fileset dir="${source.resources}/ejb3/ejbthree7376" includes="**">
+	 <include name="META-INF/persistence.xml"/>
+	</fileset>
+            
+      </jar>
+   </target>
+
    <target name="ejb3-servlet" depends="compile"
       description="Builds all jar files."
       >
@@ -124,7 +136,7 @@
 	      </jar>
 	</target>
 	
-   <target name="_jars-ejb3" depends="ejb3-servlet,jbas6161,jbas6239,ejbthree1597,jbas5713,jboss51xsd">
+   <target name="_jars-ejb3" depends="ejb3-servlet,jbas6161,jbas6239,ejbthree1597,ejbthree7376,jbas5713,jboss51xsd">
       <mkdir dir="${build.lib}" />
 
       <!-- A jar with a simple ejb3 session -->

Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/Player.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/Player.java	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/Player.java	2009-10-22 20:15:12 UTC (rev 95444)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.test.ejb3.ejbthree7376;
+
+import javax.persistence.*;
+import javax.validation.constraints.Size;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.AssertTrue;
+
+ at Entity
+ at Table(name = "SOCCER_PLAYER")
+
+public class Player implements java.io.Serializable {
+
+   @Size(max=32)
+   private String name;
+
+   @Size(max=32)
+   private String team;
+
+   @Max(100)
+   private int goals;
+
+   private int id;
+
+   private int version;
+
+   public Player()
+   {
+   }
+
+   public Player(int id, String name, String team, int goals) 
+   {
+     this.id = id;
+     this.name = name;
+     this.team = team;
+     this.goals = goals;
+   }
+   
+    @Id
+    @Column(name = "ID")
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    @Version
+    @Column(name = "VERSION")
+    public int getVersion() {
+        return version;
+    }
+
+    public void setVersion(int version) {
+        this.version = version;
+    }
+
+    @Column(length = 32, name = "NAME")
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Column(length = 32, name = "TEAM")
+    public String getTeam() {
+        return team;
+    }
+
+    public void setTeam(String team) {
+        this.team = team;
+    }
+
+    @Column(name = "GOALS")
+    public int getGoals() {
+        return goals;
+    }
+
+    public void setGoals(int goals) {
+        this.goals = goals;
+    }
+
+}
+

Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/Soccer.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/Soccer.java	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/Soccer.java	2009-10-22 20:15:12 UTC (rev 95444)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.test.ejb3.ejbthree7376;
+
+import javax.ejb.Remote;
+
+/**
+ * @author Scott Marlow 
+ *
+ */
+ at Remote
+public interface Soccer 
+{
+    void addPlayer(int id, String name, String team, int goals);
+    Player getPlayer(int id);
+}

Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/SoccerBean.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/SoccerBean.java	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/SoccerBean.java	2009-10-22 20:15:12 UTC (rev 95444)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.test.ejb3.ejbthree7376;
+
+import javax.ejb.*;
+import javax.persistence.*;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+
+/**
+ * @author Scott Marlow
+ *
+ */
+ at Stateless(mappedName="ejb3/ejbthree7376/Soccer") 
+ at TransactionManagement(TransactionManagementType.CONTAINER)
+public class SoccerBean implements Soccer
+{
+ 
+   @PersistenceUnit
+   private EntityManagerFactory emf;
+
+   private EntityManager em;
+
+   @PostConstruct
+   public void init()
+   {
+     em = emf.createEntityManager();
+   }
+
+   @PreDestroy
+   public void destroy()
+   {
+     em.close();
+   }
+
+   /*TransactionAttribute(TransactionAttributeType.REQUIRED)*/
+   public void addPlayer(int id, String name, String team, int goals)
+   {
+
+     Player p = new Player(id, name, team, goals);
+     em.persist(p);
+   }
+
+
+  public Player getPlayer(int id)
+   {
+      return em.find(Player.class, id);
+   }
+
+}

Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/unit/JPAUnitTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/unit/JPAUnitTestCase.java	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/unit/JPAUnitTestCase.java	2009-10-22 20:15:12 UTC (rev 95444)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.test.ejb3.ejbthree7376.unit;
+
+import javax.naming.InitialContext;
+import javax.validation.ConstraintViolationException;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.ejb3.ejbthree7376.Soccer;
+import org.jboss.test.ejb3.ejbthree7376.Player;
+
+
+/**
+ * JPA 2 testing
+ *
+ * @author Scott Marlow
+ */
+public class JPAUnitTestCase extends JBossTestCase
+{
+
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(JPAUnitTestCase.class, "ejbthree7376.jar");
+   }
+
+   public JPAUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testJPA() throws Exception
+   {
+     getLog().info("testJPA start");
+     InitialContext ctx = this.getInitialContext();
+     Soccer stats = (Soccer) ctx.lookup("ejb3/ejbthree7376/Soccer");
+     getLog().info("testJPA about to add player");
+     stats.addPlayer(0,"Heather Mitts","Boston Breakers", 0); // 2009 season
+     getLog().info("testJPA player added.  About to look up player");
+     Player p = stats.getPlayer(0);
+     assertEquals(p.getName(), "Heather Mitts");
+     assertEquals(p.getTeam(), "Boston Breakers");
+     getLog().info("testJPA end");
+   }
+
+  public void testJPABeanValidation() throws Exception
+   {
+     getLog().info("testJPABeanValidation start");
+     InitialContext ctx = this.getInitialContext();
+     Soccer stats = (Soccer) ctx.lookup("ejb3/ejbthree7376/Soccer");
+     try {
+       stats.addPlayer(1, "Christine Lily","Boston Breakers", 9999); // should be invalid number of goals 
+       fail("failed to throw ConstraintViolationException");
+     }
+     catch(ConstraintViolationException expected)
+     {
+       // expected path
+     }
+
+     getLog().info("testJPABeanValidation ended");
+   }
+
+}

Added: branches/Branch_5_x/testsuite/src/resources/ejb3/ejbthree7376/META-INF/persistence.xml
===================================================================
--- branches/Branch_5_x/testsuite/src/resources/ejb3/ejbthree7376/META-INF/persistence.xml	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/resources/ejb3/ejbthree7376/META-INF/persistence.xml	2009-10-22 20:15:12 UTC (rev 95444)
@@ -0,0 +1,15 @@
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
+    http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
+  version="2.0">
+
+   <persistence-unit name="ejbthree7376">
+      <jta-data-source>java:/DefaultDS</jta-data-source>
+      <validation-mode>AUTO</validation-mode>
+      <properties>
+       <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+      </properties>
+   </persistence-unit>
+
+</persistence>




More information about the jboss-cvs-commits mailing list