KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > relationships > unit > RelationshipUnitTestCase


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.relationships.unit;
23
24 import java.util.Collection JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import org.jboss.ejb3.test.relationships.Customer;
27 import org.jboss.ejb3.test.relationships.LineItem;
28 import org.jboss.ejb3.test.relationships.Order;
29 import org.jboss.ejb3.test.relationships.SessionRemote;
30 import org.jboss.test.JBossTestCase;
31 import junit.framework.Test;
32
33 /**
34  * Test reentrant remote call. There was a bug that remoting didn't route locally
35  * and the tx propagation was happening when it shouldn't
36  *
37  * @author <a HREF="mailto:bill@burkecentral.com">Bill Burke</a>
38  * @version $Id: RelationshipUnitTestCase.java 58110 2006-11-04 08:34:21Z scott.stark@jboss.org $
39  */

40
41 public class RelationshipUnitTestCase
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 RelationshipUnitTestCase(String JavaDoc name)
50    {
51
52       super(name);
53
54    }
55
56    public void testUniOneToMany() throws Exception JavaDoc
57    {
58       SessionRemote remote = (SessionRemote) getInitialContext().lookup("SessionBean/remote");
59       remote.createCategory();
60       remote.createItem();
61       int num = remote.getNumItems();
62       assertEquals(1, num);
63    }
64
65    public void testOneToOne() throws Exception JavaDoc
66    {
67       SessionRemote remote = (SessionRemote) getInitialContext().lookup("SessionBean/remote");
68       long id = remote.createCustomer();
69       Customer cust = remote.getCustomer(id);
70       long record = cust.getCustomerRecord().getId();
71       remote.testInverse(record);
72       cust = remote.getCustomer(id);
73       record = cust.getCustomerRecord().getId();
74
75    }
76
77    public void testMappedByOneToMany() throws Exception JavaDoc
78    {
79       SessionRemote remote = (SessionRemote) getInitialContext().lookup("SessionBean/remote");
80       long id1 = remote.createCustomer();
81       Customer cust1 = remote.getCustomer(id1);
82       long orderId = remote.creatOrder();
83       Order order = remote.getOrder(orderId);
84       order.setCustomer(cust1);
85       remote.merge(order);
86       orderId = remote.creatOrder();
87       order = remote.getOrder(orderId);
88       order.setCustomer(cust1);
89       remote.merge(order);
90       cust1 = remote.getCustomer(id1);
91       assertEquals(cust1.getOrders().size(), 2);
92       for (Order orderIn : cust1.getOrders())
93       {
94          orderIn.setCustomer(null);
95          remote.merge(orderIn);
96          break;
97       }
98       cust1 = remote.getCustomer(id1);
99       assertEquals(cust1.getOrders().size(), 1);
100
101
102
103    }
104
105    public void testRemove() throws Exception JavaDoc
106    {
107
108       SessionRemote remote = (SessionRemote) getInitialContext().lookup("SessionBean/remote");
109       long id = remote.creatOrder();
110       Order order = remote.getOrder(id);
111       assertEquals(order.getItems().size(), 2);
112       remote.deleteFromCollection(id);
113       order = remote.getOrder(id);
114       assertEquals(order.getItems().size(), 1);
115       for (LineItem item : order.getItems())
116       {
117          remote.deleteOne(item.getId());
118          break;
119       }
120       order = remote.getOrder(id);
121       assertEquals(order.getItems().size(), 0);
122    }
123
124    public void testMergeRemove() throws Exception JavaDoc
125    {
126
127       SessionRemote remote = (SessionRemote) getInitialContext().lookup("SessionBean/remote");
128       long id = remote.creatOrder();
129       Order order = remote.getOrder(id);
130       Collection JavaDoc<LineItem> items = order.getItems();
131       Iterator JavaDoc<LineItem> it = items.iterator();
132       while (it.hasNext())
133       {
134          LineItem item = it.next();
135          item.setOrder(null);
136          break;
137       }
138       remote.merge(order);
139       order = remote.getOrder(id);
140       assertEquals(order.getItems().size(), 1);
141    }
142
143    public static Test suite() throws Exception JavaDoc
144    {
145       return getDeploySetup(RelationshipUnitTestCase.class, "relationships-test.jar");
146    }
147
148 }
149
Popular Tags