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