1 22 package org.jboss.ejb3.test.composite.unit; 23 24 import java.util.Set ; 25 import org.jboss.ejb3.test.composite.Customer; 26 import org.jboss.ejb3.test.composite.EntityTest; 27 import org.jboss.ejb3.test.composite.FieldCustomer; 28 import org.jboss.ejb3.test.composite.FieldFlight; 29 import org.jboss.ejb3.test.composite.FieldTicket; 30 import org.jboss.ejb3.test.composite.Flight; 31 import org.jboss.ejb3.test.composite.Ticket; 32 import org.jboss.test.JBossTestCase; 33 import junit.framework.Test; 34 35 41 42 public class EntityUnitTestCase 43 extends JBossTestCase 44 { 45 org.jboss.logging.Logger log = getLog(); 46 47 static boolean deployed = false; 48 static int test = 0; 49 50 public EntityUnitTestCase(String name) 51 { 52 53 super(name); 54 55 } 56 57 public void testOneToMany() throws Exception 58 { 59 EntityTest test = (EntityTest) this.getInitialContext().lookup("EntityTestBean/remote"); 60 Customer c = test.oneToManyCreate("Bill"); 61 assertNotNull(c); 62 assertNotNull(c.getTickets()); 63 Set <Ticket> tickets = c.getTickets(); 64 assertTrue(tickets.size() > 0); 65 66 c = test.findCustomerByPk(c.getPk()); 68 assertNotNull(c); 69 assertNotNull(c.getTickets()); 70 tickets = c.getTickets(); 71 assertTrue(tickets.size() > 0); 72 assertEquals("Bill", c.getName()); 73 74 } 75 76 public void testManyToOne() throws Exception 77 { 78 EntityTest test = (EntityTest) this.getInitialContext().lookup("EntityTestBean/remote"); 79 Flight f = test.manyToOneCreate(); 80 f = test.findFlightById(f.getId()); 81 assertTrue(f.getName().equals("AF0101")); 82 } 83 84 public void testManyToMany() throws Exception 85 { 86 EntityTest test = (EntityTest) this.getInitialContext().lookup("EntityTestBean/remote"); 87 test.manyToManyCreate(); 88 89 Flight one = test.findFlightById(new Long (1)); 90 Flight two = test.findFlightById(new Long (2)); 91 92 System.out.println("Air France customers"); 93 for (Customer c : one.getCustomers()) 94 { 95 System.out.println(c.getName()); 96 97 } 98 System.out.println("USAir customers"); 99 100 for (Customer c : two.getCustomers()) 101 { 102 System.out.println(c.getName()); 103 } 104 105 } 106 107 public void testFieldOneToMany() throws Exception 108 { 109 EntityTest test = (EntityTest) this.getInitialContext().lookup("EntityTestBean/remote"); 110 FieldCustomer c = test.fieldOneToManyCreate("Bill"); 111 assertNotNull(c); 112 assertNotNull(c.getTickets()); 113 Set <FieldTicket> tickets = c.getTickets(); 114 assertTrue(tickets.size() > 0); 115 116 c = test.fieldFindCustomerByPk(c.getPk()); 118 assertNotNull(c); 119 assertNotNull(c.getTickets()); 120 tickets = c.getTickets(); 121 assertTrue(tickets.size() > 0); 122 assertEquals("Bill", c.getName()); 123 124 } 125 126 public void testFieldManyToOne() throws Exception 127 { 128 EntityTest test = (EntityTest) this.getInitialContext().lookup("EntityTestBean/remote"); 129 FieldFlight f = test.fieldManyToOneCreate(); 130 f = test.fieldFindFlightById(f.getId()); 131 assertTrue(f.getName().equals("AF0101")); 132 } 133 134 public void testFieldManyToMany() throws Exception 135 { 136 EntityTest test = (EntityTest) this.getInitialContext().lookup("EntityTestBean/remote"); 137 test.fieldManyToManyCreate(); 138 139 FieldFlight one = test.fieldFindFlightById(new Long (1)); 140 FieldFlight two = test.fieldFindFlightById(new Long (2)); 141 142 System.out.println("Air France customers"); 143 for (FieldCustomer c : one.getCustomers()) 144 { 145 System.out.println(c.getName()); 146 147 } 148 System.out.println("USAir customers"); 149 150 for (FieldCustomer c : two.getCustomers()) 151 { 152 System.out.println(c.getName()); 153 } 154 155 } 156 157 public static Test suite() throws Exception 158 { 159 return getDeploySetup(EntityUnitTestCase.class, "composite-test.jar"); 160 } 161 162 } 163 | Popular Tags |