Polishing

This commit is contained in:
Juergen Hoeller 2015-11-09 15:03:14 +01:00
parent da9c80c604
commit 760bc719f2
17 changed files with 199 additions and 153 deletions

View File

@ -302,7 +302,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe
Class<?> targetBeanClass = targetBean.getClass();
if (!methodDeclaringClass.isAssignableFrom(targetBeanClass)) {
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 " +
"(e.g. due to @Transactional), please use class-based proxying.";
throw new IllegalStateException(getInvocationErrorMessage(targetBean, msg, args));

View File

@ -391,12 +391,10 @@ public class AnnotatedElementUtils {
* the result back into an annotation of the specified {@code annotationType}.
* <p>{@link AliasFor @AliasFor} semantics are fully supported, both
* within a single annotation and within the annotation hierarchy.
* <p>This method delegates to {@link #findMergedAnnotation(AnnotatedElement, String)}.
* @param element the annotated element
* @param annotationType the annotation type to find
* @return the merged, synthesized {@code Annotation}, or {@code null} if not found
* @since 4.2
* @see #findMergedAnnotation(AnnotatedElement, String)
* @see #findMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean)
* @see #getMergedAnnotationAttributes(AnnotatedElement, Class)
*/

View File

@ -52,6 +52,7 @@ public abstract class AbstractJmsAnnotationDrivenTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Test
public abstract void sampleConfiguration();
@ -79,6 +80,7 @@ public abstract class AbstractJmsAnnotationDrivenTests {
@Test
public abstract void jmsListeners();
/**
* Test for {@link SampleBean} discovery. If a factory with the default name
* is set, an endpoint will use it automatically
@ -92,18 +94,6 @@ public abstract class AbstractJmsAnnotationDrivenTests {
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
* all endpoints provide a default registry. This shows that the default factory
@ -127,29 +117,6 @@ public abstract class AbstractJmsAnnotationDrivenTests {
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
* with "myCustomEndpointId". The custom endpoint does not provide
@ -179,14 +146,6 @@ public abstract class AbstractJmsAnnotationDrivenTests {
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
* factory to use as a default is registered with an explicit
@ -208,13 +167,6 @@ public abstract class AbstractJmsAnnotationDrivenTests {
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
* 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));
}
@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
* {@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());
}
@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
static class JmsListenerRepeatableBean {
@ -271,9 +280,9 @@ public abstract class AbstractJmsAnnotationDrivenTests {
@JmsListener(id = "second", destination = "anotherQueue", concurrency = "2-10")
public void repeatableHandle(String msg) {
}
}
@Component
static class JmsListenersBean {
@ -283,9 +292,9 @@ public abstract class AbstractJmsAnnotationDrivenTests {
})
public void repeatableHandle(String msg) {
}
}
static class TestValidator implements Validator {
@Override
@ -301,4 +310,5 @@ public abstract class AbstractJmsAnnotationDrivenTests {
}
}
}
}

View File

@ -30,7 +30,6 @@ import org.springframework.jms.listener.adapter.ListenerExecutionFailedException
import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException;
/**
*
* @author Stephane Nicoll
*/
public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenTests {
@ -75,6 +74,7 @@ public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenT
}
@Override
@Test
public void defaultContainerFactory() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"annotation-driven-default-container-factory.xml", getClass());
@ -82,6 +82,7 @@ public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenT
}
@Override
@Test
public void jmsHandlerMethodFactoryConfiguration() throws JMSException {
ApplicationContext context = new ClassPathXmlApplicationContext(
"annotation-driven-custom-handler-method-factory.xml", getClass());
@ -92,6 +93,7 @@ public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenT
}
@Override
@Test
public void jmsListenerIsRepeatable() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"annotation-driven-jms-listener-repeatable.xml", getClass());
@ -99,12 +101,14 @@ public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenT
}
@Override
@Test
public void jmsListeners() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"annotation-driven-jms-listeners.xml", getClass());
testJmsListenerRepeatable(context);
}
static class CustomJmsListenerConfigurer implements JmsListenerConfigurer {
private MessageListener messageListener;
@ -121,6 +125,6 @@ public class AnnotationDrivenNamespaceTests extends AbstractJmsAnnotationDrivenT
public void setMessageListener(MessageListener messageListener) {
this.messageListener = messageListener;
}
}
}

View File

