1 22 package org.jboss.ejb3.test.manytomany.unit; 23 24 import java.util.Set ; 25 import org.jboss.ejb3.test.manytomany.Address; 26 import org.jboss.ejb3.test.manytomany.Company; 27 import org.jboss.ejb3.test.manytomany.Customer; 28 import org.jboss.ejb3.test.manytomany.EntityTest; 29 import org.jboss.ejb3.test.manytomany.Flight; 30 import org.jboss.ejb3.test.manytomany.Ticket; 31 import org.jboss.test.JBossTestCase; 32 import junit.framework.Test; 33 34 40 41 public class EntityUnitTestCase 42 extends JBossTestCase 43 { 44 org.jboss.logging.Logger log = getLog(); 45 46 static boolean deployed = false; 47 static int test = 0; 48 49 public EntityUnitTestCase(String name) 50 { 51 52 super(name); 53 54 } 55 56 public void testOneToMany() throws Exception 57 { 58 EntityTest test = (EntityTest) this.getInitialContext().lookup("EntityTestBean/remote"); 59 Customer c = test.oneToManyCreate(); 60 assertNotNull(c); 61 assertNotNull(c.getTickets()); 62 Set <Ticket> tickets = c.getTickets(); 63 assertTrue(tickets.size() > 0); 64 65 c = test.findCustomerById(c.getId()); 67 assertNotNull(c); 68 assertNotNull(c.getTickets()); 69 tickets = c.getTickets(); 70 assertTrue(tickets.size() > 0); 71 72 Address address = c.getAddress(); 74 assertTrue(address != null); 75 assertTrue(address.getCity().equals("Boston")); 76 } 77 78 public void testManyToOne() throws Exception 79 { 80 EntityTest test = (EntityTest) this.getInitialContext().lookup("EntityTestBean/remote"); 81 Flight f = test.manyToOneCreate(); 82 f = test.findFlightById(f.getId()); 83 assertTrue(f.getName().equals("AF0101")); 84 assertTrue(f.getCompany().getName().equals("Air France")); 85 86 Company c = test.findCompanyById(f.getCompany().getId()); 87 assertTrue(c != null); 88 assertTrue(c.getFlights().size() == 1); 89 } 90 91 public void testManyToMany() throws Exception 92 { 93 EntityTest test = (EntityTest) this.getInitialContext().lookup("EntityTestBean/remote"); 94 test.manyToManyCreate(); 95 96 Flight one = test.findFlightById(new Long (1)); 97 assertTrue(one.getCompany().getName().equals("Air France")); 98 99 Flight two = test.findFlightById(new Long (2)); 100 assertTrue(two.getCompany().getName().equals("USAir")); 101 102 System.out.println("Air France customers"); 103 for (Customer c : one.getCustomers()) 104 { 105 System.out.println(c.getName()); 106 107 } 108 System.out.println("USAir customers"); 109 110 for (Customer c : two.getCustomers()) 111 { 112 System.out.println(c.getName()); 113 } 114 115 } 116 117 public static Test suite() throws Exception 118 { 119 return getDeploySetup(EntityUnitTestCase.class, "manytomany-test.jar"); 120 } 121 122 } 123 | Popular Tags |