You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2020/05/14 16:19:14 UTC

[qpid-jms] branch master updated: NO-JIRA: add some test peer tests verifying the emitted filter type and value

This is an automated email from the ASF dual-hosted git repository.

robbie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-jms.git


The following commit(s) were added to refs/heads/master by this push:
     new 664e041  NO-JIRA: add some test peer tests verifying the emitted filter type and value
664e041 is described below

commit 664e0413ff5f7fbe568b04fc5772f490d2ba5117
Author: Robbie Gemmell <ro...@apache.org>
AuthorDate: Thu May 14 17:18:33 2020 +0100

    NO-JIRA: add some test peer tests verifying the emitted filter type and value
---
 .../jms/integration/SessionIntegrationTest.java    | 42 ++++++++++++++++++
 .../testpeer/matchers/DescribedTypeMatcher.java    | 51 ++++++++++++++++++++++
 2 files changed, 93 insertions(+)

diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SessionIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SessionIntegrationTest.java
index ce50edc..0e19c07 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SessionIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/SessionIntegrationTest.java
@@ -21,6 +21,7 @@ package org.apache.qpid.jms.integration;
 import static org.apache.qpid.jms.provider.amqp.AmqpSupport.ANONYMOUS_RELAY;
 import static org.hamcrest.Matchers.arrayContaining;
 import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasEntry;
 import static org.hamcrest.Matchers.notNullValue;
 import static org.hamcrest.Matchers.nullValue;
 import static org.junit.Assert.assertEquals;
@@ -77,6 +78,7 @@ import org.apache.qpid.jms.test.testpeer.describedtypes.Rejected;
 import org.apache.qpid.jms.test.testpeer.describedtypes.sections.AmqpValueDescribedType;
 import org.apache.qpid.jms.test.testpeer.describedtypes.sections.HeaderDescribedType;
 import org.apache.qpid.jms.test.testpeer.matchers.AcceptedMatcher;
+import org.apache.qpid.jms.test.testpeer.matchers.DescribedTypeMatcher;
 import org.apache.qpid.jms.test.testpeer.matchers.ModifiedMatcher;
 import org.apache.qpid.jms.test.testpeer.matchers.ReleasedMatcher;
 import org.apache.qpid.jms.test.testpeer.matchers.SourceMatcher;
@@ -90,8 +92,10 @@ import org.apache.qpid.jms.util.Repeat;
 import org.apache.qpid.proton.amqp.Binary;
 import org.apache.qpid.proton.amqp.Symbol;
 import org.apache.qpid.proton.amqp.UnsignedInteger;
+import org.apache.qpid.proton.amqp.UnsignedLong;
 import org.apache.qpid.proton.amqp.messaging.Modified;
 import org.apache.qpid.proton.amqp.messaging.Released;
+import org.hamcrest.Matcher;
 import org.hamcrest.Matchers;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -285,6 +289,44 @@ public class SessionIntegrationTest extends QpidJmsTestCase {
     }
 
     @Test(timeout = 20000)
+    public void testCreateConsumerWithSimpleSelector() throws Exception {
+        doCreateConsumerWithSelectorTestImpl("myvar=42");
+    }
+
+    @Test(timeout = 20000)
+    public void testCreateConsumerWithQuotedVariableSelector() throws Exception {
+        doCreateConsumerWithSelectorTestImpl("\"my.quoted-var\"='some-value'");
+    }
+
+    private void doCreateConsumerWithSelectorTestImpl(String messageSelector) throws Exception {
+        try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
+            Connection connection = testFixture.establishConnecton(testPeer);
+            connection.start();
+
+            testPeer.expectBegin();
+
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+            Matcher<?> filterMapMatcher = hasEntry(equalTo(Symbol.valueOf("jms-selector")),
+                    new DescribedTypeMatcher(UnsignedLong.valueOf(0x0000468C00000004L), Symbol.valueOf("apache.org:selector-filter:string"), equalTo(messageSelector)));
+
+            SourceMatcher sourceMatcher = new SourceMatcher();
+            sourceMatcher.withFilter(filterMapMatcher);
+
+            testPeer.expectReceiverAttach(notNullValue(), sourceMatcher);
+            testPeer.expectLinkFlow();
+            testPeer.expectClose();
+
+            Queue queue = session.createQueue("myQueue");
+            session.createConsumer(queue, messageSelector);
+
+            connection.close();
+
+            testPeer.waitForAllHandlersToComplete(3000);
+        }
+    }
+
+    @Test(timeout = 20000)
     public void testCreateConsumerFailsWhenLinkRefusedAndAttachResponseWriteIsNotDeferred() throws Exception {
         doCreateConsumerFailsWhenLinkRefusedTestImpl(false);
     }
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/testpeer/matchers/DescribedTypeMatcher.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/testpeer/matchers/DescribedTypeMatcher.java
new file mode 100644
index 0000000..9f0e647
--- /dev/null
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/test/testpeer/matchers/DescribedTypeMatcher.java
@@ -0,0 +1,51 @@
+/*
+ * 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.jms.test.testpeer.matchers;
+
+import org.apache.qpid.jms.test.testpeer.DescriptorMatcher;
+import org.apache.qpid.proton.amqp.DescribedType;
+import org.apache.qpid.proton.amqp.Symbol;
+import org.apache.qpid.proton.amqp.UnsignedLong;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+
+public class DescribedTypeMatcher extends DescriptorMatcher
+{
+    private Matcher<?> valueMatcher;
+
+    public DescribedTypeMatcher(UnsignedLong expectedDescriptorCode, Symbol expectedDescriptorSymbol, Matcher<?> value)
+    {
+        super(expectedDescriptorCode, expectedDescriptorSymbol);
+        this.valueMatcher = value;
+    }
+
+    @Override
+    public void describeTo(Description description)
+    {
+        super.describeTo(description);
+        description.appendText(" and value ");
+        valueMatcher.describeTo(description);
+    }
+
+    @Override
+    protected boolean matchesSafely(DescribedType dt)
+    {
+        return super.matchesSafely(dt) && valueMatcher.matches(dt.getDescribed());
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org