Skip to content

Commit 9df356e

Browse files
committed
Fix destination checking in Artemis auto-configuration tests
Closes gh-18319
1 parent 7533bfd commit 9df356e

File tree

1 file changed

+26
-38
lines changed

1 file changed

+26
-38
lines changed

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/artemis/ArtemisAutoConfigurationTests.java

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
import java.util.UUID;
2222

2323
import javax.jms.ConnectionFactory;
24-
import javax.jms.Destination;
25-
import javax.jms.JMSException;
2624
import javax.jms.Message;
2725
import javax.jms.TextMessage;
2826

27+
import org.apache.activemq.artemis.api.core.RoutingType;
28+
import org.apache.activemq.artemis.api.core.SimpleString;
2929
import org.apache.activemq.artemis.api.core.TransportConfiguration;
3030
import org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory;
3131
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
32+
import org.apache.activemq.artemis.core.server.BindingQueryResult;
3233
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
3334
import org.apache.activemq.artemis.jms.server.config.JMSConfiguration;
3435
import org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration;
@@ -50,9 +51,6 @@
5051
import org.springframework.context.annotation.Configuration;
5152
import org.springframework.jms.connection.CachingConnectionFactory;
5253
import org.springframework.jms.core.JmsTemplate;
53-
import org.springframework.jms.core.SessionCallback;
54-
import org.springframework.jms.support.destination.DestinationResolver;
55-
import org.springframework.jms.support.destination.DynamicDestinationResolver;
5654

5755
import static org.assertj.core.api.Assertions.assertThat;
5856

@@ -208,9 +206,9 @@ public void embeddedServerWithDestinations() {
208206
DestinationChecker checker = new DestinationChecker(context);
209207
checker.checkQueue("Queue1", true);
210208
checker.checkQueue("Queue2", true);
211-
checker.checkQueue("QueueWillNotBeAutoCreated", true);
209+
checker.checkQueue("NonExistentQueue", false);
212210
checker.checkTopic("Topic1", true);
213-
checker.checkTopic("TopicWillBeAutoCreated", true);
211+
checker.checkTopic("NonExistentTopic", false);
214212
});
215213
}
216214

@@ -230,8 +228,8 @@ public void embeddedServiceWithCustomJmsConfiguration() {
230228
.withPropertyValues("spring.artemis.embedded.queues=Queue1,Queue2").run((context) -> {
231229
DestinationChecker checker = new DestinationChecker(context);
232230
checker.checkQueue("custom", true); // See CustomJmsConfiguration
233-
checker.checkQueue("Queue1", true);
234-
checker.checkQueue("Queue2", true);
231+
checker.checkQueue("Queue1", false);
232+
checker.checkQueue("Queue2", false);
235233
});
236234
}
237235

@@ -275,10 +273,10 @@ public void severalEmbeddedBrokers() {
275273
.isLessThan(secondProperties.getEmbedded().getServerId());
276274
DestinationChecker firstChecker = new DestinationChecker(first);
277275
firstChecker.checkQueue("Queue1", true);
278-
firstChecker.checkQueue("Queue2", true);
276+
firstChecker.checkQueue("Queue2", false);
279277
DestinationChecker secondChecker = new DestinationChecker(second);
278+
secondChecker.checkQueue("Queue1", false);
280279
secondChecker.checkQueue("Queue2", true);
281-
secondChecker.checkQueue("Queue1", true);
282280
});
283281
});
284282
}
@@ -295,10 +293,9 @@ public void connectToASpecificEmbeddedBroker() {
295293
// Do not start a specific one
296294
"spring.artemis.embedded.enabled=false")
297295
.run((secondContext) -> {
298-
DestinationChecker firstChecker = new DestinationChecker(first);
299-
firstChecker.checkQueue("Queue1", true);
300-
DestinationChecker secondChecker = new DestinationChecker(secondContext);
301-
secondChecker.checkQueue("Queue1", true);
296+
first.getBean(JmsTemplate.class).convertAndSend("Queue1", "test");
297+
assertThat(secondContext.getBean(JmsTemplate.class).receiveAndConvert("Queue1"))
298+
.isEqualTo("test");
302299
});
303300
});
304301
}
@@ -394,40 +391,31 @@ private TransportConfiguration getSingleTransportConfiguration(ActiveMQConnectio
394391

395392
private static final class DestinationChecker {
396393

397-
private final JmsTemplate jmsTemplate;
398-
399-
private final DestinationResolver destinationResolver;
394+
private final EmbeddedJMS embeddedJms;
400395

401396
private DestinationChecker(ApplicationContext applicationContext) {
402-
this.jmsTemplate = applicationContext.getBean(JmsTemplate.class);
403-
this.destinationResolver = new DynamicDestinationResolver();
397+
this.embeddedJms = applicationContext.getBean(EmbeddedJMS.class);
404398
}
405399

406400
public void checkQueue(String name, boolean shouldExist) {
407-
checkDestination(name, false, shouldExist);
401+
checkDestination(name, RoutingType.ANYCAST, shouldExist);
408402
}
409403

410404
public void checkTopic(String name, boolean shouldExist) {
411-
checkDestination(name, true, shouldExist);
405+
checkDestination(name, RoutingType.MULTICAST, shouldExist);
412406
}
413407

414-
public void checkDestination(String name, final boolean pubSub, final boolean shouldExist) {
415-
this.jmsTemplate.execute((SessionCallback<Void>) (session) -> {
416-
try {
417-
Destination destination = this.destinationResolver.resolveDestinationName(session, name, pubSub);
418-
if (!shouldExist) {
419-
throw new IllegalStateException(
420-
"Destination '" + name + "' was not expected but got " + destination);
421-
}
422-
}
423-
catch (JMSException ex) {
424-
if (shouldExist) {
425-
throw new IllegalStateException(
426-
"Destination '" + name + "' was expected but got " + ex.getMessage());
427-
}
408+
public void checkDestination(String name, RoutingType routingType, boolean shouldExist) {
409+
try {
410+
BindingQueryResult result = this.embeddedJms.getActiveMQServer().bindingQuery(new SimpleString(name));
411+
assertThat(result.isExists()).isEqualTo(shouldExist);
412+
if (shouldExist) {
413+
assertThat(result.getAddressInfo().getRoutingType()).isEqualTo(routingType);
428414
}
429-
return null;
430-
});
415+
}
416+
catch (Exception ex) {
417+
throw new RuntimeException(ex);
418+
}
431419
}
432420

433421
}

0 commit comments

Comments
 (0)