KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cts > test > StatelessSessionBrokenCreateUnitTestCase


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.test.cts.test;
23
24 import java.rmi.RemoteException JavaDoc;
25
26 import javax.management.ObjectName JavaDoc;
27 import javax.naming.InitialContext JavaDoc;
28 import javax.rmi.PortableRemoteObject JavaDoc;
29
30 import junit.framework.Test;
31
32 import org.jboss.test.JBossTestCase;
33 import org.jboss.test.cts.interfaces.StatelessSession;
34 import org.jboss.test.cts.interfaces.StatelessSessionHome;
35
36 /**
37  * Simple test to assert the correct exception when
38  * an instance cannot be created.<p>
39  *
40  * Put in a separate test because this currently
41  * stops the session bean from being usable at all.
42  *
43  * @author adrian@jboss.com
44  * @version $Revision: 37406 $
45  */

46 public class StatelessSessionBrokenCreateUnitTestCase extends JBossTestCase
47 {
48    public StatelessSessionBrokenCreateUnitTestCase(String JavaDoc name)
49    {
50       super(name);
51    }
52
53    public void testCreateExceptionFromRemoteInterface() throws Exception JavaDoc
54    {
55       getLog().debug("+++ testCreateExceptionFromInterface()");
56       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
57       Object JavaDoc ref = ctx.lookup("ejbcts/StatelessSessionHome");
58       StatelessSessionHome home = (StatelessSessionHome) PortableRemoteObject.narrow(ref, StatelessSessionHome.class);
59       StatelessSession sessionBean = home.create();
60       sessionBean.breakCreate();
61       ObjectName JavaDoc pool = new ObjectName JavaDoc("jboss.j2ee:jndiName=ejbcts/StatelessSessionHome,plugin=pool,service=EJB");
62       getServer().invoke(pool, "clear", null, null);
63       try
64       {
65          sessionBean.method1("This should cause a CreateException");
66          fail("Should not be here");
67       }
68       catch (RemoteException JavaDoc expected)
69       {
70          log.debug("Expected", expected);
71       }
72    }
73
74    public static Test suite() throws Exception JavaDoc
75    {
76       return getDeploySetup(StatelessSessionBrokenCreateUnitTestCase.class, "cts.jar");
77    }
78 }
79
Popular Tags