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_NoBean.java 7607 2005-10-25 13:40:13Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.clients.jms;
027:
028: import javax.jms.Connection;
029: import javax.jms.ConnectionFactory;
030: import javax.jms.Destination;
031: import javax.jms.MessageProducer;
032: import javax.jms.Session;
033: import javax.jms.TextMessage;
034: import javax.jms.Topic;
035: import javax.jms.TopicConnection;
036: import javax.jms.TopicConnectionFactory;
037: import javax.jms.TopicSubscriber;
038: import javax.naming.NamingException;
039: import javax.rmi.PortableRemoteObject;
040: import junit.framework.Test;
041: import junit.framework.TestSuite;
042: import org.objectweb.jonas.jtests.util.JTestCase;
043: import org.objectweb.jonas.jtests.beans.message.Sender;
044: import org.objectweb.jonas.jtests.beans.message.SenderHome;
045: import org.objectweb.jonas.jtests.beans.message.Sender1_1;
046: import org.objectweb.jonas.jtests.beans.message.Sender1_1Home;
047:
048: public class F_NoBean extends JTestCase {
049:
050: public F_NoBean(String name) {
051: super (name);
052: }
053:
054: /**
055: * init environment:
056: */
057: protected void setUp() {
058: super .setUp();
059: }
060:
061: /**
062: * Test the NoLocal attribute.
063: * @throws Exception
064: */
065: public void testNoLocal() throws Exception {
066: ConnectionFactory cf = (ConnectionFactory) ictx.lookup("JCF");
067: Topic topic = (Topic) ictx.lookup("sampleTopic");
068: Connection tc = cf.createConnection();
069: Session sess = tc
070: .createSession(false, Session.AUTO_ACKNOWLEDGE);
071: TopicSubscriber tl = sess.createDurableSubscriber(topic,
072: "NoLocal", "", true);
073: MessageProducer pd = sess.createProducer(topic);
074: tc.start();
075:
076: // Send 2 messages on the topic
077: TextMessage messageSent = null;
078: messageSent = sess.createTextMessage();
079: messageSent.setText("Just a test");
080: messageSent.setStringProperty("TEST_NAME", "testNoLocal");
081: messageSent.setBooleanProperty("lastMessage", false);
082: pd.send(messageSent);
083: messageSent.setStringProperty("TEST_NAME", "test");
084: messageSent.setBooleanProperty("lastMessage", true);
085: pd.send(messageSent);
086:
087: // Verify that tl did not receive any message
088: long timeout = 2000L;
089: TextMessage messageReceived = null;
090: messageReceived = (TextMessage) tl.receive(timeout);
091: if (messageReceived != null) {
092: fail("createDurableSubscriber with NoLocal");
093: }
094:
095: sess.close();
096: tc.close();
097: }
098:
099: /**
100: * Run all the tests
101: */
102: public static Test suite() {
103: return new TestSuite(F_NoBean.class);
104: }
105:
106: public static void main(String args[]) {
107: String testtorun = null;
108: // Get args
109: for (int argn = 0; argn < args.length; argn++) {
110: String s_arg = args[argn];
111: if (s_arg.equals("-n")) {
112: testtorun = args[++argn];
113: }
114: }
115: if (testtorun == null) {
116: junit.textui.TestRunner.run(suite());
117: } else {
118: junit.textui.TestRunner.run(new F_NoBean(testtorun));
119: }
120: }
121: }
|