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.test.txiiop.test;
023:
024: import javax.naming.Context;
025: import javax.rmi.PortableRemoteObject;
026: import javax.transaction.UserTransaction;
027:
028: import junit.framework.Test;
029: import org.jboss.test.JBossIIOPTestCase;
030: import org.jboss.test.txiiop.interfaces.StatefulSession;
031: import org.jboss.test.txiiop.interfaces.StatefulSessionHome;
032:
033: /** Tests of IIOP UserTransaction
034: *
035: * @author kimptoc
036: * @author Scott.Stark@jboss.org
037: * @author d_jencks converted to JBossTestCase, added logging.
038: * @author reverbel@ime.usp.br
039: * @version $Revision: 57211 $
040: */
041: public class IIOPUserTransactionStressTestCase extends
042: JBossIIOPTestCase {
043: // Constructors --------------------------------------------------
044: public IIOPUserTransactionStressTestCase(String name) {
045: super (name);
046: }
047:
048: // Public --------------------------------------------------------
049:
050: public void testUserTx() throws Exception {
051: getLog().debug("+++ testUsrTx");
052:
053: getLog().debug("Obtain home interface");
054: // Create a new session object
055: Context ctx = getInitialContext();
056: Object ref = ctx.lookup("txiiop/StatefulSessionBean");
057: StatefulSessionHome home = (StatefulSessionHome) PortableRemoteObject
058: .narrow(ref, StatefulSessionHome.class);
059: StatefulSession bean = home.create("testUserTx");
060:
061: bean.setCounter(100);
062: getLog().debug("Try to instantiate a UserTransaction");
063: UserTransaction userTx = (UserTransaction) ctx
064: .lookup("UserTransaction");
065: userTx.begin();
066: bean.incCounter();
067: bean.incCounter();
068: userTx.commit();
069: int counter = bean.getCounter();
070: assertTrue("counter == 102", counter == 102);
071:
072: bean.setCounter(100);
073: userTx.begin();
074: bean.incCounter();
075: bean.incCounter();
076: userTx.rollback();
077: counter = bean.getCounter();
078: assertTrue("counter == 100", counter == 100);
079:
080: bean.remove();
081: }
082:
083: public void testTxMandatory() throws Exception {
084: getLog().debug("+++ testTxMandatory");
085:
086: getLog().debug("Obtain home interface");
087: // Create a new session object
088: Context ctx = getInitialContext();
089: Object ref = ctx.lookup("txiiop/StatefulSessionBean");
090: StatefulSessionHome home = (StatefulSessionHome) PortableRemoteObject
091: .narrow(ref, StatefulSessionHome.class);
092: StatefulSession bean = home.create("testTxMandatory");
093: getLog().debug(
094: "Call txMandatoryMethod without a UserTransaction");
095: try {
096: bean.txMandatoryMethod("without a UserTransaction");
097: getLog().debug("Should not get here!");
098: fail("TransactionRequiredException should have been thrown");
099: } catch (javax.transaction.TransactionRequiredException e) {
100: getLog().debug("Expected exception: " + e);
101: }
102: getLog().debug("Begin UserTransaction");
103: UserTransaction userTx = (UserTransaction) ctx
104: .lookup("UserTransaction");
105: userTx.begin();
106: bean.txMandatoryMethod("within a UserTransaction");
107: getLog().debug("Commit UserTransaction");
108: userTx.commit();
109: bean.remove();
110: }
111:
112: public static Test suite() throws Exception {
113: return getDeploySetup(IIOPUserTransactionStressTestCase.class,
114: "txiiop.jar");
115: }
116:
117: }
|