Skip to content

Commit 26eb53a

Browse files
acogoluegnesansd
authored andcommitted
Add JMS selector tests from QPid test suite
1 parent 5b963ba commit 26eb53a

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// The contents of this file are subject to the Mozilla Public License
2+
// Version 2.0 (the "License"); you may not use this file except in
3+
// compliance with the License. You may obtain a copy of the License
4+
// at https://www.mozilla.org/en-US/MPL/2.0/
5+
//
6+
// Software distributed under the License is distributed on an "AS IS"
7+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8+
// the License for the specific language governing rights and
9+
// limitations under the License.
10+
//
11+
// The Original Code is RabbitMQ.
12+
//
13+
// The Initial Developer of the Original Code is Pivotal Software, Inc.
14+
// Copyright (c) 2025 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc.
15+
// and/or its subsidiaries. All rights reserved.
16+
//
17+
package com.rabbitmq.amqp.tests.jms;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
21+
import jakarta.jms.Connection;
22+
import jakarta.jms.ConnectionFactory;
23+
import jakarta.jms.DeliveryMode;
24+
import jakarta.jms.Message;
25+
import jakarta.jms.MessageConsumer;
26+
import jakarta.jms.MessageProducer;
27+
import jakarta.jms.Queue;
28+
import jakarta.jms.Session;
29+
import jakarta.jms.TextMessage;
30+
import org.junit.jupiter.api.Test;
31+
import org.junit.jupiter.api.Timeout;
32+
33+
/**
34+
* Based on
35+
* https://github.com/apache/qpid-jms/blob/main/qpid-jms-interop-tests/qpid-jms-activemq-tests/src/test/java/org/apache/qpid/jms/consumer/JmsMessageConsumerTest.java.
36+
*/
37+
@JmsTestInfrastructure
38+
public class JmsConsumerTest {
39+
40+
ConnectionFactory factory;
41+
42+
@Test
43+
@Timeout(30)
44+
void testSelectors(
45+
@TestUtils.QueueArgs(
46+
boolArgs = {@TestUtils.QueueArgBool(name = "x-filter-enabled", value = true)},
47+
listArgs = {
48+
@TestUtils.QueueArgList(
49+
name = "x-filter-field-names",
50+
values = {"priority"})
51+
})
52+
Queue queue)
53+
throws Exception {
54+
try (Connection connection = factory.createConnection()) {
55+
connection.start();
56+
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
57+
MessageProducer p = session.createProducer(queue);
58+
59+
TextMessage message = session.createTextMessage();
60+
message.setText("hello");
61+
p.send(message, DeliveryMode.PERSISTENT, 5, 0);
62+
63+
message = session.createTextMessage();
64+
message.setText("hello + 9");
65+
p.send(message, DeliveryMode.PERSISTENT, 9, 0);
66+
67+
p.close();
68+
69+
MessageConsumer consumer = session.createConsumer(queue, "JMSPriority > 8");
70+
Message msg = consumer.receive(5000);
71+
assertThat(msg).isNotNull().isInstanceOf(TextMessage.class);
72+
assertThat(((TextMessage) msg).getText()).isEqualTo("hello + 9");
73+
assertThat(consumer.receive(1000)).isNull();
74+
}
75+
}
76+
77+
@Test
78+
@Timeout(45)
79+
void testSelectorsWithJMSType(@TestUtils.QueueArgs(
80+
boolArgs = {@TestUtils.QueueArgBool(name = "x-filter-enabled", value = true)},
81+
listArgs = {
82+
@TestUtils.QueueArgList(
83+
name = "x-filter-field-names",
84+
values = {"subject"})
85+
}) Queue queue) throws Exception {
86+
try (Connection connection = factory.createConnection()) {
87+
connection.start();
88+
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
89+
MessageProducer producer = session.createProducer(queue);
90+
91+
TextMessage message = session.createTextMessage();
92+
message.setText("text");
93+
producer.send(
94+
message,
95+
DeliveryMode.NON_PERSISTENT,
96+
Message.DEFAULT_PRIORITY,
97+
Message.DEFAULT_TIME_TO_LIVE);
98+
99+
TextMessage message2 = session.createTextMessage();
100+
String type = "myJMSType";
101+
message2.setJMSType(type);
102+
message2.setText("text + type");
103+
producer.send(
104+
message2,
105+
DeliveryMode.NON_PERSISTENT,
106+
Message.DEFAULT_PRIORITY,
107+
Message.DEFAULT_TIME_TO_LIVE);
108+
109+
producer.close();
110+
111+
MessageConsumer consumer = session.createConsumer(queue, "JMSType = '" + type + "'");
112+
Message msg = consumer.receive(5000);
113+
assertThat(msg).isNotNull().isInstanceOf(TextMessage.class);
114+
assertThat(msg.getJMSType()).isEqualTo(type);
115+
assertThat(((TextMessage) msg).getText()).isEqualTo("text + type");
116+
}
117+
}
118+
}

0 commit comments

Comments
 (0)