KickJava   Java API By Example, From Geeks To Geeks.

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


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 CrimePortalSetUp extends EJBTestCase
16       implements CrimePortalTestConstants {
17
18    public static Test suite() {
19       TestSuite testSuite = new TestSuite("CrimePortalSetUp");
20       testSuite.addTestSuite(CrimePortalSetUp.class);
21       return testSuite;
22    }
23
24    public CrimePortalSetUp(String JavaDoc name) {
25       super(name);
26    }
27
28
29    /**
30     * Looks up all of the home interfaces and creates the initial data.
31     * @throws Exception if a problem occures while finding the home interfaces,
32     * or if an problem occures while createing the initial data
33     */

34    public void testSetUp() throws Exception JavaDoc {
35       InitialContext JavaDoc jndi = new InitialContext JavaDoc();
36
37       OrganizationHome organizationHome =
38             (OrganizationHome) jndi.lookup("crimeportal/Organization");
39
40       GangsterHome gangsterHome =
41             (GangsterHome) jndi.lookup("crimeportal/Gangster");
42
43       JobHome jobHome = (JobHome) jndi.lookup("crimeportal/Job");
44
45       // Create some organizations
46
Organization yakuza =
47             organizationHome.create("Yakuza", "Japanese Gangsters");
48       Organization mafia =
49             organizationHome.create("Mafia", "Italian Bad Guys");
50       Organization triads =
51             organizationHome.create("Triads", "Kung Fu Movie Extras");
52
53       // Create some gangsters
54
Gangster yojimbo = gangsterHome.create(YOJIMBO, "Yojimbo", "Bodyguard");
55       yojimbo.setBadness(7);
56       yojimbo.setOrganization(yakuza);
57
58       Gangster takeshi = gangsterHome.create(TAKESHI, "Takeshi", "Master");
59       takeshi.setBadness(10);
60       takeshi.setOrganization(yakuza);
61
62       Gangster yuriko = gangsterHome.create(YURIKO, "Yuriko", "Four finger");
63       yuriko.setBadness(4);
64       yuriko.setOrganization(yakuza);
65
66       Gangster chow = gangsterHome.create(CHOW, "Chow", "Killer");
67       chow.setBadness(9);
68       chow.setOrganization(triads);
69
70       Gangster shogi = gangsterHome.create(SHOGI, "Shogi", "Lightning");
71       shogi.setBadness(8);
72       shogi.setOrganization(triads);
73       
74       Gangster valentino =
75             gangsterHome.create(VALENTINO, "Valentino", "Pizza-Face");
76       valentino.setBadness(4);
77       valentino.setOrganization(mafia);
78
79       Gangster toni = gangsterHome.create(TONI, "Toni", "Toohless");
80       toni.setBadness(2);
81       toni.setOrganization(mafia);
82
83       Gangster corleone =
84             gangsterHome.create(CORLEONE, "Corleone", "Godfather");
85       corleone.setBadness(6);
86       corleone.setOrganization(mafia);
87
88       // Assign the bosses
89
yakuza.setTheBoss(takeshi);
90       triads.setTheBoss(chow);
91       mafia.setTheBoss(corleone);
92
93       // Create some jobs
94
Job jewler = jobHome.create("10th Street Jeweler Heist");
95       jewler.setScore(5000);
96       jewler.setSetupCost(50);
97       
98       Job train = jobHome.create("The Greate Train Robbery");
99       train.setScore(2000000);
100       train.setSetupCost(500000);
101
102       Job liquorStore = jobHome.create("Cheap Liquor Snatch and Grab");
103       liquorStore.setScore(50);
104       liquorStore.setSetupCost(0);
105
106       // assign some gangsters to the jobs
107
jewler.getGangsters().add(valentino);
108       jewler.getGangsters().add(corleone);
109       
110       train.getGangsters().add(yojimbo);
111       train.getGangsters().add(chow);
112
113       liquorStore.getGangsters().add(chow);
114    }
115 }
116
Popular Tags