001: /*
002: * JBoss, Home of Professional Open Source
003: * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
004: * by the @authors tag. See the copyright.txt in the distribution for a
005: * 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.ejbthree959.unit;
023:
024: import javax.ejb.NoSuchEJBException;
025: import javax.naming.NamingException;
026: import javax.rmi.PortableRemoteObject;
027:
028: import junit.framework.Test;
029:
030: import org.jboss.ejb3.test.ejbthree959.MyStateful;
031: import org.jboss.ejb3.test.ejbthree959.MyStatefulHome;
032: import org.jboss.ejb3.test.ejbthree959.Status;
033: import org.jboss.test.JBossTestCase;
034:
035: /**
036: * Test if an EJB 2.1 bean is properly deployed.
037: *
038: * @author <a href="mailto:carlo.dewolf@jboss.com">Carlo de Wolf</a>
039: * @version $Revision: $
040: */
041: public class EJB21TestCase extends JBossTestCase {
042:
043: public EJB21TestCase(String name) {
044: super (name);
045: }
046:
047: private MyStatefulHome getMyStatefulHome() throws Exception {
048: return (MyStatefulHome) PortableRemoteObject.narrow(
049: getInitialContext().lookup("MyStateful/home"),
050: MyStatefulHome.class);
051: }
052:
053: private Status getStatus() throws Exception {
054: return (Status) getInitialContext().lookup("StatusBean/remote");
055: }
056:
057: public void testCreateNoArgs() throws Exception {
058: MyStatefulHome home = getMyStatefulHome();
059: MyStateful bean = home.create();
060: bean.setName("testCreateNoArgs");
061: String expected = "Hi testCreateNoArgs";
062: String actual = bean.sayHi();
063: assertEquals(expected, actual);
064: bean.remove();
065: }
066:
067: public void testCreateWithArgs() throws Exception {
068: MyStatefulHome home = getMyStatefulHome();
069: MyStateful bean = home.create("testCreateWithArgs");
070: String expected = "Hi testCreateWithArgs";
071: String actual = bean.sayHi();
072: assertEquals(expected, actual);
073: bean.remove();
074: }
075:
076: public void testCtx() throws Exception {
077: MyStatefulHome home = getMyStatefulHome();
078: MyStateful bean = home.create();
079: bean.checkCtx();
080: bean.remove();
081: }
082:
083: public void testLifeCycle() throws Exception {
084: Status status = getStatus();
085: status.reset();
086:
087: MyStatefulHome home = getMyStatefulHome();
088: MyStateful bean = home.create();
089:
090: assertEquals(1, status.getCreateCalls());
091:
092: bean.setName("testLifeCycle");
093: String expected = "Hi testLifeCycle";
094: String actual = bean.sayHi();
095: assertEquals(expected, actual);
096:
097: sleep(10000);
098:
099: assertEquals(1, status.getPassivateCalls());
100:
101: actual = bean.sayHi();
102: assertEquals(expected, actual);
103:
104: assertEquals(1, status.getActivateCalls());
105:
106: bean.remove();
107:
108: assertEquals(1, status.getRemoveCalls());
109:
110: try {
111: bean.sayHi();
112: fail("expected no such ejb exception");
113: } catch (NoSuchEJBException e) {
114: // good
115: }
116: }
117:
118: public static Test suite() throws Exception {
119: return getDeploySetup(EJB21TestCase.class, "ejbthree959.jar");
120: }
121:
122: }
|