KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > config > ConfigUsingDestinationOptions


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.config;
19
20 import junit.framework.TestCase;
21 import org.apache.activemq.command.ActiveMQQueue;
22 import org.apache.activemq.ActiveMQConnectionFactory;
23 import org.apache.activemq.ActiveMQMessageConsumer;
24
25 import javax.jms.Connection JavaDoc;
26 import javax.jms.JMSException JavaDoc;
27 import javax.jms.Session JavaDoc;
28 import javax.jms.InvalidSelectorException JavaDoc;
29
30 public class ConfigUsingDestinationOptions extends TestCase {
31     public void testValidSelectorConfig() throws JMSException JavaDoc {
32         ActiveMQQueue queue = new ActiveMQQueue("TEST.FOO?consumer.selector=test=1");
33
34         ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
35         Connection JavaDoc conn = factory.createConnection();
36         Session JavaDoc sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
37
38         ActiveMQMessageConsumer cons;
39         // JMS selector should be priority
40
cons = (ActiveMQMessageConsumer) sess.createConsumer(queue, "test=2");
41         assertEquals("test=2", cons.getMessageSelector());
42
43         // Test setting using JMS destinations
44
cons = (ActiveMQMessageConsumer) sess.createConsumer(queue);
45         assertEquals("test=1", cons.getMessageSelector());
46     }
47
48     public void testInvalidSelectorConfig() throws JMSException JavaDoc {
49         ActiveMQQueue queue = new ActiveMQQueue("TEST.FOO?consumer.selector=test||1");
50
51         ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
52         Connection JavaDoc conn = factory.createConnection();
53         Session JavaDoc sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
54
55         ActiveMQMessageConsumer cons;
56         // JMS selector should be priority
57
try {
58             cons = (ActiveMQMessageConsumer) sess.createConsumer(queue, "test||1");
59             fail("Selector should be invalid");
60         } catch (InvalidSelectorException JavaDoc e) {
61
62         }
63
64         // Test setting using JMS destinations
65
try {
66             cons = (ActiveMQMessageConsumer) sess.createConsumer(queue);
67             fail("Selector should be invalid");
68         } catch (InvalidSelectorException JavaDoc e) {
69
70         }
71     }
72 }
73
Popular Tags