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.codehaus.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 import org.codehaus.activemq.TestSupport; 28 29 /*** 30 * @version $Revision: 1.1 $ 31 */ 32 public class ChangeSentMessageTest extends TestSupport { 33 private static final int COUNT = 200; 34 private static final String VALUE_NAME = "value"; 35 36 /*** 37 * test Object messages can be changed after sending with no side-affects 38 * @throws Exception 39 */ 40 public void testDoChangeSentMessage() throws Exception { 41 Destination destination = createDestination("foo.bar"); 42 Connection connection = createConnection(); 43 connection.start(); 44 Session consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 45 MessageConsumer consumer = consumerSession.createConsumer(destination); 46 Session publisherSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 47 MessageProducer producer = publisherSession.createProducer(destination); 48 HashMap map = new HashMap(); 49 ObjectMessage message = publisherSession.createObjectMessage(map); 50 for (int i = 0;i < COUNT;i++) { 51 map.put(VALUE_NAME, new Integer(i)); 52 producer.send(message); 53 assertTrue(message.getObject()==map); 54 } 55 for (int i = 0;i < COUNT;i++) { 56 ObjectMessage msg = (ObjectMessage) consumer.receive(); 57 HashMap receivedMap = (HashMap) msg.getObject(); 58 Integer intValue = (Integer) receivedMap.get(VALUE_NAME); 59 assertTrue(intValue.intValue() == i); 60 } 61 } 62 }