KickJava   Java API By Example, From Geeks To Geeks.

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


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 CrimePortalTest extends EJBTestCase
16       implements CrimePortalTestConstants {
17
18    public static Test suite() {
19       TestSuite testSuite = new TestSuite("CrimePortalTest");
20       testSuite.addTestSuite(CrimePortalTest.class);
21       return testSuite;
22    }
23
24    public CrimePortalTest(String JavaDoc name) {
25       super(name);
26    }
27
28    private OrganizationHome organizationHome;
29    private GangsterHome gangsterHome;
30    private JobHome jobHome;
31
32    /**
33     * Looks up all of the home interfaces and creates the initial data.
34     * Looking up objects in JNDI is expensive, so it should be done once
35     * and cached.
36     * @throws Exception if a problem occures while finding the home interfaces,
37     * or if an problem occures while createing the initial data
38     */

39    public void setUp() throws Exception JavaDoc {
40       InitialContext JavaDoc jndi = new InitialContext JavaDoc();
41
42       organizationHome =
43             (OrganizationHome) jndi.lookup("crimeportal/Organization");
44
45       gangsterHome = (GangsterHome) jndi.lookup("crimeportal/Gangster");
46
47       jobHome = (JobHome) jndi.lookup("crimeportal/Job");
48    }
49
50    /** Test Organization-Gangster relationship */
51    public void testOrganization() throws Exception JavaDoc {
52       Organization yakuza = organizationHome.findByPrimaryKey("Yakuza");
53       Collection JavaDoc gangsters = yakuza.getMemberGangsters();
54       assertEquals(3, gangsters.size());
55       assertTrue(gangsters.contains(gangsterHome.findByPrimaryKey(YOJIMBO)));
56       assertTrue(gangsters.contains(gangsterHome.findByPrimaryKey(TAKESHI)));
57       assertTrue(gangsters.contains(gangsterHome.findByPrimaryKey(YURIKO)));
58    }
59
60    /** Test find bad dudes query */
61    public void testFindBadDudes() throws Exception JavaDoc {
62       Collection JavaDoc gangsters = gangsterHome.findBadDudes(5);
63       assertEquals(5, gangsters.size());
64
65       assertTrue(gangsters.contains(
66             gangsterHome.findByPrimaryKey(TAKESHI)));
67       assertTrue(gangsters.contains(
68             gangsterHome.findByPrimaryKey(CHOW)));
69       assertTrue(gangsters.contains(
70             gangsterHome.findByPrimaryKey(SHOGI)));
71       assertTrue(gangsters.contains(
72             gangsterHome.findByPrimaryKey(YOJIMBO)));
73       assertTrue(gangsters.contains(
74             gangsterHome.findByPrimaryKey(CORLEONE)));
75    }
76
77    /** Test select boss query */
78    public void testSelectBoss() throws Exception JavaDoc {
79       Set JavaDoc gangsters = gangsterHome.selectBoss(" Yojimbo ");
80       assertEquals(1, gangsters.size());
81       assertTrue(gangsters.contains(gangsterHome.findByPrimaryKey(TAKESHI)));
82
83       gangsters = gangsterHome.selectBoss(" Takeshi ");
84       assertEquals(1, gangsters.size());
85       assertTrue(gangsters.contains(gangsterHome.findByPrimaryKey(TAKESHI)));
86
87       gangsters = gangsterHome.selectBoss("non-existant");
88       assertEquals(0, gangsters.size());
89    }
90 }
91
Popular Tags