Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/usecases/ChangeSentMessageTest.java


1   /** 
2    * 
3    * Copyright 2004 Protique Ltd
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * You may obtain a copy of the License at 
8    * 
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License. 
16   * 
17   **/
18  
19  package org.activemq.usecases;
20  import java.util.HashMap;
21  import javax.jms.Connection;
22  import javax.jms.Destination;
23  import javax.jms.MessageConsumer;
24  import javax.jms.MessageProducer;
25  import javax.jms.ObjectMessage;
26  import javax.jms.Session;
27  
28  import org.activemq.test.TestSupport;
29  
30  /**
31   * @version $Revision: 1.1.1.1 $
32   */
33  public class ChangeSentMessageTest extends TestSupport {
34      private static final int COUNT = 200;
35      private static final String VALUE_NAME = "value";
36  
37      /**
38       * test Object messages can be changed after sending with no side-affects
39       * @throws Exception
40       */
41      public void testDoChangeSentMessage() throws Exception {
42          Destination destination = createDestination("test-"+ChangeSentMessageTest.class.getName());
43          Connection connection = createConnection();
44          connection.start();
45          Session consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
46          MessageConsumer consumer = consumerSession.createConsumer(destination);
47          Session publisherSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
48          MessageProducer producer = publisherSession.createProducer(destination);
49          HashMap map = new HashMap();
50          ObjectMessage message = publisherSession.createObjectMessage();
51          for (int i = 0;i < COUNT;i++) {
52              map.put(VALUE_NAME, new Integer(i));
53              message.setObject(map);
54              producer.send(message);
55              assertTrue(message.getObject()==map);
56          }
57          for (int i = 0;i < COUNT;i++) {
58              ObjectMessage msg = (ObjectMessage) consumer.receive();
59              HashMap receivedMap = (HashMap) msg.getObject();
60              Integer intValue = (Integer) receivedMap.get(VALUE_NAME);
61              assertTrue(intValue.intValue() == i);
62          }
63      }
64  }