@ -54,6 +54,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Override
@Test
public void sampleConfiguration() {
@ -113,6 +114,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
}
@Override
@Test
public void jmsListenerIsRepeatable() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
EnableJmsDefaultContainerFactoryConfig.class, JmsListenerRepeatableBean.class);
@ -120,6 +122,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
}
@Override
@Test
public void jmsListeners() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
EnableJmsDefaultContainerFactoryConfig.class, JmsListenersBean.class);
@ -150,6 +153,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
assertTrue("Should have been stopped " + container, container.isStopped());
}
@EnableJms
@Configuration
static class EnableJmsSampleConfig {
@ -165,6 +169,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
}
}
@EnableJms
@Configuration
static class EnableJmsFullConfig {
@ -175,6 +180,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
}
}
@EnableJms
@Configuration
@PropertySource("classpath:/org/springframework/jms/annotation/jms-listener.properties")
@ -191,6 +197,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
}
}
@Configuration
@EnableJms
static class EnableJmsCustomConfig implements JmsListenerConfigurer {
@ -228,6 +235,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
}
}
@Configuration
@EnableJms
static class EnableJmsCustomContainerFactoryConfig implements JmsListenerConfigurer {
@ -243,6 +251,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
}
}
@Configuration
@EnableJms
static class EnableJmsDefaultContainerFactoryConfig {
@ -253,6 +262,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
}
}
@Configuration
@EnableJms
static class EnableJmsHandlerMethodFactoryConfig implements JmsListenerConfigurer {
@ -275,6 +285,7 @@ public class EnableJmsTests extends AbstractJmsAnnotationDrivenTests {
}
}
@Component
@Lazy
static class LazyBean {

View File

@ -49,9 +49,6 @@ import static org.mockito.Mockito.*;
*/
public class JmsListenerContainerFactoryTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
private final ConnectionFactory connectionFactory = new StubConnectionFactory();
private final DestinationResolver destinationResolver = new DynamicDestinationResolver();
@ -61,6 +58,10 @@ public class JmsListenerContainerFactoryTests {
private final TransactionManager transactionManager = mock(TransactionManager.class);
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Test
public void createSimpleContainer() {
SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory();
@ -148,6 +149,7 @@ public class JmsListenerContainerFactoryTests {
assertSame(backOff, new DirectFieldAccessor(container).getPropertyValue("backOff"));
}
private void setDefaultJmsConfig(AbstractJmsListenerContainerFactory<?> factory) {
factory.setConnectionFactory(connectionFactory);
factory.setDestinationResolver(destinationResolver);

View File

@ -30,9 +30,6 @@ import static org.junit.Assert.*;
*/
public class JmsListenerEndpointRegistrarTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
private final JmsListenerEndpointRegistrar registrar = new JmsListenerEndpointRegistrar();
private final JmsListenerEndpointRegistry registry = new JmsListenerEndpointRegistry();
@ -40,12 +37,17 @@ public class JmsListenerEndpointRegistrarTests {
private final JmsListenerContainerTestFactory containerFactory = new JmsListenerContainerTestFactory();
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Before
public void setup() {
registrar.setEndpointRegistry(registry);
registrar.setBeanFactory(new StaticListableBeanFactory());
}
@Test
public void registerNullEndpoint() {
thrown.expect(IllegalArgumentException.class);

View File

@ -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");
* 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;
/**
*
* @author Stephane Nicoll
*/
public class JmsListenerEndpointRegistryTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
private final JmsListenerEndpointRegistry registry = new JmsListenerEndpointRegistry();
private final JmsListenerContainerTestFactory containerFactory = new JmsListenerContainerTestFactory();
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Test
public void createWithNullEndpoint() {
thrown.expect(IllegalArgumentException.class);
@ -59,6 +60,7 @@ public class JmsListenerEndpointRegistryTests {
registry.registerListenerContainer(createEndpoint("test", "queue"), containerFactory);
}
private SimpleJmsListenerEndpoint createEndpoint(String id, String destinationName) {
SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
endpoint.setId(id);

View File

@ -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");
* you may not use this file except in compliance with the License.
@ -41,6 +41,7 @@ public class JmsListenerEndpointTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Test
public void setupJmsMessageContainerFullConfig() {
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
@ -112,5 +113,4 @@ public class JmsListenerEndpointTests {
endpoint.setupListenerContainer(container);
}
}

View File

@ -71,12 +71,6 @@ import static org.mockito.BDDMockito.*;
*/
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 DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
@ -84,11 +78,19 @@ public class MethodJmsListenerEndpointTests {
private final JmsEndpointSampleBean sample = new JmsEndpointSampleBean();
@Rule
public final TestName name = new TestName();
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Before
public void setup() {
initializeFactory(factory);
}
@Test
public void createMessageListenerNoFactory() {
MethodJmsListenerEndpoint endpoint = new MethodJmsListenerEndpoint();
@ -401,8 +403,10 @@ public class MethodJmsListenerEndpointTests {
listener.onMessage(createSimpleJmsTextMessage("test"), session); // Message<String> as Message<Integer>
}
private MessagingMessageListenerAdapter createInstance(
DefaultMessageHandlerMethodFactory factory, Method method, MessageListenerContainer container) {
MethodJmsListenerEndpoint endpoint = new MethodJmsListenerEndpoint();
endpoint.setBean(sample);
endpoint.setMethod(method);
@ -410,8 +414,7 @@ public class MethodJmsListenerEndpointTests {
return endpoint.createMessageListener(container);
}
private MessagingMessageListenerAdapter createInstance(
DefaultMessageHandlerMethodFactory factory, Method method) {
private MessagingMessageListenerAdapter createInstance(DefaultMessageHandlerMethodFactory factory, Method method) {
return createInstance(factory, method, new SimpleMessageListenerContainer());
}
@ -575,8 +578,8 @@ public class MethodJmsListenerEndpointTests {
@SuppressWarnings("serial")
static class MyBean implements Serializable {
private String name;
private String name;
}
}

View File

@ -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");
* 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.*;
/**
*
* @author Stephane Nicoll
*/
public class SimpleJmsListenerEndpointTests {
private final SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
@Test
public void createListener() {
SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
@ -40,4 +40,5 @@ public class SimpleJmsListenerEndpointTests {
endpoint.setMessageListener(messageListener);
assertSame(messageListener, endpoint.createMessageListener(container));
}
}

View File

@ -232,7 +232,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
Class<?> targetBeanClass = targetBean.getClass();
if (!methodDeclaringClass.isAssignableFrom(targetBeanClass)) {
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 " +
"(e.g. due to @Transactional), please use class-based proxying.";
throw new IllegalStateException(getInvocationErrorMessage(msg, args));
@ -242,7 +242,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
private String getInvocationErrorMessage(String message, Object[] resolvedArgs) {
StringBuilder sb = new StringBuilder(getDetailedErrorMessage(message));
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("] ");
if (resolvedArgs[i] == null) {
sb.append("[null] \n");

View File

@ -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");
* 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.springframework.context.support.StaticApplicationContext;
import org.springframework.core.MethodIntrospector;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.DestinationPatternsMessageCondition;
import org.springframework.messaging.handler.HandlerMethod;
import org.springframework.messaging.handler.HandlerMethodSelector;
import org.springframework.messaging.handler.annotation.support.MessageMethodArgumentResolver;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.util.AntPathMatcher;
@ -264,6 +264,7 @@ public class MethodMessageHandlerTests {
}
}
private static class TestExceptionHandlerMethodResolver extends AbstractExceptionHandlerMethodResolver {
public TestExceptionHandlerMethodResolver(Class<?> handlerType) {
@ -272,7 +273,7 @@ public class MethodMessageHandlerTests {
private static Map<Class<? extends Throwable>, Method> initExceptionMappings(Class<?> handlerType) {
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)) {
result.put(exception, method);
}
@ -281,13 +282,11 @@ public class MethodMessageHandlerTests {
}
public final static MethodFilter EXCEPTION_HANDLER_METHOD_FILTER = new MethodFilter() {
@Override
public boolean matches(Method method) {
return method.getName().contains("Exception");
}
};
}
}

View File

@ -52,8 +52,7 @@ import static org.junit.Assert.*;
import static org.springframework.transaction.event.TransactionPhase.*;
/**
* Integration tests for {@link TransactionalEventListener @TransactionalEventListener}
* support
* Integration tests for {@link TransactionalEventListener} support
*
* @author Stephane Nicoll
* @author Sam Brannen
@ -61,15 +60,16 @@ import static org.springframework.transaction.event.TransactionPhase.*;
*/
public class TransactionalEventListenerTests {
@Rule
public final ExpectedException thrown = ExpectedException.none();
private ConfigurableApplicationContext context;
private EventCollector eventCollector;
private TransactionTemplate transactionTemplate = new TransactionTemplate(new CallCountingTransactionManager());
@Rule
public final ExpectedException thrown = ExpectedException.none();
@After
public void closeContext() {
if (this.context != null) {
@ -77,6 +77,7 @@ public class TransactionalEventListenerTests {
}
}
@Test
public void immediately() {
load(ImmediateTestListener.class);
@ -305,30 +306,6 @@ public class TransactionalEventListenerTests {
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() {
return eventCollector;
@ -350,6 +327,33 @@ public class TransactionalEventListenerTests {
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 {
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};
private final MultiValueMap<String, Object> events = new LinkedMultiValueMap<>();
public void addEvent(String phase, Object event) {
@ -402,9 +405,9 @@ public class TransactionalEventListenerTests {
assertEquals("Wrong number of total events (" + this.events.size() + ") " +
"registered phase(s)", number, size);
}
}
static abstract class BaseTransactionalTestListener {
static final String FAIL_MSG = "FAIL";
@ -418,9 +421,9 @@ public class TransactionalEventListenerTests {
throw new IllegalStateException("Test exception on phase '" + phase + "'");
}
}
}
@Component
static class ImmediateTestListener extends BaseTransactionalTestListener {
@ -430,6 +433,7 @@ public class TransactionalEventListenerTests {
}
}
@Component
static class AfterCompletionTestListener extends BaseTransactionalTestListener {
@ -439,6 +443,7 @@ public class TransactionalEventListenerTests {
}
}
@Component
static class AfterCompletionExplicitTestListener extends BaseTransactionalTestListener {
@ -453,6 +458,7 @@ public class TransactionalEventListenerTests {
}
}
@Transactional
@Component
static interface TransactionalComponentTestListenerInterface {
@ -462,6 +468,7 @@ public class TransactionalEventListenerTests {
void handleAfterCommit(String data);
}
static class TransactionalComponentTestListener extends BaseTransactionalTestListener implements
TransactionalComponentTestListenerInterface {
@ -471,6 +478,7 @@ public class TransactionalEventListenerTests {
}
}
@Component
static class BeforeCommitTestListener extends BaseTransactionalTestListener {
@ -479,9 +487,9 @@ public class TransactionalEventListenerTests {
public void handleBeforeCommit(String data) {
handleEvent(EventCollector.BEFORE_COMMIT, data);
}
}
@Component
static class FallbackExecutionTestListener extends BaseTransactionalTestListener {
@ -506,12 +514,14 @@ public class TransactionalEventListenerTests {
}
}
@TransactionalEventListener(phase = AFTER_COMMIT, condition = "!'SKIP'.equals(#p0)")
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface AfterCommitEventListener {
}
@Component
static class AfterCommitMetaAnnotationTestListener extends BaseTransactionalTestListener {
@ -519,10 +529,11 @@ public class TransactionalEventListenerTests {
public void handleAfterCommit(String data) {
handleEvent(EventCollector.AFTER_COMMIT, data);
}
}
static class EventTransactionSynchronization extends TransactionSynchronizationAdapter {
private final int order;
EventTransactionSynchronization(int order) {

View File

@ -256,7 +256,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
Class<?> targetBeanClass = targetBean.getClass();
if (!methodDeclaringClass.isAssignableFrom(targetBeanClass)) {
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 " +
"(e.g. due to @Transactional), please use class-based proxying.";
throw new IllegalStateException(getInvocationErrorMessage(msg, args));
@ -266,7 +266,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
private String getInvocationErrorMessage(String message, Object[] resolvedArgs) {
StringBuilder sb = new StringBuilder(getDetailedErrorMessage(message));
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("] ");
if (resolvedArgs[i] == null) {
sb.append("[null] \n");

View File

@ -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");
* you may not use this file except in compliance with the License.
@ -172,7 +172,7 @@ public class ModelAttributeMethodProcessorTests {
}
@Test
public void resovleArgumentValidation() throws Exception {
public void resolveArgumentValidation() throws Exception {
String name = "attrName";
Object target = new TestBean();
mavContainer.addAttribute(name, target);
@ -187,7 +187,7 @@ public class ModelAttributeMethodProcessorTests {
assertTrue(dataBinder.isValidateInvoked());
}
@Test(expected=BindException.class)
@Test(expected = BindException.class)
public void resovleArgumentBindException() throws Exception {
String name = "testBean";
Object target = new TestBean();
@ -203,9 +203,7 @@ public class ModelAttributeMethodProcessorTests {
verify(binderFactory).createBinder(webRequest, target, name);
}
// SPR-9378
@Test
@Test // SPR-9378
public void resolveArgumentOrdering() throws Exception {
String name = "testBean";
Object testBean = new TestBean(name);
@ -241,6 +239,7 @@ public class ModelAttributeMethodProcessorTests {
assertSame(testBean, mavContainer.getModel().get("testBean"));
}
private static class StubRequestDataBinder extends WebRequestDataBinder {
private boolean bindInvoked;
@ -273,31 +272,31 @@ public class ModelAttributeMethodProcessorTests {
public void validate(Object... validationHints) {
validateInvoked = true;
}
}
@Target({ METHOD, FIELD, CONSTRUCTOR, PARAMETER })
@Target({METHOD, FIELD, CONSTRUCTOR, PARAMETER})
@Retention(RUNTIME)
public @interface Valid {
}
@SessionAttributes(types=TestBean.class)
private static class ModelAttributeHandler {
@SuppressWarnings("unused")
public void modelAttribute(@ModelAttribute("attrName") @Valid TestBean annotatedAttr,
Errors errors,
int intArg,
@ModelAttribute TestBean defaultNameAttr,
TestBean notAnnotatedAttr) {
public void modelAttribute(@ModelAttribute("attrName") @Valid TestBean annotatedAttr, Errors errors,
int intArg, @ModelAttribute TestBean defaultNameAttr, TestBean notAnnotatedAttr) {
}
}
@ModelAttribute("modelAttrName")
private String annotatedReturnValue() {
return null;
}
@SuppressWarnings("unused")
private TestBean notAnnotatedReturnValue() {
return null;

View File

@ -93,7 +93,6 @@ import static org.junit.Assert.assertTrue;
* specific argument or return value type.
*
* @author Rossen Stoyanchev
*
* @see HandlerMethodAnnotationDetectionTests
* @see ServletAnnotationControllerHandlerMethodTests
*/
@ -143,7 +142,6 @@ public class RequestMappingHandlerAdapterIntegrationTests {
@Test
public void handle() throws Exception {
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,
Color.class, HttpServletRequest.class, HttpServletResponse.class, User.class, OtherUser.class,
@ -218,7 +216,6 @@ public class RequestMappingHandlerAdapterIntegrationTests {
@Test
public void handleRequestBody() throws Exception {
Class<?>[] parameterTypes = new Class<?>[] { byte[].class };
request.setMethod("POST");
@ -236,7 +233,6 @@ public class RequestMappingHandlerAdapterIntegrationTests {
@Test
public void handleAndValidateRequestBody() throws Exception {
Class<?>[] parameterTypes = new Class<?>[] { TestBean.class, Errors.class };
request.addHeader("Content-Type", "text/plain; charset=utf-8");
@ -253,7 +249,6 @@ public class RequestMappingHandlerAdapterIntegrationTests {
@Test
public void handleHttpEntity() throws Exception {
Class<?>[] parameterTypes = new Class<?>[] { HttpEntity.class };
request.addHeader("Content-Type", "text/plain; charset=utf-8");
@ -306,8 +301,9 @@ public class RequestMappingHandlerAdapterIntegrationTests {
return new InvocableHandlerMethod(handler, method);
}
@SuppressWarnings("unused")
@SessionAttributes(types=TestBean.class)
@SessionAttributes(types = TestBean.class)
private static class Handler {
@InitBinder("dateParam")
@ -398,7 +394,9 @@ public class RequestMappingHandlerAdapterIntegrationTests {
}
}
private static class StubValidator implements Validator {
@Override
public boolean supports(Class<?> clazz) {
return true;
@ -410,25 +408,31 @@ public class RequestMappingHandlerAdapterIntegrationTests {
}
}
private static class ColorArgumentResolver implements WebArgumentResolver {
@Override
public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) throws Exception {
return new Color(0);
}
}
private static class User implements Principal {
@Override
public String getName() {
return "user";
}
}
private static class OtherUser implements Principal {
@Override
public String getName() {
return "other user";
}
}
}
}