Polishing

This commit is contained in:
Juergen Hoeller
2024-02-16 22:27:09 +01:00
parent 26ca7c49fb
commit 3aae7a66e6
9 changed files with 74 additions and 68 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -105,8 +105,7 @@ class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
void containerAreStartedByDefault() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
EnableJmsDefaultContainerFactoryConfig.class, DefaultBean.class);
JmsListenerContainerTestFactory factory =
context.getBean(JmsListenerContainerTestFactory.class);
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
MessageListenerTestContainer container = factory.getListenerContainers().get(0);
assertThat(container.isAutoStartup()).isTrue();
assertThat(container.isStarted()).isTrue();
@@ -116,8 +115,7 @@ class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
void containerCanBeStarterViaTheRegistry() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
EnableJmsAutoStartupFalseConfig.class, DefaultBean.class);
JmsListenerContainerTestFactory factory =
context.getBean(JmsListenerContainerTestFactory.class);
JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
MessageListenerTestContainer container = factory.getListenerContainers().get(0);
assertThat(container.isAutoStartup()).isFalse();
assertThat(container.isStarted()).isFalse();
@@ -132,9 +130,9 @@ class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
EnableJmsHandlerMethodFactoryConfig.class, ValidationBean.class);
assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() ->
testJmsHandlerMethodFactoryConfiguration(context))
.withCauseInstanceOf(MethodArgumentNotValidException.class);
assertThatExceptionOfType(ListenerExecutionFailedException.class)
.isThrownBy(() -> testJmsHandlerMethodFactoryConfiguration(context))
.withCauseInstanceOf(MethodArgumentNotValidException.class);
}
@Override
@@ -156,19 +154,20 @@ class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
@Test
void composedJmsListeners() {
try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
EnableJmsDefaultContainerFactoryConfig.class, ComposedJmsListenersBean.class)) {
JmsListenerContainerTestFactory simpleFactory = context.getBean("jmsListenerContainerFactory",
JmsListenerContainerTestFactory.class);
EnableJmsDefaultContainerFactoryConfig.class, ComposedJmsListenersBean.class)) {
JmsListenerContainerTestFactory simpleFactory =
context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class);
assertThat(simpleFactory.getListenerContainers()).hasSize(2);
MethodJmsListenerEndpoint first = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer(
"first").getEndpoint();
MethodJmsListenerEndpoint first = (MethodJmsListenerEndpoint)
simpleFactory.getListenerContainer("first").getEndpoint();
assertThat(first.getId()).isEqualTo("first");
assertThat(first.getDestination()).isEqualTo("orderQueue");
assertThat(first.getConcurrency()).isNull();
MethodJmsListenerEndpoint second = (MethodJmsListenerEndpoint) simpleFactory.getListenerContainer(
"second").getEndpoint();
MethodJmsListenerEndpoint second = (MethodJmsListenerEndpoint)
simpleFactory.getListenerContainer("second").getEndpoint();
assertThat(second.getId()).isEqualTo("second");
assertThat(second.getDestination()).isEqualTo("billingQueue");
assertThat(second.getConcurrency()).isEqualTo("2-10");
@@ -178,9 +177,9 @@ class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
@Test
void unknownFactory() {
// not found
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
new AnnotationConfigApplicationContext(EnableJmsSampleConfig.class, CustomBean.class))
.withMessageContaining("customFactory");
assertThatExceptionOfType(BeanCreationException.class)
.isThrownBy(() -> new AnnotationConfigApplicationContext(EnableJmsSampleConfig.class, CustomBean.class))
.withMessageContaining("customFactory");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,15 +28,13 @@ public class JmsListenerContainerTestFactory implements JmsListenerContainerFact
private boolean autoStartup = true;
private final Map<String, MessageListenerTestContainer> listenerContainers =
new LinkedHashMap<>();
private final Map<String, MessageListenerTestContainer> listenerContainers = new LinkedHashMap<>();
public void setAutoStartup(boolean autoStartup) {
this.autoStartup = autoStartup;
}
public List<MessageListenerTestContainer> getListenerContainers() {
return new ArrayList<>(this.listenerContainers.values());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,6 +42,7 @@ import static org.junit.jupiter.params.provider.Arguments.arguments;
/**
* Observation tests for {@link AbstractMessageListenerContainer} implementations.
*
* @author Brian Clozel
*/
class MessageListenerContainerObservationTests {
@@ -75,8 +76,8 @@ class MessageListenerContainerObservationTests {
assertThat(registry).hasObservationWithNameEqualTo("jms.message.process")
.that()
.hasHighCardinalityKeyValue("messaging.destination.name", "spring.test.observation");
listenerContainer.shutdown();
listenerContainer.stop();
listenerContainer.shutdown();
}
@ParameterizedTest(name = "[{index}] {0}")
@@ -103,8 +104,8 @@ class MessageListenerContainerObservationTests {
assertThat(registry).hasObservationWithNameEqualTo("jms.message.process")
.that()
.hasHighCardinalityKeyValue("messaging.destination.name", "spring.test.observation");
listenerContainer.shutdown();
listenerContainer.stop();
listenerContainer.shutdown();
}
static Stream<Arguments> listenerContainers() {