001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb3.test.relationships.unit;
023:
024: import java.util.Collection;
025: import java.util.Iterator;
026: import org.jboss.ejb3.test.relationships.Customer;
027: import org.jboss.ejb3.test.relationships.LineItem;
028: import org.jboss.ejb3.test.relationships.Order;
029: import org.jboss.ejb3.test.relationships.SessionRemote;
030: import org.jboss.test.JBossTestCase;
031: import junit.framework.Test;
032:
033: /**
034: * Test reentrant remote call. There was a bug that remoting didn't route locally
035: * and the tx propagation was happening when it shouldn't
036: *
037: * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
038: * @version $Id: RelationshipUnitTestCase.java 60233 2007-02-03 10:13:23Z wolfc $
039: */
040:
041: public class RelationshipUnitTestCase extends JBossTestCase {
042: org.apache.log4j.Logger log = getLog();
043:
044: static boolean deployed = false;
045: static int test = 0;
046:
047: public RelationshipUnitTestCase(String name) {
048:
049: super (name);
050:
051: }
052:
053: public void testUniOneToMany() throws Exception {
054: SessionRemote remote = (SessionRemote) getInitialContext()
055: .lookup("SessionBean/remote");
056: remote.createCategory();
057: remote.createItem();
058: int num = remote.getNumItems();
059: assertEquals(1, num);
060: }
061:
062: public void testOneToOne() throws Exception {
063: SessionRemote remote = (SessionRemote) getInitialContext()
064: .lookup("SessionBean/remote");
065: long id = remote.createCustomer();
066: Customer cust = remote.getCustomer(id);
067: long record = cust.getCustomerRecord().getId();
068: remote.testInverse(record);
069: cust = remote.getCustomer(id);
070: record = cust.getCustomerRecord().getId();
071:
072: }
073:
074: public void testMappedByOneToMany() throws Exception {
075: SessionRemote remote = (SessionRemote) getInitialContext()
076: .lookup("SessionBean/remote");
077: long id1 = remote.createCustomer();
078: Customer cust1 = remote.getCustomer(id1);
079: long orderId = remote.creatOrder();
080: Order order = remote.getOrder(orderId);
081: order.setCustomer(cust1);
082: remote.merge(order);
083: orderId = remote.creatOrder();
084: order = remote.getOrder(orderId);
085: order.setCustomer(cust1);
086: remote.merge(order);
087: cust1 = remote.getCustomer(id1);
088: assertEquals(cust1.getOrders().size(), 2);
089: for (Order orderIn : cust1.getOrders()) {
090: orderIn.setCustomer(null);
091: remote.merge(orderIn);
092: break;
093: }
094: cust1 = remote.getCustomer(id1);
095: assertEquals(cust1.getOrders().size(), 1);
096:
097: }
098:
099: public void testRemove() throws Exception {
100:
101: SessionRemote remote = (SessionRemote) getInitialContext()
102: .lookup("SessionBean/remote");
103: long id = remote.creatOrder();
104: Order order = remote.getOrder(id);
105: assertEquals(order.getItems().size(), 2);
106: remote.deleteFromCollection(id);
107: order = remote.getOrder(id);
108: assertEquals(order.getItems().size(), 1);
109: for (LineItem item : order.getItems()) {
110: remote.deleteOne(item.getId());
111: break;
112: }
113: order = remote.getOrder(id);
114: assertEquals(order.getItems().size(), 0);
115: }
116:
117: public void testMergeRemove() throws Exception {
118:
119: SessionRemote remote = (SessionRemote) getInitialContext()
120: .lookup("SessionBean/remote");
121: long id = remote.creatOrder();
122: Order order = remote.getOrder(id);
123: Collection<LineItem> items = order.getItems();
124: Iterator<LineItem> it = items.iterator();
125: while (it.hasNext()) {
126: LineItem item = it.next();
127: item.setOrder(null);
128: break;
129: }
130: remote.merge(order);
131: order = remote.getOrder(id);
132: assertEquals(order.getItems().size(), 1);
133: }
134:
135: public static Test suite() throws Exception {
136: return getDeploySetup(RelationshipUnitTestCase.class,
137: "relationships-test.jar");
138: }
139:
140: }
|