[jboss-cvs] JBossAS SVN: r95513 - in branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376: unit and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Oct 23 11:53:24 EDT 2009
Author: smarlow at redhat.com
Date: 2009-10-23 11:53:24 -0400 (Fri, 23 Oct 2009)
New Revision: 95513
Added:
branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/SoccerFacade.java
branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/SoccerFacadeBean.java
Modified:
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/JPAUnitTestCase.java
Log:
JBAS-7376 Implement unit tests for the jpa2 and bean validation
Modified: 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 2009-10-23 15:49:20 UTC (rev 95512)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/Soccer.java 2009-10-23 15:53:24 UTC (rev 95513)
@@ -32,4 +32,6 @@
{
void addPlayer(int id, String name, String team, int goals);
Player getPlayer(int id);
+ Player getPlayerReadLock(int id);
+ Player getPlayerOptimisticLock(int id);
}
Modified: 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 2009-10-23 15:49:20 UTC (rev 95512)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/SoccerBean.java 2009-10-23 15:53:24 UTC (rev 95513)
@@ -37,33 +37,51 @@
@PersistenceUnit
private EntityManagerFactory emf;
+ EntityManager em;
- private EntityManager em;
@PostConstruct
public void init()
{
- em = emf.createEntityManager();
+ em = emf.createEntityManager();
}
@PreDestroy
public void destroy()
{
- em.close();
+ 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);
+ em.flush();
}
-
- public Player getPlayer(int id)
+ public Player getPlayer(int id)
{
- return em.find(Player.class, id);
+ Player p = em.find(Player.class, id);
+ return p;
}
+ public Player getPlayerReadLock(int id)
+ {
+ em.joinTransaction();
+ Player p = em.find(Player.class, id);
+ if(p != null)
+ em.lock(p, LockModeType.READ);
+ return p;
+ }
+
+ public Player getPlayerOptimisticLock(int id)
+ {
+ em.joinTransaction();
+ Player p = em.find(Player.class, id);
+ if(p != null)
+ em.lock(p, LockModeType.OPTIMISTIC);
+ return p;
+ }
+
}
Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/SoccerFacade.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/SoccerFacade.java (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/SoccerFacade.java 2009-10-23 15:53:24 UTC (rev 95513)
@@ -0,0 +1,37 @@
+/*
+ * 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 SoccerFacade
+{
+ void addPlayer(int id, String name, String team, int goals);
+ Player getPlayer(int id);
+ Player getPlayerReadLock(int id);
+ Player getPlayerOptimisticLock(int id);
+}
Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/SoccerFacadeBean.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/SoccerFacadeBean.java (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/SoccerFacadeBean.java 2009-10-23 15:53:24 UTC (rev 95513)
@@ -0,0 +1,85 @@
+/*
+ * 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.naming.InitialContext;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+
+
+/**
+ * @author Scott Marlow
+ *
+ */
+ at Stateless(mappedName="ejb3/ejbthree7376/SoccerFacade")
+ at TransactionManagement(TransactionManagementType.CONTAINER)
+public class SoccerFacadeBean implements SoccerFacade
+{
+ InitialContext ctx=null;
+ Soccer stats = null;
+
+ @PostConstruct
+ public void init()
+ {
+
+ try {
+ ctx = new InitialContext();
+ stats = (Soccer) ctx.lookup("ejb3/ejbthree7376/Soccer");
+ }
+ catch(Throwable e) {
+ e.printStackTrace();
+ }
+ }
+
+ @PreDestroy
+ public void destroy()
+ {
+ ctx = null;
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRED)
+ public void addPlayer(int id, String name, String team, int goals)
+ {
+ stats.addPlayer(id, name, team, goals);
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRED)
+ public Player getPlayer(int id)
+ {
+ return stats.getPlayer(id);
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRED)
+ public Player getPlayerReadLock(int id)
+ {
+ return stats.getPlayerReadLock(id);
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRED)
+ public Player getPlayerOptimisticLock(int id)
+ {
+ return stats.getPlayerOptimisticLock(id);
+ }
+
+
+}
Modified: 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 2009-10-23 15:49:20 UTC (rev 95512)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/ejb3/ejbthree7376/unit/JPAUnitTestCase.java 2009-10-23 15:53:24 UTC (rev 95513)
@@ -28,6 +28,7 @@
import org.jboss.test.JBossTestCase;
import org.jboss.test.ejb3.ejbthree7376.Soccer;
+import org.jboss.test.ejb3.ejbthree7376.SoccerFacade;
import org.jboss.test.ejb3.ejbthree7376.Player;
@@ -53,21 +54,22 @@
{
getLog().info("testJPA start");
InitialContext ctx = this.getInitialContext();
- Soccer stats = (Soccer) ctx.lookup("ejb3/ejbthree7376/Soccer");
+ SoccerFacade stats = (SoccerFacade) ctx.lookup("ejb3/ejbthree7376/SoccerFacade");
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);
+ assertNotNull("player is null" , p);
assertEquals(p.getName(), "Heather Mitts");
assertEquals(p.getTeam(), "Boston Breakers");
getLog().info("testJPA end");
}
-
- public void testJPABeanValidation() throws Exception
+
+ public void testJPABeanValidation() throws Exception
{
getLog().info("testJPABeanValidation start");
InitialContext ctx = this.getInitialContext();
- Soccer stats = (Soccer) ctx.lookup("ejb3/ejbthree7376/Soccer");
+ SoccerFacade stats = (SoccerFacade) ctx.lookup("ejb3/ejbthree7376/SoccerFacade");
try {
stats.addPlayer(1, "Christine Lily","Boston Breakers", 9999); // should be invalid number of goals
fail("failed to throw ConstraintViolationException");
@@ -80,4 +82,38 @@
getLog().info("testJPABeanValidation ended");
}
+ public void testJPAReadLock() throws Exception
+ {
+ getLog().info("testJPA start");
+ InitialContext ctx = this.getInitialContext();
+ SoccerFacade stats = (SoccerFacade) ctx.lookup("ejb3/ejbthree7376/SoccerFacade");
+ getLog().info("testJPA about to add player");
+ stats.addPlayer(2,"Fabiana","Boston Breakers", 5); // 2009 season
+ assertNotNull("player is null", stats.getPlayer(2));
+ getLog().info("testJPA player added. About to look up player");
+ Player p = stats.getPlayerReadLock(2);
+ assertNotNull("player is null" , p);
+ assertEquals(p.getName(), "Fabiana");
+ assertEquals(p.getTeam(), "Boston Breakers");
+ getLog().info("testJPA end");
+ }
+
+ public void testJPAOptimisticLock() throws Exception
+ {
+ getLog().info("testJPA start");
+ InitialContext ctx = this.getInitialContext();
+ SoccerFacade stats = (SoccerFacade) ctx.lookup("ejb3/ejbthree7376/SoccerFacade");
+ getLog().info("testJPA about to add player");
+ stats.addPlayer(3,"Kelly Smith","Boston Breakers", 10); // 2009 season
+ assertNotNull("player is null", stats.getPlayer(3));
+ getLog().info("testJPA player added. About to look up player");
+ Player p = stats.getPlayerOptimisticLock(3);
+ assertNotNull("player is null" , p);
+ assertEquals(p.getName(), "Kelly Smith");
+ assertEquals(p.getTeam(), "Boston Breakers");
+ getLog().info("testJPA end");
+
+ }
+
+
}
More information about the jboss-cvs-commits
mailing list