KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > test > JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest


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.test;
19
20 import org.apache.activemq.ActiveMQConnectionFactory;
21 import org.apache.activemq.broker.BrokerService;
22
23 import javax.jms.JMSException JavaDoc;
24 import javax.jms.Message JavaDoc;
25
26 import java.util.Iterator JavaDoc;
27 import java.util.List JavaDoc;
28
29 /**
30  *
31  * @version $Revision: 1.1 $
32  */

33 public class JmsTopicSendReceiveWithEmbeddedBrokerAndUserIDTest extends
34         JmsTopicSendReceiveWithTwoConnectionsAndEmbeddedBrokerTest {
35
36     protected String JavaDoc userName = "James";
37     
38     protected ActiveMQConnectionFactory createConnectionFactory() throws Exception JavaDoc {
39         ActiveMQConnectionFactory answer = super.createConnectionFactory();
40         answer.setUserName(userName);
41         return answer;
42     }
43
44     protected void configureBroker(BrokerService answer) throws Exception JavaDoc {
45         answer.setPopulateJMSXUserID(true);
46         super.configureBroker(answer);
47     }
48
49     protected void assertMessagesReceivedAreValid(List JavaDoc receivedMessages) throws JMSException JavaDoc {
50         super.assertMessagesReceivedAreValid(receivedMessages);
51
52         // lets assert that the user ID is set
53
for (Iterator JavaDoc iter = receivedMessages.iterator(); iter.hasNext();) {
54             Message JavaDoc message = (Message JavaDoc) iter.next();
55             String JavaDoc userID = message.getStringProperty("JMSXUserID");
56
57             log.info("Received message with userID: " + userID);
58
59             assertEquals("JMSXUserID header", userName, userID);
60         }
61     }
62 }
63
Popular Tags