KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > docs > cmp2 > crimeportal > CrimePortalTearDown


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