[jboss-cvs] jboss-ejb3/src/test/org/jboss/ejb3/test/iiop/unit ...

Carlo de Wolf carlo at nerdnet.nl
Fri Jul 28 04:04:34 EDT 2006


  User: wolfc   
  Date: 06/07/28 04:04:34

  Added:       src/test/org/jboss/ejb3/test/iiop/unit 
                        IiopRemoteUnitTestCase.java
  Log:
  EJBTHREE-667: work in progress
  
  Revision  Changes    Path
  1.1      date: 2006/07/28 08:04:34;  author: wolfc;  state: Exp;jboss-ejb3/src/test/org/jboss/ejb3/test/iiop/unit/IiopRemoteUnitTestCase.java
  
  Index: IiopRemoteUnitTestCase.java
  ===================================================================
  /*
    * JBoss, Home of Professional Open Source
    * Copyright 2005, JBoss Inc., and individual contributors as indicated
    * by the @authors tag. See the copyright.txt in the distribution for a
    * full listing of individual contributors.
    *
    * This is free software; you can redistribute it and/or modify it
    * under the terms of the GNU Lesser General Public License as
    * published by the Free Software Foundation; either version 2.1 of
    * the License, or (at your option) any later version.
    *
    * This software is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    * Lesser General Public License for more details.
    *
    * You should have received a copy of the GNU Lesser General Public
    * License along with this software; if not, write to the Free
    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
    */
  package org.jboss.ejb3.test.iiop.unit;
  
  import java.util.Date;
  import java.util.Properties;
  
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import javax.rmi.PortableRemoteObject;
  import javax.transaction.UserTransaction;
  
  import junit.framework.Test;
  
  import org.jboss.ejb3.test.iiop.MyStatefulHome;
  import org.jboss.ejb3.test.iiop.TxTester;
  import org.jboss.ejb3.test.iiop.MySession;
  import org.jboss.ejb3.test.iiop.MyStateful;
  import org.jboss.test.JBossTestCase;
  
  /**
   * TODO: use JBossIIOPTestCase
   *
   * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
   * @version $Revision: 1.1 $
   */
  public class IiopRemoteUnitTestCase extends JBossTestCase
  {
  
     public IiopRemoteUnitTestCase(String name)
     {
        super(name);
     }
  
     public InitialContext getInitialContext() throws NamingException
     {
        return new InitialContext(getJndiProperties());
     }
     
     private Properties getJndiProperties()
     {
        Properties props = new Properties();
        props.put("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");
        props.put("java.naming.provider.url", "corbaloc::localhost:3528/NameService");
        props.put("java.naming.factory.object", "org.jboss.tm.iiop.client.IIOPClientUserTransactionObjectFactory");
        return props;
     }
     
     public void test1() throws Exception
     {
        InitialContext ctx = getInitialContext();
        Object obj = ctx.lookup("MySessionBean/remote");
        System.err.println(obj.getClass());
        MySession session = (MySession) PortableRemoteObject.narrow(obj, MySession.class);
        assertNotNull(session);
        String me = new Date().toString();
        String response = session.sayHelloTo(me);
        assertEquals("Hi " + me, response);
     }
     
     public void test2() throws Exception
     {
        InitialContext ctx = getInitialContext();
        Object obj = ctx.lookup("MyStatefulBean/remoteHome");
        MyStatefulHome home = (MyStatefulHome) PortableRemoteObject.narrow(obj, MyStatefulHome.class);
        //MyStateful bean1 = (MyStateful) PortableRemoteObject.narrow(obj, MyStateful.class);
        MyStateful bean1 = home.create();
        bean1.setName("bean1");
        String response = bean1.sayHello();
        assertEquals("Hello bean1", response);
     }
     
     public void testTxPropegation() throws Exception
     {
        InitialContext ctx = getInitialContext();
        Object obj = ctx.lookup("TxTesterBean/remote");
        TxTester session = (TxTester) PortableRemoteObject.narrow(obj, TxTester.class);
        assertNotNull(session);
        UserTransaction tx = (UserTransaction) PortableRemoteObject.narrow(ctx.lookup("UserTransaction"), UserTransaction.class);
        tx.begin();
        try
        {
           session.txMandatoryMethod();
        }
        finally
        {
           tx.rollback();
        }
        // If it doesn't throw an exception everything is fine.
     }
  
     public void testTxRequired() throws Exception
     {
        InitialContext ctx = getInitialContext();
        Object obj = ctx.lookup("TxTesterBean/remote");
        TxTester session = (TxTester) PortableRemoteObject.narrow(obj, TxTester.class);
        assertNotNull(session);
        try
        {
           session.txMandatoryMethod();
           fail("Expected an exception");
        }
        catch(Exception e)
        {
           //fail("TODO: check exception");
        }
        // TODO: throws an ugly exception, needs assertions to check
     }
     
     public static Test suite() throws Exception
     {
        return getDeploySetup(IiopRemoteUnitTestCase.class, "iiop.jar");
     }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list