KickJava   Java API By Example, From Geeks To Geeks.

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

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 JavaDoc name)
51    {
52
53       super(name);
54
55    }
56
57    public void testOneToMany() throws Exception JavaDoc
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 JavaDoc<Ticket> tickets = c.getTickets();
64       assertTrue(tickets.size() > 0);
65
66       // test find
67
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 JavaDoc
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 JavaDoc
85    {
86       EntityTest test = (EntityTest) this.getInitialContext().lookup("EntityTestBean/remote");
87       test.manyToManyCreate();
88
89       Flight one = test.findFlightById(new Long JavaDoc(1));
90       Flight two = test.findFlightById(new Long JavaDoc(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 JavaDoc
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 JavaDoc<FieldTicket> tickets = c.getTickets();
114       assertTrue(tickets.size() > 0);
115
116       // test find
117
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 JavaDoc
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 JavaDoc
135    {
136       EntityTest test = (EntityTest) this.getInitialContext().lookup("EntityTestBean/remote");
137       test.fieldManyToManyCreate();
138
139       FieldFlight one = test.fieldFindFlightById(new Long JavaDoc(1));
140       FieldFlight two = test.fieldFindFlightById(new Long JavaDoc(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 JavaDoc
158    {
159       return getDeploySetup(EntityUnitTestCase.class, "composite-test.jar");
160    }
161
162 }
163
Popular Tags