KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > manytomany > unit > EntityUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ejb3.test.manytomany.unit;
23
24 import java.util.Set JavaDoc;
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 /**
35  * Sample client for the jboss container.
36  *
37  * @author <a HREF="mailto:bill@burkecentral.com">Bill Burke</a>
38  * @version $Id: EntityUnitTestCase.java 58110 2006-11-04 08:34:21Z scott.stark@jboss.org $
39  */

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 JavaDoc name)
50    {
51
52       super(name);
53
54    }
55
56    public void testOneToMany() throws Exception JavaDoc
57    {
58       EntityTest test = (EntityTest) this.getInitialContext().lookup("EntityTestBean/remote");
59       Customer c = test.oneToManyCreate();
60       assertNotNull(c);
61       assertNotNull(c.getTickets());
62       Set JavaDoc<Ticket> tickets = c.getTickets();
63       assertTrue(tickets.size() > 0);
64
65       // test find
66
c = test.findCustomerById(c.getId());
67       assertNotNull(c);
68       assertNotNull(c.getTickets());
69       tickets = c.getTickets();
70       assertTrue(tickets.size() > 0);
71
72       // test 1-1
73
Address address = c.getAddress();
74       assertTrue(address != null);
75       assertTrue(address.getCity().equals("Boston"));
76    }
77
78    public void testManyToOne() throws Exception JavaDoc
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 JavaDoc
92    {
93       EntityTest test = (EntityTest) this.getInitialContext().lookup("EntityTestBean/remote");
94       test.manyToManyCreate();
95
96       Flight one = test.findFlightById(new Long JavaDoc(1));
97       assertTrue(one.getCompany().getName().equals("Air France"));
98
99       Flight two = test.findFlightById(new Long JavaDoc(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 JavaDoc
118    {
119       return getDeploySetup(EntityUnitTestCase.class, "manytomany-test.jar");
120    }
121
122 }
123
Popular Tags