[jboss-cvs] JBossAS SVN: r63777 - in trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity: unit and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jul 2 12:32:34 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-07-02 12:32:33 -0400 (Mon, 02 Jul 2007)
New Revision: 63777

Added:
   trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/BulkOperationsTest.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/BulkOperationsTestBean.java
   trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/BulkOperationsUnitTestCase.java
Log:
Port the BulkOperationsTest from Branch_4_2

Copied: trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/BulkOperationsTest.java (from rev 62740, branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/BulkOperationsTest.java)
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/BulkOperationsTest.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/BulkOperationsTest.java	2007-07-02 16:32:33 UTC (rev 63777)
@@ -0,0 +1,46 @@
+/*
+ * 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.clusteredentity;
+
+import java.util.List;
+
+/**
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+public interface BulkOperationsTest
+{
+   void createContacts();
+   
+   int deleteContacts();
+   
+   int updateContacts(String name, String newTLF);
+   
+   List<Integer> getContactsByCustomer(String customerName);
+   
+   List<Integer> getContactsByTLF(String tlf);
+   
+   Contact getContact(Integer id);
+   
+   void remove();
+}

Copied: trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/BulkOperationsTestBean.java (from rev 62740, branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/BulkOperationsTestBean.java)
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/BulkOperationsTestBean.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/BulkOperationsTestBean.java	2007-07-02 16:32:33 UTC (rev 63777)
@@ -0,0 +1,159 @@
+/*
+ * 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.clusteredentity;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.ejb.Remote;
+import javax.ejb.Remove;
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.FlushModeType;
+import javax.persistence.PersistenceContext;
+
+/**
+ * @author Brian Stansberry
+ * @version $Revision$
+ */
+ at Stateless
+ at Remote(BulkOperationsTest.class)
+public class BulkOperationsTestBean implements BulkOperationsTest
+{
+   @PersistenceContext
+   private EntityManager manager;
+   
+   
+   public void createContacts()
+   {
+      for (int i = 0; i < 10; i++)
+         createCustomer(i);
+   }
+
+   public int deleteContacts()
+   {
+      String deleteHQL = "delete Contact where customer in ";
+      deleteHQL += " (select customer FROM Customer as customer ";
+      deleteHQL += " where customer.name = :cName)";
+
+      int rowsAffected = manager.createQuery(deleteHQL)
+                                .setFlushMode(FlushModeType.AUTO)
+                                .setParameter("cName", "Red Hat")
+                                .executeUpdate();
+      return rowsAffected;
+   }
+   
+   public List<Integer> getContactsByCustomer(String customerName)
+   {
+      String selectHQL = "select contact.id from Contact contact";
+      selectHQL += " where contact.customer.name = :cName";
+   
+      List results = manager.createQuery(selectHQL)
+                            .setFlushMode(FlushModeType.AUTO)
+                            .setParameter("cName", customerName)
+                            .getResultList();
+      
+      return results;      
+   }
+   
+   public List<Integer> getContactsByTLF(String tlf)
+   {
+      String selectHQL = "select contact.id from Contact contact";
+      selectHQL += " where contact.tlf = :cTLF";
+   
+      List results = manager.createQuery(selectHQL)
+                            .setFlushMode(FlushModeType.AUTO)
+                            .setParameter("cTLF", tlf)
+                            .getResultList();
+      
+      return results;      
+   }
+
+   public int updateContacts(String name, String newTLF)
+   {
+      String updateHQL = "update Contact set tlf = :cNewTLF where name = :cName";
+
+      int rowsAffected = manager.createQuery(updateHQL)
+                                .setFlushMode(FlushModeType.AUTO)
+                                .setParameter("cNewTLF", newTLF)
+                                .setParameter("cName", name)
+                                .executeUpdate();
+      return rowsAffected;
+   }
+   
+   public Contact getContact(Integer id)
+   {
+      return manager.find(Contact.class, id);
+   }
+   
+   @Remove
+   public void remove()
+   {
+      
+   }
+   
+   private Customer createCustomer(int id)
+   {
+      System.out.println("CREATE CUSTOMER " + id);
+      try
+      {
+         Customer customer = new Customer();
+         customer.setId(id);
+         customer.setName((id % 2 == 0) ? "JBoss" : "Red Hat");
+         Set<Contact> contacts = new HashSet<Contact>();
+         
+         Contact kabir = new Contact();
+         kabir.setId(1000 + id);
+         kabir.setCustomer(customer);
+         kabir.setName("Kabir");
+         kabir.setTlf("1111");
+         contacts.add(kabir);
+         
+         Contact bill = new Contact();
+         bill.setId(2000 +id);
+         bill.setCustomer(customer);
+         bill.setName("Bill");
+         bill.setTlf("2222");
+         contacts.add(bill);
+
+         customer.setContacts(contacts);
+
+         manager.persist(customer);
+         return customer;
+      }
+      catch (RuntimeException e)
+      {
+         throw e;
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+      finally
+      {
+         System.out.println("CREATE CUSTOMER " +  id + " -  END");         
+      }
+   }
+
+}

Copied: trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/BulkOperationsUnitTestCase.java (from rev 62740, branches/Branch_4_2/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/BulkOperationsUnitTestCase.java)
===================================================================
--- trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/BulkOperationsUnitTestCase.java	                        (rev 0)
+++ trunk/ejb3/src/test/org/jboss/ejb3/test/clusteredentity/unit/BulkOperationsUnitTestCase.java	2007-07-02 16:32:33 UTC (rev 63777)
@@ -0,0 +1,117 @@
+/*
+ * 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.clusteredentity.unit;
+
+import java.util.List;
+import java.util.Properties;
+
+import javax.naming.InitialContext;
+
+import junit.framework.Test;
+
+import org.jboss.ejb3.test.clusteredentity.BulkOperationsTest;
+import org.jboss.ejb3.test.clusteredentity.Contact;
+import org.jboss.test.JBossClusteredTestCase;
+
+/**
+ * Sample client for the jboss container.
+ *
+ * @author Brian Stansberry
+ * @version $Id: EntityUnitTestCase.java 60697 2007-02-20 05:08:31Z bstansberry at jboss.com $
+ */
+public class BulkOperationsUnitTestCase
+extends JBossClusteredTestCase
+{
+   public BulkOperationsUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testBulkOperations() throws Exception
+   {
+      System.out.println("*** testBulkOperations()");
+      String node0 = System.getProperty("jbosstest.cluster.node0");
+        
+      Properties prop0 = new Properties();
+      prop0.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+      prop0.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
+      prop0.put("java.naming.provider.url", "jnp://" + node0 + ":1099");
+      
+      System.out.println("===== Node0 properties: ");
+      System.out.println(prop0);
+      
+      System.out.println("Lookup node 0");
+      InitialContext ctx0 = new InitialContext(prop0);
+      
+      BulkOperationsTest tester = (BulkOperationsTest) ctx0.lookup("BulkOperationsTestBean/remote");
+      
+      try
+      {
+         tester.createContacts();
+         
+         List<Integer> rhContacts = tester.getContactsByCustomer("Red Hat");
+         assertNotNull("Red Hat contacts exist", rhContacts);
+         assertEquals("Created expected number of Red Hat contacts", 10, rhContacts.size());
+         
+         assertEquals("Deleted all Red Hat contacts", 10, tester.deleteContacts());
+         
+         List<Integer> jbContacts = tester.getContactsByCustomer("JBoss");
+         assertNotNull("JBoss contacts exist", jbContacts);
+         assertEquals("JBoss contacts remain", 10, jbContacts.size());
+         
+         for (Integer id : rhContacts)
+         {
+            assertNull("Red Hat contact " + id + " cannot be retrieved",
+                       tester.getContact(id));
+         }
+         rhContacts = tester.getContactsByCustomer("Red Hat");
+         if (rhContacts != null)
+         {
+            assertEquals("No Red Hat contacts remain", 0, rhContacts.size());
+         }
+         
+         tester.updateContacts("Kabir", "Updated");
+         for (Integer id : jbContacts)
+         {
+            Contact contact = tester.getContact(id);
+            assertNotNull("JBoss contact " + id + " exists", contact);
+            String expected = ("Kabir".equals(contact.getName())) ? "Updated" : "2222";
+            assertEquals("JBoss contact " + id + " has correct TLF",
+                         expected, contact.getTlf());
+         }
+         
+         List<Integer> updated = tester.getContactsByTLF("Updated");
+         assertNotNull("Got updated contacts", updated);
+         assertEquals("Updated contacts", 5, updated.size());
+      }
+      finally
+      {
+         // cleanup the db so we can run this test multiple times w/o restarting the cluster
+         tester.remove();
+      }
+   }
+   
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(BulkOperationsUnitTestCase.class, "clusteredentity-test.jar");
+   }
+}




More information about the jboss-cvs-commits mailing list