001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: F_TimerSL.java 8387 2006-05-24 11:43:09Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.timer;
027:
028: import javax.naming.NamingException;
029: import javax.rmi.PortableRemoteObject;
030:
031: import junit.framework.Test;
032: import junit.framework.TestSuite;
033:
034: import org.objectweb.jonas.jtests.beans.transacted.Simple;
035: import org.objectweb.jonas.jtests.beans.transacted.SimpleSHome;
036:
037: /**
038: * test TimerService on Stateless Session Beans
039: */
040: public class F_TimerSL extends A_TimerSession {
041:
042: private static String BEAN_HOME = "transactedSimpleSLHome";
043: protected static SimpleSHome home = null;
044:
045: /**
046: * constructor
047: * @param name name of the test suite.
048: */
049: public F_TimerSL(String name) {
050: super (name);
051: }
052:
053: /**
054: * Create a bean and return it.
055: */
056: public Simple getSimple(int i) throws Exception {
057: return home.create();
058: }
059:
060: /**
061: * init environment:
062: * - load beans
063: * - get the home for session beans
064: * - cancel timers left over from previous tests
065: */
066: protected void setUp() {
067: super .setUp();
068: if (home == null) {
069: try {
070: home = (SimpleSHome) PortableRemoteObject.narrow(ictx
071: .lookup(BEAN_HOME), SimpleSHome.class);
072: } catch (NamingException e) {
073: fail("Cannot get Home:" + e);
074: }
075: }
076: }
077:
078: /**
079: * - cancel timers from test
080: */
081: protected void tearDown() throws Exception {
082: // Remove this line to test the persistent timers !
083: cancelSessionTimers();
084: super .tearDown();
085: }
086:
087: private void cancelSessionTimers() {
088: Simple s;
089: try {
090: s = getSimple(0);
091: } catch (Exception e) {
092: throw new RuntimeException("could not create session bean",
093: e);
094: }
095:
096: try {
097: s.cancelTimers();
098: s.remove();
099: } catch (java.rmi.RemoteException re) {
100: throw new RuntimeException(
101: "could not cancel session timers", re);
102: } catch (javax.ejb.RemoveException re) {
103: throw new RuntimeException("could not remove session bean",
104: re);
105: }
106: }
107:
108: /**
109: * This suite is all Session Statless test cases
110: */
111: public static Test suite() {
112: return new TestSuite(F_TimerSL.class);
113: }
114:
115: public static void main(String args[]) {
116: String testtorun = null;
117: // Get args
118: for (int argn = 0; argn < args.length; argn++) {
119: String sarg = args[argn];
120: if (sarg.equals("-n")) {
121: testtorun = args[++argn];
122: }
123: }
124: if (testtorun == null) {
125: junit.textui.TestRunner.run(suite());
126: } else {
127: junit.textui.TestRunner.run(new F_TimerSL(testtorun));
128: }
129: }
130: }
|