Java Source Code: org.jboss.cmp2.crimeportal.CrimePortalTearDown


   1: package org.jboss.cmp2.crimeportal;
   2: 
   3: import java.util.Iterator;
   4: import javax.naming.InitialContext;
   5: import javax.ejb.EJBLocalObject;
   6: 
   7: import junit.framework.Test;
   8: import junit.framework.TestSuite;
   9: import org.jboss.test.util.ejb.EJBTestCase;
  10: 
  11: public class CrimePortalTearDown extends EJBTestCase
  12:	  {
  13:   public static Test suite()
  14:	     {
  15:      TestSuite testSuite = new TestSuite("CrimePortalTearDown");
  16:      testSuite.addTestSuite(CrimePortalTearDown.class);
  17:      return testSuite;
  18:   }
  19:
  20:   public CrimePortalTearDown(String name)
  21:	     {
  22:      super(name);
  23:   }
  24:
  25:   public void testTearDown() throws Exception
  26:	     {
  27:      InitialContext jndi = new InitialContext();
  28:
  29:      // delete all organizations
  30:      OrganizationHome organizationHome =
  31:         (OrganizationHome) jndi.lookup("crimeportal/Organization");
  32:      Iterator organizations = organizationHome.findAll().iterator();
  33:      while (organizations.hasNext())
  34:	        {
  35:         EJBLocalObject ejb = (EJBLocalObject) organizations.next();
  36:         ejb.remove();
  37:      }
  38:
  39:      // delete all gangsters (should be cascade-deleted, but be safe)
  40:      GangsterHome gangsterHome =
  41:         (GangsterHome) jndi.lookup("crimeportal/Gangster");
  42:      Iterator gangsters = gangsterHome.findAll().iterator();
  43:      while (gangsters.hasNext())
  44:	        {
  45:         EJBLocalObject ejb = (EJBLocalObject) gangsters.next();
  46:         ejb.remove();
  47:      }
  48:
  49:      // delete all jobs
  50:      JobHome jobHome = (JobHome) jndi.lookup("crimeportal/Job");
  51:      Iterator jobs = jobHome.findAll().iterator();
  52:      while (jobs.hasNext())
  53:	        {
  54:         EJBLocalObject ejb = (EJBLocalObject) jobs.next();
  55:         ejb.remove();
  56:      }
  57:
  58:      // delete all locations (should be cascade-deleted, but be safe)
  59:      LocationHome locationHome =
  60:         (LocationHome) jndi.lookup("crimeportal/Location");
  61:      Iterator locations = locationHome.findAll().iterator();
  62:      while (locations.hasNext())
  63:	        {
  64:         EJBLocalObject ejb = (EJBLocalObject) locations.next();
  65:         ejb.remove();
  66:      }
  67:   }
  68:}