1 package org.jboss.docs.cmp2.crimeportal; 2 3 import java.util.Collection ; 4 import java.util.HashSet ; 5 import java.util.Set ; 6 import java.util.Iterator ; 7 import javax.naming.InitialContext ; 8 import javax.ejb.EJBLocalObject ; 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 name) { 25 super(name); 26 } 27 28 private OrganizationHome organizationHome; 29 private GangsterHome gangsterHome; 30 private JobHome jobHome; 31 32 39 public void setUp() throws Exception { 40 InitialContext jndi = new InitialContext (); 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 51 public void testOrganization() throws Exception { 52 Organization yakuza = organizationHome.findByPrimaryKey("Yakuza"); 53 Collection 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 61 public void testFindBadDudes() throws Exception { 62 Collection 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 78 public void testSelectBoss() throws Exception { 79 Set 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 |