KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > JmsDurableTopicSendReceiveTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq;
19
20 import javax.jms.Connection JavaDoc;
21 import javax.jms.Destination JavaDoc;
22 import javax.jms.Message JavaDoc;
23 import javax.jms.MessageConsumer JavaDoc;
24 import javax.jms.MessageProducer JavaDoc;
25 import javax.jms.Session JavaDoc;
26 import javax.jms.TextMessage JavaDoc;
27 import javax.jms.Topic JavaDoc;
28
29 import org.apache.activemq.test.JmsTopicSendReceiveTest;
30
31 /**
32  * @version $Revision: 1.5 $
33  */

34 public class JmsDurableTopicSendReceiveTest extends JmsTopicSendReceiveTest {
35     private static final org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
36             .getLog(JmsDurableTopicSendReceiveTest.class);
37     
38     protected Connection JavaDoc connection2;
39     protected Session JavaDoc session2;
40     protected Session JavaDoc consumeSession2;
41     protected MessageConsumer JavaDoc consumer2;
42     protected MessageProducer JavaDoc producer2;
43     protected Destination JavaDoc consumerDestination2;
44     protected Destination JavaDoc producerDestination2;
45     /**
46      * Set up a durable suscriber test.
47      *
48      * @see junit.framework.TestCase#setUp()
49      */

50     protected void setUp() throws Exception JavaDoc {
51         this.durable = true;
52         super.setUp();
53     }
54
55     /**
56      * Test if all the messages sent are being received.
57      *
58      * @throws Exception
59      */

60     public void testSendWhileClosed() throws Exception JavaDoc {
61         connection2 = createConnection();
62         connection2.setClientID("test");
63         connection2.start();
64         session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
65         producer2 = session2.createProducer(null);
66         producer2.setDeliveryMode(deliveryMode);
67         producerDestination2 = session2.createTopic(getProducerSubject()+"2");
68         Thread.sleep(1000);
69
70         consumeSession2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
71         consumerDestination2 = session2.createTopic(getConsumerSubject()+"2");
72         consumer2 = consumeSession2.createDurableSubscriber((Topic JavaDoc)consumerDestination2, getName());
73         Thread.sleep(1000);
74         consumer2.close();
75         TextMessage JavaDoc message = session2.createTextMessage("test");
76         message.setStringProperty("test","test");
77         message.setJMSType("test");
78         producer2.send(producerDestination2, message);
79         log.info("Creating durable consumer");
80         consumer2 = consumeSession2.createDurableSubscriber((Topic JavaDoc)consumerDestination2, getName());
81         Message msg = consumer2.receive(1000);
82         assertNotNull(msg);
83         assertEquals(((TextMessage JavaDoc) msg).getText(), "test");
84         assertEquals(msg.getJMSType(), "test");
85         assertEquals(msg.getStringProperty("test"), "test");
86         connection2.stop();
87         connection2.close();
88     }
89 }
90
Popular Tags