diff options
| author | Keith Wall <kwall@apache.org> | 2011-11-07 08:27:31 +0000 |
|---|---|---|
| committer | Keith Wall <kwall@apache.org> | 2011-11-07 08:27:31 +0000 |
| commit | 36d4650990d99bdbc29609567e56d846839edc46 (patch) | |
| tree | 24d5fb1c1e9bb5d336e0601b016cfdb0a198c472 /qpid/java/client/src/test | |
| parent | f1f1b41c39982ab393b73a099a8e479ee6251bd2 (diff) | |
| download | qpid-python-36d4650990d99bdbc29609567e56d846839edc46.tar.gz | |
QPID-2848: refactored message consumer: pre-aquire, capacity decisions are moved into consumer, renamed field noConsume into browseOnly, cleaned up selector filter code.
Applied patch from Andrew MacBean <andymacbean@gmail.com>, Oleksandr Rudyy<orudyy@gmail.com> and myself.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1198642 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/client/src/test')
| -rw-r--r-- | qpid/java/client/src/test/java/org/apache/qpid/filter/JMSSelectorFilterTest.java | 108 | ||||
| -rw-r--r-- | qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java | 3 |
2 files changed, 110 insertions, 1 deletions
diff --git a/qpid/java/client/src/test/java/org/apache/qpid/filter/JMSSelectorFilterTest.java b/qpid/java/client/src/test/java/org/apache/qpid/filter/JMSSelectorFilterTest.java new file mode 100644 index 0000000000..d4d8ea4350 --- /dev/null +++ b/qpid/java/client/src/test/java/org/apache/qpid/filter/JMSSelectorFilterTest.java @@ -0,0 +1,108 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.filter; + +import junit.framework.TestCase; + +import org.apache.qpid.AMQInternalException; +import org.apache.qpid.client.message.JMSTextMessage; +import org.apache.qpid.client.message.TestMessageHelper; + +public class JMSSelectorFilterTest extends TestCase +{ + + public void testEmptySelectorFilter() throws Exception + { + try + { + new JMSSelectorFilter(""); + fail("Should not be able to create a JMSSelectorFilter with an empty selector"); + } + catch (IllegalArgumentException iae) + { + // pass + } + } + + public void testNullSelectorFilter() throws Exception + { + try + { + new JMSSelectorFilter(null); + fail("Should not be able to create a JMSSelectorFilter with a null selector"); + } + catch (IllegalArgumentException iae) + { + // pass + } + } + + public void testInvalidSelectorFilter() throws Exception + { + try + { + new JMSSelectorFilter("$%^"); + fail("Unparsable selector so expected AMQInternalException to be thrown"); + } + catch (AMQInternalException amqie) + { + // pass + } + } + + public void testSimpleSelectorFilter() throws Exception + { + MessageFilter simpleSelectorFilter = new JMSSelectorFilter("select=5"); + + assertNotNull("Filter object is null", simpleSelectorFilter); + assertNotNull("Selector string is null", simpleSelectorFilter.getSelector()); + assertEquals("Unexpected selector", "select=5", simpleSelectorFilter.getSelector()); + assertTrue("Filter object is invalid", simpleSelectorFilter != null); + + final JMSTextMessage message = TestMessageHelper.newJMSTextMessage(); + + message.setIntProperty("select", 4); + assertFalse("Selector did match when not expected", simpleSelectorFilter.matches(message)); + message.setIntProperty("select", 5); + assertTrue("Selector didnt match when expected", simpleSelectorFilter.matches(message)); + message.setIntProperty("select", 6); + assertFalse("Selector did match when not expected", simpleSelectorFilter.matches(message)); + } + + public void testFailedMatchingFilter() throws Exception + { + MessageFilter simpleSelectorFilter = new JMSSelectorFilter("select>4"); + + assertNotNull("Filter object is null", simpleSelectorFilter); + assertNotNull("Selector string is null", simpleSelectorFilter.getSelector()); + assertEquals("Unexpected selector", "select>4", simpleSelectorFilter.getSelector()); + assertTrue("Filter object is invalid", simpleSelectorFilter != null); + + final JMSTextMessage message = TestMessageHelper.newJMSTextMessage(); + + message.setStringProperty("select", "5"); + assertFalse("Selector matched when not expected", simpleSelectorFilter.matches(message)); + message.setStringProperty("select", "elephant"); + assertFalse("Selector matched when not expected", simpleSelectorFilter.matches(message)); + message.setBooleanProperty("select", false); + assertFalse("Selector matched when not expected", simpleSelectorFilter.matches(message)); + } +} diff --git a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java index 6759b43387..b9d1476055 100644 --- a/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java +++ b/qpid/java/client/src/test/java/org/apache/qpid/test/unit/message/TestAMQSession.java @@ -36,6 +36,7 @@ import org.apache.qpid.client.BasicMessageProducer_0_8; import org.apache.qpid.client.failover.FailoverException; import org.apache.qpid.client.message.AMQMessageDelegateFactory; import org.apache.qpid.client.protocol.AMQProtocolHandler; +import org.apache.qpid.filter.MessageFilter; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.framing.FieldTable; @@ -124,7 +125,7 @@ public class TestAMQSession extends AMQSession<BasicMessageConsumer_0_8, BasicMe return false; } - public void sendConsume(BasicMessageConsumer_0_8 consumer, AMQShortString queueName, AMQProtocolHandler protocolHandler, boolean nowait, String messageSelector, int tag) throws AMQException, FailoverException + public void sendConsume(BasicMessageConsumer_0_8 consumer, AMQShortString queueName, AMQProtocolHandler protocolHandler, boolean nowait, MessageFilter messageSelector, int tag) throws AMQException, FailoverException { } |
