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_TimerMD.java 8308 2006-04-27 13:38:45Z 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.message.Sender1_1;
035: import org.objectweb.jonas.jtests.beans.message.Sender1_1Home;
036: import org.objectweb.jonas.jtests.util.JTestCase;
037:
038: /**
039: * test TimerService on Message Driven Beans
040: */
041: public class F_TimerMD extends JTestCase {
042:
043: // Uses JMS 1.1 (std API for J2EE 1.4)
044: private static String BEAN_HOME = "messageSender1_1SFHome";
045: protected static Sender1_1Home home = null;
046:
047: // Must be the same values than in org.objectweb.jonas.jtests.beans.message.Listener
048: public static final int CREATE_TIMER_MIN = 1500;
049: public static final int CREATE_TIMER_MAX = 1600;
050:
051: /**
052: * constructor
053: * @param name name of the test suite.
054: */
055: public F_TimerMD(String name) {
056: super (name);
057: }
058:
059: /**
060: * Sets up the fixture, here load the beans if not loaded yet.
061: * This method is called before a test is executed.
062: */
063: protected void setUp() {
064: super .setUp();
065: useBeans("message", true);
066: }
067:
068: public Sender1_1Home getHome() {
069: if (home == null) {
070: try {
071: home = (Sender1_1Home) PortableRemoteObject.narrow(ictx
072: .lookup(BEAN_HOME), Sender1_1Home.class);
073: } catch (NamingException e) {
074: fail("Cannot get bean home");
075: }
076: }
077: return home;
078: }
079:
080: /**
081: * Basic test: Send 1 message on a topic
082: * 2 MDB are reading the topic.
083: * No tx.
084: */
085: public void testBasicSendOnTopic1() throws Exception {
086: Sender1_1 s = getHome().create();
087: int val = 200;
088: s.sendOnDestination("JunitTopic1", val, 1);
089: assertEquals(2, s.check(val, 2, 4));
090: s.remove();
091: }
092:
093: /**
094: * Start a timer on Topic MDB
095: */
096: public void testTimerTopic1() throws Exception {
097: Sender1_1 s = getHome().create();
098: int val = CREATE_TIMER_MIN + 4;
099: s.sendOnDestination("JunitTopic1", val, 1);
100: assertEquals(2, s.check(val, 2, 5));
101: s.remove();
102: }
103:
104: /**
105: * Start a timer on Queue MDB
106: */
107: public void testTimerQueue1() throws Exception {
108: Sender1_1 s = getHome().create();
109: int val = CREATE_TIMER_MIN + 5;
110: s.sendOnDestination("JunitQueue1", val, 1);
111: assertEquals(1, s.check(val, 1, 6));
112: s.remove();
113: }
114:
115: /**
116: * Start several timers on Queue MDB
117: */
118: public void testTimersQueue1() throws Exception {
119: Sender1_1 s = getHome().create();
120: int val = CREATE_TIMER_MIN + 6;
121: s.sendOnDestination("JunitQueue1", val, 5);
122: assertEquals(5, s.check(val, 5, 7));
123: s.remove();
124: }
125:
126: /**
127: * This suite is all Message Driven Timer test cases
128: */
129: public static Test suite() {
130: return new TestSuite(F_TimerMD.class);
131: }
132:
133: public static void main(String args[]) {
134: String testtorun = null;
135: // Get args
136: for (int argn = 0; argn < args.length; argn++) {
137: String sarg = args[argn];
138: if (sarg.equals("-n")) {
139: testtorun = args[++argn];
140: }
141: }
142: if (testtorun == null) {
143: junit.textui.TestRunner.run(suite());
144: } else {
145: junit.textui.TestRunner.run(new F_TimerMD(testtorun));
146: }
147: }
148: }
|