KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > usecases > ChangeSentMessageTest


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
19 package org.apache.activemq.usecases;
20 import java.util.HashMap JavaDoc;
21 import javax.jms.Connection JavaDoc;
22 import javax.jms.Destination JavaDoc;
23 import javax.jms.MessageConsumer JavaDoc;
24 import javax.jms.MessageProducer JavaDoc;
25 import javax.jms.ObjectMessage JavaDoc;
26 import javax.jms.Session JavaDoc;
27
28 import org.apache.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 JavaDoc 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 JavaDoc {
42         Destination JavaDoc destination = createDestination("test-"+ChangeSentMessageTest.class.getName());
43         Connection JavaDoc connection = createConnection();
44         connection.start();
45         Session JavaDoc consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
46         MessageConsumer JavaDoc consumer = consumerSession.createConsumer(destination);
47         Session JavaDoc publisherSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
48         MessageProducer JavaDoc producer = publisherSession.createProducer(destination);
49         HashMap JavaDoc map = new HashMap JavaDoc();
50         ObjectMessage JavaDoc message = publisherSession.createObjectMessage();
51         for (int i = 0;i < COUNT;i++) {
52             map.put(VALUE_NAME, new Integer JavaDoc(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 JavaDoc msg = (ObjectMessage JavaDoc) consumer.receive();
59             HashMap JavaDoc receivedMap = (HashMap JavaDoc) msg.getObject();
60             Integer JavaDoc intValue = (Integer JavaDoc) receivedMap.get(VALUE_NAME);
61             assertTrue(intValue.intValue() == i);
62         }
63     }
64 }
65
Popular Tags