Polishing
This commit is contained in:
parent
da9c80c604
commit
760bc719f2
|
@ -302,7 +302,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe
|
||||||
Class<?> targetBeanClass = targetBean.getClass();
|
Class<?> targetBeanClass = targetBean.getClass();
|
||||||
if (!methodDeclaringClass.isAssignableFrom(targetBeanClass)) {
|
if (!methodDeclaringClass.isAssignableFrom(targetBeanClass)) {
|
||||||
String msg = "The event listener method class '" + methodDeclaringClass.getName() +
|
String msg = "The event listener method class '" + methodDeclaringClass.getName() +
|
||||||
"' is not an instance of the actual bean instance '" +
|
"' is not an instance of the actual bean class '" +
|
||||||
targetBeanClass.getName() + "'. If the bean requires proxying " +
|
targetBeanClass.getName() + "'. If the bean requires proxying " +
|
||||||
"(e.g. due to @Transactional), please use class-based proxying.";
|
"(e.g. due to @Transactional), please use class-based proxying.";
|
||||||
throw new IllegalStateException(getInvocationErrorMessage(targetBean, msg, args));
|
throw new IllegalStateException(getInvocationErrorMessage(targetBean, msg, args));
|
||||||
|
|
|
@ -391,12 +391,10 @@ public class AnnotatedElementUtils {
|
||||||
* the result back into an annotation of the specified {@code annotationType}.
|
* the result back into an annotation of the specified {@code annotationType}.
|
||||||
* <p>{@link AliasFor @AliasFor} semantics are fully supported, both
|
* <p>{@link AliasFor @AliasFor} semantics are fully supported, both
|
||||||
* within a single annotation and within the annotation hierarchy.
|
* within a single annotation and within the annotation hierarchy.
|
||||||
* <p>This method delegates to {@link #findMergedAnnotation(AnnotatedElement, String)}.
|
|
||||||
* @param element the annotated element
|
* @param element the annotated element
|
||||||
* @param annotationType the annotation type to find
|
* @param annotationType the annotation type to find
|
||||||
* @return the merged, synthesized {@code Annotation}, or {@code null} if not found
|
* @return the merged, synthesized {@code Annotation}, or {@code null} if not found
|
||||||
* @since 4.2
|
* @since 4.2
|
||||||
* @see #findMergedAnnotation(AnnotatedElement, String)
|
|
||||||
* @see #findMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean)
|
* @see #findMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean)
|
||||||
* @see #getMergedAnnotationAttributes(AnnotatedElement, Class)
|
* @see #getMergedAnnotationAttributes(AnnotatedElement, Class)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -52,6 +52,7 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||||
@Rule
|
@Rule
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
public final ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public abstract void sampleConfiguration();
|
public abstract void sampleConfiguration();
|
||||||
|
|
||||||
|
@ -79,6 +80,7 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||||
@Test
|
@Test
|
||||||
public abstract void jmsListeners();
|
public abstract void jmsListeners();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link SampleBean} discovery. If a factory with the default name
|
* Test for {@link SampleBean} discovery. If a factory with the default name
|
||||||
* is set, an endpoint will use it automatically
|
* is set, an endpoint will use it automatically
|
||||||
|
@ -92,18 +94,6 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||||
assertEquals(1, simpleFactory.getListenerContainers().size());
|
assertEquals(1, simpleFactory.getListenerContainers().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component
|
|
||||||
static class SampleBean {
|
|
||||||
|
|
||||||
@JmsListener(destination = "myQueue")
|
|
||||||
public void defaultHandle(String msg) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@JmsListener(containerFactory = "simpleFactory", destination = "myQueue")
|
|
||||||
public void simpleHandle(String msg) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link FullBean} discovery. In this case, no default is set because
|
* Test for {@link FullBean} discovery. In this case, no default is set because
|
||||||
* all endpoints provide a default registry. This shows that the default factory
|
* all endpoints provide a default registry. This shows that the default factory
|
||||||
|
@ -127,29 +117,6 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||||
assertEquals("queueOut", destination);
|
assertEquals("queueOut", destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component
|
|
||||||
static class FullBean {
|
|
||||||
|
|
||||||
@JmsListener(id = "listener1", containerFactory = "simpleFactory", destination = "queueIn",
|
|
||||||
selector = "mySelector", subscription = "mySubscription", concurrency = "1-10")
|
|
||||||
@SendTo("queueOut")
|
|
||||||
public String fullHandle(String msg) {
|
|
||||||
return "reply";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Component
|
|
||||||
static class FullConfigurableBean {
|
|
||||||
|
|
||||||
@JmsListener(id = "${jms.listener.id}", containerFactory = "${jms.listener.containerFactory}",
|
|
||||||
destination = "${jms.listener.destination}", selector = "${jms.listener.selector}",
|
|
||||||
subscription = "${jms.listener.subscription}", concurrency = "${jms.listener.concurrency}")
|
|
||||||
@SendTo("${jms.listener.sendTo}")
|
|
||||||
public String fullHandle(String msg) {
|
|
||||||
return "reply";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link CustomBean} and an manually endpoint registered
|
* Test for {@link CustomBean} and an manually endpoint registered
|
||||||
* with "myCustomEndpointId". The custom endpoint does not provide
|
* with "myCustomEndpointId". The custom endpoint does not provide
|
||||||
|
@ -179,14 +146,6 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||||
customRegistry.getListenerContainer("myCustomEndpointId"));
|
customRegistry.getListenerContainer("myCustomEndpointId"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component
|
|
||||||
static class CustomBean {
|
|
||||||
|
|
||||||
@JmsListener(id = "listenerId", containerFactory = "customFactory", destination = "myQueue")
|
|
||||||
public void customHandle(String msg) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link DefaultBean} that does not define the container
|
* Test for {@link DefaultBean} that does not define the container
|
||||||
* factory to use as a default is registered with an explicit
|
* factory to use as a default is registered with an explicit
|
||||||
|
@ -208,13 +167,6 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||||
assertEquals(1, defaultFactory.getListenerContainers().size());
|
assertEquals(1, defaultFactory.getListenerContainers().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
static class DefaultBean {
|
|
||||||
|
|
||||||
@JmsListener(destination = "myQueue")
|
|
||||||
public void handleIt(String msg) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link ValidationBean} with a validator ({@link TestValidator}) specified
|
* Test for {@link ValidationBean} with a validator ({@link TestValidator}) specified
|
||||||
* in a custom {@link org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory}.
|
* in a custom {@link org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory}.
|
||||||
|
@ -234,14 +186,6 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||||
listener.onMessage(new StubTextMessage("failValidation"), mock(Session.class));
|
listener.onMessage(new StubTextMessage("failValidation"), mock(Session.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component
|
|
||||||
static class ValidationBean {
|
|
||||||
|
|
||||||
@JmsListener(containerFactory = "defaultFactory", destination = "myQueue")
|
|
||||||
public void defaultHandle(@Validated String msg) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link JmsListenerRepeatableBean} and {@link JmsListenersBean} that validates that the
|
* Test for {@link JmsListenerRepeatableBean} and {@link JmsListenersBean} that validates that the
|
||||||
* {@code @JmsListener} annotation is repeatable and generate one specific container per annotation.
|
* {@code @JmsListener} annotation is repeatable and generate one specific container per annotation.
|
||||||
|
@ -264,6 +208,71 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||||
assertEquals("2-10", second.getConcurrency());
|
assertEquals("2-10", second.getConcurrency());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Component
|
||||||
|
static class SampleBean {
|
||||||
|
|
||||||
|
@JmsListener(destination = "myQueue")
|
||||||
|
public void defaultHandle(String msg) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@JmsListener(containerFactory = "simpleFactory", destination = "myQueue")
|
||||||
|
public void simpleHandle(String msg) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Component
|
||||||
|
static class FullBean {
|
||||||
|
|
||||||
|
@JmsListener(id = "listener1", containerFactory = "simpleFactory", destination = "queueIn",
|
||||||
|
selector = "mySelector", subscription = "mySubscription", concurrency = "1-10")
|
||||||
|
@SendTo("queueOut")
|
||||||
|
public String fullHandle(String msg) {
|
||||||
|
return "reply";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Component
|
||||||
|
static class FullConfigurableBean {
|
||||||
|
|
||||||
|
@JmsListener(id = "${jms.listener.id}", containerFactory = "${jms.listener.containerFactory}",
|
||||||
|
destination = "${jms.listener.destination}", selector = "${jms.listener.selector}",
|
||||||
|
subscription = "${jms.listener.subscription}", concurrency = "${jms.listener.concurrency}")
|
||||||
|
@SendTo("${jms.listener.sendTo}")
|
||||||
|
public String fullHandle(String msg) {
|
||||||
|
return "reply";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Component
|
||||||
|
static class CustomBean {
|
||||||
|
|
||||||
|
@JmsListener(id = "listenerId", containerFactory = "customFactory", destination = "myQueue")
|
||||||
|
public void customHandle(String msg) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static class DefaultBean {
|
||||||
|
|
||||||
|
@JmsListener(destination = "myQueue")
|
||||||
|
public void handleIt(String msg) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Component
|
||||||
|
static class ValidationBean {
|
||||||
|
|
||||||
|
@JmsListener(containerFactory = "defaultFactory", destination = "myQueue")
|
||||||
|
public void defaultHandle(@Validated String msg) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
static class JmsListenerRepeatableBean {
|
static class JmsListenerRepeatableBean {
|
||||||
|
|
||||||
|
@ -271,9 +280,9 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||||
@JmsListener(id = "second", destination = "anotherQueue", concurrency = "2-10")
|
@JmsListener(id = "second", destination = "anotherQueue", concurrency = "2-10")
|
||||||
public void repeatableHandle(String msg) {
|
public void repeatableHandle(String msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
static class JmsListenersBean {
|
static class JmsListenersBean {
|
||||||
|
|
||||||
|
@ -283,9 +292,9 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||||
})
|
})
|
||||||
public void repeatableHandle(String msg) {
|
public void repeatableHandle(String msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class TestValidator implements Validator {
|
static class TestValidator implements Validator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -301,4 +310,5 @@ public abstract class AbstractJmsAnnotationDrivenTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ import org.springframework.jms.listener.adapter.ListenerExecutionFailedException
|
||||||
import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException;
|
import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
*/
|
*/
|
||||||
public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenTests {
|
public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenTests {
|
||||||
|
@ -75,6 +74,7 @@ public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenT
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Test
|
||||||
public void defaultContainerFactory() {
|
public void defaultContainerFactory() {
|
||||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||||
"annotation-driven-default-container-factory.xml", getClass());
|
"annotation-driven-default-container-factory.xml", getClass());
|
||||||
|
@ -82,6 +82,7 @@ public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenT
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Test
|
||||||
public void jmsHandlerMethodFactoryConfiguration() throws JMSException {
|
public void jmsHandlerMethodFactoryConfiguration() throws JMSException {
|
||||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||||
"annotation-driven-custom-handler-method-factory.xml", getClass());
|
"annotation-driven-custom-handler-method-factory.xml", getClass());
|
||||||
|
@ -92,6 +93,7 @@ public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenT
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Test
|
||||||
public void jmsListenerIsRepeatable() {
|
public void jmsListenerIsRepeatable() {
|
||||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||||
"annotation-driven-jms-listener-repeatable.xml", getClass());
|
"annotation-driven-jms-listener-repeatable.xml", getClass());
|
||||||
|
@ -99,12 +101,14 @@ public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenT
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Test
|
||||||
public void jmsListeners() {
|
public void jmsListeners() {
|
||||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||||
"annotation-driven-jms-listeners.xml", getClass());
|
"annotation-driven-jms-listeners.xml", getClass());
|
||||||
testJmsListenerRepeatable(context);
|
testJmsListenerRepeatable(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class CustomJmsListenerConfigurer implements JmsListenerConfigurer {
|
static class CustomJmsListenerConfigurer implements JmsListenerConfigurer {
|
||||||
|
|
||||||
private MessageListener messageListener;
|
private MessageListener messageListener;
|
||||||
|
@ -121,6 +125,6 @@ public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenT
|
||||||
public void setMessageListener(MessageListener messageListener) {
|
public void setMessageListener(MessageListener messageListener) {
|
||||||
this.messageListener = messageListener;
|
this.messageListener = messageListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||||
@Rule
|
@Rule
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
public final ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test
|
@Test
|
||||||
public void sampleConfiguration() {
|
public void sampleConfiguration() {
|
||||||
|
@ -113,6 +114,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Test
|
||||||
public void jmsListenerIsRepeatable() {
|
public void jmsListenerIsRepeatable() {
|
||||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
|
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
EnableJmsDefaultContainerFactoryConfig.class, JmsListenerRepeatableBean.class);
|
EnableJmsDefaultContainerFactoryConfig.class, JmsListenerRepeatableBean.class);
|
||||||
|
@ -120,6 +122,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Test
|
||||||
public void jmsListeners() {
|
public void jmsListeners() {
|
||||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
|
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
|
||||||
EnableJmsDefaultContainerFactoryConfig.class, JmsListenersBean.class);
|
EnableJmsDefaultContainerFactoryConfig.class, JmsListenersBean.class);
|
||||||
|
@ -150,6 +153,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||||
assertTrue("Should have been stopped " + container, container.isStopped());
|
assertTrue("Should have been stopped " + container, container.isStopped());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@EnableJms
|
@EnableJms
|
||||||
@Configuration
|
@Configuration
|
||||||
static class EnableJmsSampleConfig {
|
static class EnableJmsSampleConfig {
|
||||||
|
@ -165,6 +169,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@EnableJms
|
@EnableJms
|
||||||
@Configuration
|
@Configuration
|
||||||
static class EnableJmsFullConfig {
|
static class EnableJmsFullConfig {
|
||||||
|
@ -175,6 +180,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@EnableJms
|
@EnableJms
|
||||||
@Configuration
|
@Configuration
|
||||||
@PropertySource("classpath:/org/springframework/jms/annotation/jms-listener.properties")
|
@PropertySource("classpath:/org/springframework/jms/annotation/jms-listener.properties")
|
||||||
|
@ -191,6 +197,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableJms
|
@EnableJms
|
||||||
static class EnableJmsCustomConfig implements JmsListenerConfigurer {
|
static class EnableJmsCustomConfig implements JmsListenerConfigurer {
|
||||||
|
@ -228,6 +235,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableJms
|
@EnableJms
|
||||||
static class EnableJmsCustomContainerFactoryConfig implements JmsListenerConfigurer {
|
static class EnableJmsCustomContainerFactoryConfig implements JmsListenerConfigurer {
|
||||||
|
@ -243,6 +251,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableJms
|
@EnableJms
|
||||||
static class EnableJmsDefaultContainerFactoryConfig {
|
static class EnableJmsDefaultContainerFactoryConfig {
|
||||||
|
@ -253,6 +262,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableJms
|
@EnableJms
|
||||||
static class EnableJmsHandlerMethodFactoryConfig implements JmsListenerConfigurer {
|
static class EnableJmsHandlerMethodFactoryConfig implements JmsListenerConfigurer {
|
||||||
|
@ -275,6 +285,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Lazy
|
@Lazy
|
||||||
static class LazyBean {
|
static class LazyBean {
|
||||||
|
|
|
@ -49,9 +49,6 @@ import static org.mockito.Mockito.*;
|
||||||
*/
|
*/
|
||||||
public class JmsListenerContainerFactoryTests {
|
public class JmsListenerContainerFactoryTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private final ConnectionFactory connectionFactory = new StubConnectionFactory();
|
private final ConnectionFactory connectionFactory = new StubConnectionFactory();
|
||||||
|
|
||||||
private final DestinationResolver destinationResolver = new DynamicDestinationResolver();
|
private final DestinationResolver destinationResolver = new DynamicDestinationResolver();
|
||||||
|
@ -61,6 +58,10 @@ public class JmsListenerContainerFactoryTests {
|
||||||
private final TransactionManager transactionManager = mock(TransactionManager.class);
|
private final TransactionManager transactionManager = mock(TransactionManager.class);
|
||||||
|
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createSimpleContainer() {
|
public void createSimpleContainer() {
|
||||||
SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory();
|
SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory();
|
||||||
|
@ -148,6 +149,7 @@ public class JmsListenerContainerFactoryTests {
|
||||||
assertSame(backOff, new DirectFieldAccessor(container).getPropertyValue("backOff"));
|
assertSame(backOff, new DirectFieldAccessor(container).getPropertyValue("backOff"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void setDefaultJmsConfig(AbstractJmsListenerContainerFactory<?> factory) {
|
private void setDefaultJmsConfig(AbstractJmsListenerContainerFactory<?> factory) {
|
||||||
factory.setConnectionFactory(connectionFactory);
|
factory.setConnectionFactory(connectionFactory);
|
||||||
factory.setDestinationResolver(destinationResolver);
|
factory.setDestinationResolver(destinationResolver);
|
||||||
|
|
|
@ -30,9 +30,6 @@ import static org.junit.Assert.*;
|
||||||
*/
|
*/
|
||||||
public class JmsListenerEndpointRegistrarTests {
|
public class JmsListenerEndpointRegistrarTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private final JmsListenerEndpointRegistrar registrar = new JmsListenerEndpointRegistrar();
|
private final JmsListenerEndpointRegistrar registrar = new JmsListenerEndpointRegistrar();
|
||||||
|
|
||||||
private final JmsListenerEndpointRegistry registry = new JmsListenerEndpointRegistry();
|
private final JmsListenerEndpointRegistry registry = new JmsListenerEndpointRegistry();
|
||||||
|
@ -40,12 +37,17 @@ public class JmsListenerEndpointRegistrarTests {
|
||||||
private final JmsListenerContainerTestFactory containerFactory = new JmsListenerContainerTestFactory();
|
private final JmsListenerContainerTestFactory containerFactory = new JmsListenerContainerTestFactory();
|
||||||
|
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
registrar.setEndpointRegistry(registry);
|
registrar.setEndpointRegistry(registry);
|
||||||
registrar.setBeanFactory(new StaticListableBeanFactory());
|
registrar.setBeanFactory(new StaticListableBeanFactory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void registerNullEndpoint() {
|
public void registerNullEndpoint() {
|
||||||
thrown.expect(IllegalArgumentException.class);
|
thrown.expect(IllegalArgumentException.class);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -21,18 +21,19 @@ import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
*/
|
*/
|
||||||
public class JmsListenerEndpointRegistryTests {
|
public class JmsListenerEndpointRegistryTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private final JmsListenerEndpointRegistry registry = new JmsListenerEndpointRegistry();
|
private final JmsListenerEndpointRegistry registry = new JmsListenerEndpointRegistry();
|
||||||
|
|
||||||
private final JmsListenerContainerTestFactory containerFactory = new JmsListenerContainerTestFactory();
|
private final JmsListenerContainerTestFactory containerFactory = new JmsListenerContainerTestFactory();
|
||||||
|
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createWithNullEndpoint() {
|
public void createWithNullEndpoint() {
|
||||||
thrown.expect(IllegalArgumentException.class);
|
thrown.expect(IllegalArgumentException.class);
|
||||||
|
@ -59,6 +60,7 @@ public class JmsListenerEndpointRegistryTests {
|
||||||
registry.registerListenerContainer(createEndpoint("test", "queue"), containerFactory);
|
registry.registerListenerContainer(createEndpoint("test", "queue"), containerFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private SimpleJmsListenerEndpoint createEndpoint(String id, String destinationName) {
|
private SimpleJmsListenerEndpoint createEndpoint(String id, String destinationName) {
|
||||||
SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
|
SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
|
||||||
endpoint.setId(id);
|
endpoint.setId(id);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -41,6 +41,7 @@ public class JmsListenerEndpointTests {
|
||||||
@Rule
|
@Rule
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
public final ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setupJmsMessageContainerFullConfig() {
|
public void setupJmsMessageContainerFullConfig() {
|
||||||
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
|
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
|
||||||
|
@ -112,5 +113,4 @@ public class JmsListenerEndpointTests {
|
||||||
endpoint.setupListenerContainer(container);
|
endpoint.setupListenerContainer(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,12 +71,6 @@ import static org.mockito.BDDMockito.*;
|
||||||
*/
|
*/
|
||||||
public class MethodJmsListenerEndpointTests {
|
public class MethodJmsListenerEndpointTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final TestName name = new TestName();
|
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private final DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
|
private final DefaultMessageHandlerMethodFactory factory = new DefaultMessageHandlerMethodFactory();
|
||||||
|
|
||||||
private final DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
|
private final DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
|
||||||
|
@ -84,11 +78,19 @@ public class MethodJmsListenerEndpointTests {
|
||||||
private final JmsEndpointSampleBean sample = new JmsEndpointSampleBean();
|
private final JmsEndpointSampleBean sample = new JmsEndpointSampleBean();
|
||||||
|
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final TestName name = new TestName();
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
initializeFactory(factory);
|
initializeFactory(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createMessageListenerNoFactory() {
|
public void createMessageListenerNoFactory() {
|
||||||
MethodJmsListenerEndpoint endpoint = new MethodJmsListenerEndpoint();
|
MethodJmsListenerEndpoint endpoint = new MethodJmsListenerEndpoint();
|
||||||
|
@ -401,8 +403,10 @@ public class MethodJmsListenerEndpointTests {
|
||||||
listener.onMessage(createSimpleJmsTextMessage("test"), session); // Message<String> as Message<Integer>
|
listener.onMessage(createSimpleJmsTextMessage("test"), session); // Message<String> as Message<Integer>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private MessagingMessageListenerAdapter createInstance(
|
private MessagingMessageListenerAdapter createInstance(
|
||||||
DefaultMessageHandlerMethodFactory factory, Method method, MessageListenerContainer container) {
|
DefaultMessageHandlerMethodFactory factory, Method method, MessageListenerContainer container) {
|
||||||
|
|
||||||
MethodJmsListenerEndpoint endpoint = new MethodJmsListenerEndpoint();
|
MethodJmsListenerEndpoint endpoint = new MethodJmsListenerEndpoint();
|
||||||
endpoint.setBean(sample);
|
endpoint.setBean(sample);
|
||||||
endpoint.setMethod(method);
|
endpoint.setMethod(method);
|
||||||
|
@ -410,8 +414,7 @@ public class MethodJmsListenerEndpointTests {
|
||||||
return endpoint.createMessageListener(container);
|
return endpoint.createMessageListener(container);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MessagingMessageListenerAdapter createInstance(
|
private MessagingMessageListenerAdapter createInstance(DefaultMessageHandlerMethodFactory factory, Method method) {
|
||||||
DefaultMessageHandlerMethodFactory factory, Method method) {
|
|
||||||
return createInstance(factory, method, new SimpleMessageListenerContainer());
|
return createInstance(factory, method, new SimpleMessageListenerContainer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -575,8 +578,8 @@ public class MethodJmsListenerEndpointTests {
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
static class MyBean implements Serializable {
|
static class MyBean implements Serializable {
|
||||||
private String name;
|
|
||||||
|
|
||||||
|
private String name;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -26,13 +26,13 @@ import org.springframework.jms.listener.adapter.MessageListenerAdapter;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
*/
|
*/
|
||||||
public class SimpleJmsListenerEndpointTests {
|
public class SimpleJmsListenerEndpointTests {
|
||||||
|
|
||||||
private final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
|
private final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createListener() {
|
public void createListener() {
|
||||||
SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
|
SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
|
||||||
|
@ -40,4 +40,5 @@ public class SimpleJmsListenerEndpointTests {
|
||||||
endpoint.setMessageListener(messageListener);
|
endpoint.setMessageListener(messageListener);
|
||||||
assertSame(messageListener, endpoint.createMessageListener(container));
|
assertSame(messageListener, endpoint.createMessageListener(container));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,7 +232,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||||
Class<?> targetBeanClass = targetBean.getClass();
|
Class<?> targetBeanClass = targetBean.getClass();
|
||||||
if (!methodDeclaringClass.isAssignableFrom(targetBeanClass)) {
|
if (!methodDeclaringClass.isAssignableFrom(targetBeanClass)) {
|
||||||
String msg = "The mapped controller method class '" + methodDeclaringClass.getName() +
|
String msg = "The mapped controller method class '" + methodDeclaringClass.getName() +
|
||||||
"' is not an instance of the actual controller bean instance '" +
|
"' is not an instance of the actual controller bean class '" +
|
||||||
targetBeanClass.getName() + "'. If the controller requires proxying " +
|
targetBeanClass.getName() + "'. If the controller requires proxying " +
|
||||||
"(e.g. due to @Transactional), please use class-based proxying.";
|
"(e.g. due to @Transactional), please use class-based proxying.";
|
||||||
throw new IllegalStateException(getInvocationErrorMessage(msg, args));
|
throw new IllegalStateException(getInvocationErrorMessage(msg, args));
|
||||||
|
@ -242,7 +242,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||||
private String getInvocationErrorMessage(String message, Object[] resolvedArgs) {
|
private String getInvocationErrorMessage(String message, Object[] resolvedArgs) {
|
||||||
StringBuilder sb = new StringBuilder(getDetailedErrorMessage(message));
|
StringBuilder sb = new StringBuilder(getDetailedErrorMessage(message));
|
||||||
sb.append("Resolved arguments: \n");
|
sb.append("Resolved arguments: \n");
|
||||||
for (int i=0; i < resolvedArgs.length; i++) {
|
for (int i = 0; i < resolvedArgs.length; i++) {
|
||||||
sb.append("[").append(i).append("] ");
|
sb.append("[").append(i).append("] ");
|
||||||
if (resolvedArgs[i] == null) {
|
if (resolvedArgs[i] == null) {
|
||||||
sb.append("[null] \n");
|
sb.append("[null] \n");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2014 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -32,10 +32,10 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.context.support.StaticApplicationContext;
|
import org.springframework.context.support.StaticApplicationContext;
|
||||||
|
import org.springframework.core.MethodIntrospector;
|
||||||
import org.springframework.messaging.Message;
|
import org.springframework.messaging.Message;
|
||||||
import org.springframework.messaging.handler.DestinationPatternsMessageCondition;
|
import org.springframework.messaging.handler.DestinationPatternsMessageCondition;
|
||||||
import org.springframework.messaging.handler.HandlerMethod;
|
import org.springframework.messaging.handler.HandlerMethod;
|
||||||
import org.springframework.messaging.handler.HandlerMethodSelector;
|
|
||||||
import org.springframework.messaging.handler.annotation.support.MessageMethodArgumentResolver;
|
import org.springframework.messaging.handler.annotation.support.MessageMethodArgumentResolver;
|
||||||
import org.springframework.messaging.support.MessageBuilder;
|
import org.springframework.messaging.support.MessageBuilder;
|
||||||
import org.springframework.util.AntPathMatcher;
|
import org.springframework.util.AntPathMatcher;
|
||||||
|
@ -264,6 +264,7 @@ public class MethodMessageHandlerTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class TestExceptionHandlerMethodResolver extends AbstractExceptionHandlerMethodResolver {
|
private static class TestExceptionHandlerMethodResolver extends AbstractExceptionHandlerMethodResolver {
|
||||||
|
|
||||||
public TestExceptionHandlerMethodResolver(Class<?> handlerType) {
|
public TestExceptionHandlerMethodResolver(Class<?> handlerType) {
|
||||||
|
@ -272,7 +273,7 @@ public class MethodMessageHandlerTests {
|
||||||
|
|
||||||
private static Map<Class<? extends Throwable>, Method> initExceptionMappings(Class<?> handlerType) {
|
private static Map<Class<? extends Throwable>, Method> initExceptionMappings(Class<?> handlerType) {
|
||||||
Map<Class<? extends Throwable>, Method> result = new HashMap<Class<? extends Throwable>, Method>();
|
Map<Class<? extends Throwable>, Method> result = new HashMap<Class<? extends Throwable>, Method>();
|
||||||
for (Method method : HandlerMethodSelector.selectMethods(handlerType, EXCEPTION_HANDLER_METHOD_FILTER)) {
|
for (Method method : MethodIntrospector.selectMethods(handlerType, EXCEPTION_HANDLER_METHOD_FILTER)) {
|
||||||
for(Class<? extends Throwable> exception : getExceptionsFromMethodSignature(method)) {
|
for(Class<? extends Throwable> exception : getExceptionsFromMethodSignature(method)) {
|
||||||
result.put(exception, method);
|
result.put(exception, method);
|
||||||
}
|
}
|
||||||
|
@ -281,13 +282,11 @@ public class MethodMessageHandlerTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static MethodFilter EXCEPTION_HANDLER_METHOD_FILTER = new MethodFilter() {
|
public final static MethodFilter EXCEPTION_HANDLER_METHOD_FILTER = new MethodFilter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Method method) {
|
public boolean matches(Method method) {
|
||||||
return method.getName().contains("Exception");
|
return method.getName().contains("Exception");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,8 +52,7 @@ import static org.junit.Assert.*;
|
||||||
import static org.springframework.transaction.event.TransactionPhase.*;
|
import static org.springframework.transaction.event.TransactionPhase.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration tests for {@link TransactionalEventListener @TransactionalEventListener}
|
* Integration tests for {@link TransactionalEventListener} support
|
||||||
* support
|
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
|
@ -61,15 +60,16 @@ import static org.springframework.transaction.event.TransactionPhase.*;
|
||||||
*/
|
*/
|
||||||
public class TransactionalEventListenerTests {
|
public class TransactionalEventListenerTests {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public final ExpectedException thrown = ExpectedException.none();
|
|
||||||
|
|
||||||
private ConfigurableApplicationContext context;
|
private ConfigurableApplicationContext context;
|
||||||
|
|
||||||
private EventCollector eventCollector;
|
private EventCollector eventCollector;
|
||||||
|
|
||||||
private TransactionTemplate transactionTemplate = new TransactionTemplate(new CallCountingTransactionManager());
|
private TransactionTemplate transactionTemplate = new TransactionTemplate(new CallCountingTransactionManager());
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final ExpectedException thrown = ExpectedException.none();
|
||||||
|
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void closeContext() {
|
public void closeContext() {
|
||||||
if (this.context != null) {
|
if (this.context != null) {
|
||||||
|
@ -77,6 +77,7 @@ public class TransactionalEventListenerTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void immediately() {
|
public void immediately() {
|
||||||
load(ImmediateTestListener.class);
|
load(ImmediateTestListener.class);
|
||||||
|
@ -305,30 +306,6 @@ public class TransactionalEventListenerTests {
|
||||||
getEventCollector().assertNoEventReceived();
|
getEventCollector().assertNoEventReceived();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration
|
|
||||||
static class BasicConfiguration {
|
|
||||||
|
|
||||||
@Bean // set automatically with tx management
|
|
||||||
public TransactionalEventListenerFactory transactionalEventListenerFactory() {
|
|
||||||
return new TransactionalEventListenerFactory();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public EventCollector eventCollector() {
|
|
||||||
return new EventCollector();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EnableTransactionManagement
|
|
||||||
@Configuration
|
|
||||||
static class TransactionalConfiguration {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public CallCountingTransactionManager transactionManager() {
|
|
||||||
return new CallCountingTransactionManager();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected EventCollector getEventCollector() {
|
protected EventCollector getEventCollector() {
|
||||||
return eventCollector;
|
return eventCollector;
|
||||||
|
@ -350,6 +327,33 @@ public class TransactionalEventListenerTests {
|
||||||
this.eventCollector = this.context.getBean(EventCollector.class);
|
this.eventCollector = this.context.getBean(EventCollector.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
static class BasicConfiguration {
|
||||||
|
|
||||||
|
@Bean // set automatically with tx management
|
||||||
|
public TransactionalEventListenerFactory transactionalEventListenerFactory() {
|
||||||
|
return new TransactionalEventListenerFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public EventCollector eventCollector() {
|
||||||
|
return new EventCollector();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@EnableTransactionManagement
|
||||||
|
@Configuration
|
||||||
|
static class TransactionalConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CallCountingTransactionManager transactionManager() {
|
||||||
|
return new CallCountingTransactionManager();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static class EventCollector {
|
static class EventCollector {
|
||||||
|
|
||||||
public static final String IMMEDIATELY = "IMMEDIATELY";
|
public static final String IMMEDIATELY = "IMMEDIATELY";
|
||||||
|
@ -364,7 +368,6 @@ public class TransactionalEventListenerTests {
|
||||||
|
|
||||||
public static final String[] ALL_PHASES = {IMMEDIATELY, BEFORE_COMMIT, AFTER_COMMIT, AFTER_ROLLBACK};
|
public static final String[] ALL_PHASES = {IMMEDIATELY, BEFORE_COMMIT, AFTER_COMMIT, AFTER_ROLLBACK};
|
||||||
|
|
||||||
|
|
||||||
private final MultiValueMap<String, Object> events = new LinkedMultiValueMap<>();
|
private final MultiValueMap<String, Object> events = new LinkedMultiValueMap<>();
|
||||||
|
|
||||||
public void addEvent(String phase, Object event) {
|
public void addEvent(String phase, Object event) {
|
||||||
|
@ -402,9 +405,9 @@ public class TransactionalEventListenerTests {
|
||||||
assertEquals("Wrong number of total events (" + this.events.size() + ") " +
|
assertEquals("Wrong number of total events (" + this.events.size() + ") " +
|
||||||
"registered phase(s)", number, size);
|
"registered phase(s)", number, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static abstract class BaseTransactionalTestListener {
|
static abstract class BaseTransactionalTestListener {
|
||||||
|
|
||||||
static final String FAIL_MSG = "FAIL";
|
static final String FAIL_MSG = "FAIL";
|
||||||
|
@ -418,9 +421,9 @@ public class TransactionalEventListenerTests {
|
||||||
throw new IllegalStateException("Test exception on phase '" + phase + "'");
|
throw new IllegalStateException("Test exception on phase '" + phase + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
static class ImmediateTestListener extends BaseTransactionalTestListener {
|
static class ImmediateTestListener extends BaseTransactionalTestListener {
|
||||||
|
|
||||||
|
@ -430,6 +433,7 @@ public class TransactionalEventListenerTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
static class AfterCompletionTestListener extends BaseTransactionalTestListener {
|
static class AfterCompletionTestListener extends BaseTransactionalTestListener {
|
||||||
|
|
||||||
|
@ -439,6 +443,7 @@ public class TransactionalEventListenerTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
static class AfterCompletionExplicitTestListener extends BaseTransactionalTestListener {
|
static class AfterCompletionExplicitTestListener extends BaseTransactionalTestListener {
|
||||||
|
|
||||||
|
@ -453,6 +458,7 @@ public class TransactionalEventListenerTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Component
|
@Component
|
||||||
static interface TransactionalComponentTestListenerInterface {
|
static interface TransactionalComponentTestListenerInterface {
|
||||||
|
@ -462,6 +468,7 @@ public class TransactionalEventListenerTests {
|
||||||
void handleAfterCommit(String data);
|
void handleAfterCommit(String data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class TransactionalComponentTestListener extends BaseTransactionalTestListener implements
|
static class TransactionalComponentTestListener extends BaseTransactionalTestListener implements
|
||||||
TransactionalComponentTestListenerInterface {
|
TransactionalComponentTestListenerInterface {
|
||||||
|
|
||||||
|
@ -471,6 +478,7 @@ public class TransactionalEventListenerTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
static class BeforeCommitTestListener extends BaseTransactionalTestListener {
|
static class BeforeCommitTestListener extends BaseTransactionalTestListener {
|
||||||
|
|
||||||
|
@ -479,9 +487,9 @@ public class TransactionalEventListenerTests {
|
||||||
public void handleBeforeCommit(String data) {
|
public void handleBeforeCommit(String data) {
|
||||||
handleEvent(EventCollector.BEFORE_COMMIT, data);
|
handleEvent(EventCollector.BEFORE_COMMIT, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
static class FallbackExecutionTestListener extends BaseTransactionalTestListener {
|
static class FallbackExecutionTestListener extends BaseTransactionalTestListener {
|
||||||
|
|
||||||
|
@ -506,12 +514,14 @@ public class TransactionalEventListenerTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@TransactionalEventListener(phase = AFTER_COMMIT, condition = "!'SKIP'.equals(#p0)")
|
@TransactionalEventListener(phase = AFTER_COMMIT, condition = "!'SKIP'.equals(#p0)")
|
||||||
@Target(ElementType.METHOD)
|
@Target(ElementType.METHOD)
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@interface AfterCommitEventListener {
|
@interface AfterCommitEventListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
static class AfterCommitMetaAnnotationTestListener extends BaseTransactionalTestListener {
|
static class AfterCommitMetaAnnotationTestListener extends BaseTransactionalTestListener {
|
||||||
|
|
||||||
|
@ -519,10 +529,11 @@ public class TransactionalEventListenerTests {
|
||||||
public void handleAfterCommit(String data) {
|
public void handleAfterCommit(String data) {
|
||||||
handleEvent(EventCollector.AFTER_COMMIT, data);
|
handleEvent(EventCollector.AFTER_COMMIT, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class EventTransactionSynchronization extends TransactionSynchronizationAdapter {
|
static class EventTransactionSynchronization extends TransactionSynchronizationAdapter {
|
||||||
|
|
||||||
private final int order;
|
private final int order;
|
||||||
|
|
||||||
EventTransactionSynchronization(int order) {
|
EventTransactionSynchronization(int order) {
|
||||||
|
|
|
@ -256,7 +256,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||||
Class<?> targetBeanClass = targetBean.getClass();
|
Class<?> targetBeanClass = targetBean.getClass();
|
||||||
if (!methodDeclaringClass.isAssignableFrom(targetBeanClass)) {
|
if (!methodDeclaringClass.isAssignableFrom(targetBeanClass)) {
|
||||||
String msg = "The mapped controller method class '" + methodDeclaringClass.getName() +
|
String msg = "The mapped controller method class '" + methodDeclaringClass.getName() +
|
||||||
"' is not an instance of the actual controller bean instance '" +
|
"' is not an instance of the actual controller bean class '" +
|
||||||
targetBeanClass.getName() + "'. If the controller requires proxying " +
|
targetBeanClass.getName() + "'. If the controller requires proxying " +
|
||||||
"(e.g. due to @Transactional), please use class-based proxying.";
|
"(e.g. due to @Transactional), please use class-based proxying.";
|
||||||
throw new IllegalStateException(getInvocationErrorMessage(msg, args));
|
throw new IllegalStateException(getInvocationErrorMessage(msg, args));
|
||||||
|
@ -266,7 +266,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
|
||||||
private String getInvocationErrorMessage(String message, Object[] resolvedArgs) {
|
private String getInvocationErrorMessage(String message, Object[] resolvedArgs) {
|
||||||
StringBuilder sb = new StringBuilder(getDetailedErrorMessage(message));
|
StringBuilder sb = new StringBuilder(getDetailedErrorMessage(message));
|
||||||
sb.append("Resolved arguments: \n");
|
sb.append("Resolved arguments: \n");
|
||||||
for (int i=0; i < resolvedArgs.length; i++) {
|
for (int i = 0; i < resolvedArgs.length; i++) {
|
||||||
sb.append("[").append(i).append("] ");
|
sb.append("[").append(i).append("] ");
|
||||||
if (resolvedArgs[i] == null) {
|
if (resolvedArgs[i] == null) {
|
||||||
sb.append("[null] \n");
|
sb.append("[null] \n");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2013 the original author or authors.
|
* Copyright 2002-2015 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -172,7 +172,7 @@ public class ModelAttributeMethodProcessorTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resovleArgumentValidation() throws Exception {
|
public void resolveArgumentValidation() throws Exception {
|
||||||
String name = "attrName";
|
String name = "attrName";
|
||||||
Object target = new TestBean();
|
Object target = new TestBean();
|
||||||
mavContainer.addAttribute(name, target);
|
mavContainer.addAttribute(name, target);
|
||||||
|
@ -187,7 +187,7 @@ public class ModelAttributeMethodProcessorTests {
|
||||||
assertTrue(dataBinder.isValidateInvoked());
|
assertTrue(dataBinder.isValidateInvoked());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=BindException.class)
|
@Test(expected = BindException.class)
|
||||||
public void resovleArgumentBindException() throws Exception {
|
public void resovleArgumentBindException() throws Exception {
|
||||||
String name = "testBean";
|
String name = "testBean";
|
||||||
Object target = new TestBean();
|
Object target = new TestBean();
|
||||||
|
@ -203,9 +203,7 @@ public class ModelAttributeMethodProcessorTests {
|
||||||
verify(binderFactory).createBinder(webRequest, target, name);
|
verify(binderFactory).createBinder(webRequest, target, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SPR-9378
|
@Test // SPR-9378
|
||||||
|
|
||||||
@Test
|
|
||||||
public void resolveArgumentOrdering() throws Exception {
|
public void resolveArgumentOrdering() throws Exception {
|
||||||
String name = "testBean";
|
String name = "testBean";
|
||||||
Object testBean = new TestBean(name);
|
Object testBean = new TestBean(name);
|
||||||
|
@ -241,6 +239,7 @@ public class ModelAttributeMethodProcessorTests {
|
||||||
assertSame(testBean, mavContainer.getModel().get("testBean"));
|
assertSame(testBean, mavContainer.getModel().get("testBean"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class StubRequestDataBinder extends WebRequestDataBinder {
|
private static class StubRequestDataBinder extends WebRequestDataBinder {
|
||||||
|
|
||||||
private boolean bindInvoked;
|
private boolean bindInvoked;
|
||||||
|
@ -273,31 +272,31 @@ public class ModelAttributeMethodProcessorTests {
|
||||||
public void validate(Object... validationHints) {
|
public void validate(Object... validationHints) {
|
||||||
validateInvoked = true;
|
validateInvoked = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Target({ METHOD, FIELD, CONSTRUCTOR, PARAMETER })
|
|
||||||
|
@Target({METHOD, FIELD, CONSTRUCTOR, PARAMETER})
|
||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
public @interface Valid {
|
public @interface Valid {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SessionAttributes(types=TestBean.class)
|
@SessionAttributes(types=TestBean.class)
|
||||||
private static class ModelAttributeHandler {
|
private static class ModelAttributeHandler {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public void modelAttribute(@ModelAttribute("attrName") @Valid TestBean annotatedAttr,
|
public void modelAttribute(@ModelAttribute("attrName") @Valid TestBean annotatedAttr, Errors errors,
|
||||||
Errors errors,
|
int intArg, @ModelAttribute TestBean defaultNameAttr, TestBean notAnnotatedAttr) {
|
||||||
int intArg,
|
|
||||||
@ModelAttribute TestBean defaultNameAttr,
|
|
||||||
TestBean notAnnotatedAttr) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ModelAttribute("modelAttrName")
|
@ModelAttribute("modelAttrName")
|
||||||
private String annotatedReturnValue() {
|
private String annotatedReturnValue() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private TestBean notAnnotatedReturnValue() {
|
private TestBean notAnnotatedReturnValue() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -93,7 +93,6 @@ import static org.junit.Assert.assertTrue;
|
||||||
* specific argument or return value type.
|
* specific argument or return value type.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*
|
|
||||||
* @see HandlerMethodAnnotationDetectionTests
|
* @see HandlerMethodAnnotationDetectionTests
|
||||||
* @see ServletAnnotationControllerHandlerMethodTests
|
* @see ServletAnnotationControllerHandlerMethodTests
|
||||||
*/
|
*/
|
||||||
|
@ -143,7 +142,6 @@ public class RequestMappingHandlerAdapterIntegrationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handle() throws Exception {
|
public void handle() throws Exception {
|
||||||
|
|
||||||
Class<?>[] parameterTypes = new Class<?>[] { int.class, String.class, String.class, String.class, Map.class,
|
Class<?>[] parameterTypes = new Class<?>[] { int.class, String.class, String.class, String.class, Map.class,
|
||||||
Date.class, Map.class, String.class, String.class, TestBean.class, Errors.class, TestBean.class,
|
Date.class, Map.class, String.class, String.class, TestBean.class, Errors.class, TestBean.class,
|
||||||
Color.class, HttpServletRequest.class, HttpServletResponse.class, User.class, OtherUser.class,
|
Color.class, HttpServletRequest.class, HttpServletResponse.class, User.class, OtherUser.class,
|
||||||
|
@ -218,7 +216,6 @@ public class RequestMappingHandlerAdapterIntegrationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handleRequestBody() throws Exception {
|
public void handleRequestBody() throws Exception {
|
||||||
|
|
||||||
Class<?>[] parameterTypes = new Class<?>[] { byte[].class };
|
Class<?>[] parameterTypes = new Class<?>[] { byte[].class };
|
||||||
|
|
||||||
request.setMethod("POST");
|
request.setMethod("POST");
|
||||||
|
@ -236,7 +233,6 @@ public class RequestMappingHandlerAdapterIntegrationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handleAndValidateRequestBody() throws Exception {
|
public void handleAndValidateRequestBody() throws Exception {
|
||||||
|
|
||||||
Class<?>[] parameterTypes = new Class<?>[] { TestBean.class, Errors.class };
|
Class<?>[] parameterTypes = new Class<?>[] { TestBean.class, Errors.class };
|
||||||
|
|
||||||
request.addHeader("Content-Type", "text/plain; charset=utf-8");
|
request.addHeader("Content-Type", "text/plain; charset=utf-8");
|
||||||
|
@ -253,7 +249,6 @@ public class RequestMappingHandlerAdapterIntegrationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void handleHttpEntity() throws Exception {
|
public void handleHttpEntity() throws Exception {
|
||||||
|
|
||||||
Class<?>[] parameterTypes = new Class<?>[] { HttpEntity.class };
|
Class<?>[] parameterTypes = new Class<?>[] { HttpEntity.class };
|
||||||
|
|
||||||
request.addHeader("Content-Type", "text/plain; charset=utf-8");
|
request.addHeader("Content-Type", "text/plain; charset=utf-8");
|
||||||
|
@ -306,8 +301,9 @@ public class RequestMappingHandlerAdapterIntegrationTests {
|
||||||
return new InvocableHandlerMethod(handler, method);
|
return new InvocableHandlerMethod(handler, method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@SessionAttributes(types=TestBean.class)
|
@SessionAttributes(types = TestBean.class)
|
||||||
private static class Handler {
|
private static class Handler {
|
||||||
|
|
||||||
@InitBinder("dateParam")
|
@InitBinder("dateParam")
|
||||||
|
@ -398,7 +394,9 @@ public class RequestMappingHandlerAdapterIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class StubValidator implements Validator {
|
private static class StubValidator implements Validator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supports(Class<?> clazz) {
|
public boolean supports(Class<?> clazz) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -410,21 +408,27 @@ public class RequestMappingHandlerAdapterIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class ColorArgumentResolver implements WebArgumentResolver {
|
private static class ColorArgumentResolver implements WebArgumentResolver {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) throws Exception {
|
public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) throws Exception {
|
||||||
return new Color(0);
|
return new Color(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class User implements Principal {
|
private static class User implements Principal {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "user";
|
return "user";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class OtherUser implements Principal {
|
private static class OtherUser implements Principal {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "other user";
|
return "other user";
|
||||||
|
|
Loading…
Reference in New Issue