Skip to content

Commit b9cfbf7

Browse files
committed
Merge branch '2.1.x'
Closes gh-18323
2 parents 98ad5e5 + 9df356e commit b9cfbf7

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
@@ -23,14 +23,15 @@
2323
import java.util.UUID;
2424

2525
import javax.jms.ConnectionFactory;
26-
import javax.jms.Destination;
27-
import javax.jms.JMSException;
2826
import javax.jms.Message;
2927
import javax.jms.TextMessage;
3028

29+
import org.apache.activemq.artemis.api.core.RoutingType;
30+
import org.apache.activemq.artemis.api.core.SimpleString;
3131
import org.apache.activemq.artemis.api.core.TransportConfiguration;
3232
import org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory;
3333
import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
34+
import org.apache.activemq.artemis.core.server.BindingQueryResult;
3435
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
3536
import org.apache.activemq.artemis.jms.server.config.JMSConfiguration;
3637
import org.apache.activemq.artemis.jms.server.config.JMSQueueConfiguration;
@@ -51,9 +52,6 @@
5152
import org.springframework.context.annotation.Configuration;
5253
import org.springframework.jms.connection.CachingConnectionFactory;
5354
import org.springframework.jms.core.JmsTemplate;
54-
import org.springframework.jms.core.SessionCallback;
55-
import org.springframework.jms.support.destination.DestinationResolver;
56-
import org.springframework.jms.support.destination.DynamicDestinationResolver;
5755

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

@@ -206,9 +204,9 @@ void embeddedServerWithDestinations() {
206204
DestinationChecker checker = new DestinationChecker(context);
207205
checker.checkQueue("Queue1", true);
208206
checker.checkQueue("Queue2", true);
209-
checker.checkQueue("QueueWillNotBeAutoCreated", true);
207+
checker.checkQueue("NonExistentQueue", false);
210208
checker.checkTopic("Topic1", true);
211-
checker.checkTopic("TopicWillBeAutoCreated", true);
209+
checker.checkTopic("NonExistentTopic", false);
212210
});
213211
}
214212

@@ -228,8 +226,8 @@ void embeddedServiceWithCustomJmsConfiguration() {
228226
.withPropertyValues("spring.artemis.embedded.queues=Queue1,Queue2").run((context) -> {
229227
DestinationChecker checker = new DestinationChecker(context);
230228
checker.checkQueue("custom", true); // See CustomJmsConfiguration
231-
checker.checkQueue("Queue1", true);
232-
checker.checkQueue("Queue2", true);
229+
checker.checkQueue("Queue1", false);
230+
checker.checkQueue("Queue2", false);
233231
});
234232
}
235233

@@ -273,10 +271,10 @@ void severalEmbeddedBrokers() {
273271
.isLessThan(secondProperties.getEmbedded().getServerId());
274272
DestinationChecker firstChecker = new DestinationChecker(first);
275273
firstChecker.checkQueue("Queue1", true);
276-
firstChecker.checkQueue("Queue2", true);
274+
firstChecker.checkQueue("Queue2", false);
277275
DestinationChecker secondChecker = new DestinationChecker(second);
276+
secondChecker.checkQueue("Queue1", false);
278277
secondChecker.checkQueue("Queue2", true);
279-
secondChecker.checkQueue("Queue1", true);
280278
});
281279
});
282280
}
@@ -293,10 +291,9 @@ void connectToASpecificEmbeddedBroker() {
293291
// Do not start a specific one
294292
"spring.artemis.embedded.enabled=false")
295293
.run((secondContext) -> {
296-
DestinationChecker firstChecker = new DestinationChecker(first);
297-
firstChecker.checkQueue("Queue1", true);
298-
DestinationChecker secondChecker = new DestinationChecker(secondContext);
299-
secondChecker.checkQueue("Queue1", true);
294+
first.getBean(JmsTemplate.class).convertAndSend("Queue1", "test");
295+
assertThat(secondContext.getBean(JmsTemplate.class).receiveAndConvert("Queue1"))
296+
.isEqualTo("test");
300297
});
301298
});
302299
}
@@ -382,40 +379,31 @@ private TransportConfiguration getSingleTransportConfiguration(ActiveMQConnectio
382379

383380
private static final class DestinationChecker {
384381

385-
private final JmsTemplate jmsTemplate;
386-
387-
private final DestinationResolver destinationResolver;
382+
private final EmbeddedJMS embeddedJms;
388383

389384
private DestinationChecker(ApplicationContext applicationContext) {
390-
this.jmsTemplate = applicationContext.getBean(JmsTemplate.class);
391-
this.destinationResolver = new DynamicDestinationResolver();
385+
this.embeddedJms = applicationContext.getBean(EmbeddedJMS.class);
392386
}
393387

394388
void checkQueue(String name, boolean shouldExist) {
395-
checkDestination(name, false, shouldExist);
389+
checkDestination(name, RoutingType.ANYCAST, shouldExist);
396390
}
397391

398392
void checkTopic(String name, boolean shouldExist) {
399-
checkDestination(name, true, shouldExist);
393+
checkDestination(name, RoutingType.MULTICAST, shouldExist);
400394
}
401395

402-
void checkDestination(String name, final boolean pubSub, final boolean shouldExist) {
403-
this.jmsTemplate.execute((SessionCallback<Void>) (session) -> {
404-
try {
405-
Destination destination = this.destinationResolver.resolveDestinationName(session, name, pubSub);
406-
if (!shouldExist) {
407-
throw new IllegalStateException(
408-
"Destination '" + name + "' was not expected but got " + destination);
409-
}
410-
}
411-
catch (JMSException ex) {
412-
if (shouldExist) {
413-
throw new IllegalStateException(
414-
"Destination '" + name + "' was expected but got " + ex.getMessage());
415-
}
396+
void checkDestination(String name, RoutingType routingType, boolean shouldExist) {
397+
try {
398+
BindingQueryResult result = this.embeddedJms.getActiveMQServer().bindingQuery(new SimpleString(name));
399+
assertThat(result.isExists()).isEqualTo(shouldExist);
400+
if (shouldExist) {
401+
assertThat(result.getAddressInfo().getRoutingType()).isEqualTo(routingType);
416402
}
417-
return null;
418-
});
403+
}
404+
catch (Exception ex) {
405+
throw new RuntimeException(ex);
406+
}
419407
}
420408

421409
}

0 commit comments

Comments
 (0)