INT-632
This commit is contained in:
@@ -7,12 +7,22 @@
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<annotation-config />
|
||||
|
||||
<aop:aspectj-autoproxy />
|
||||
|
||||
<channel id="input"/>
|
||||
|
||||
<channel id="output">
|
||||
<queue capacity="1"/>
|
||||
</channel>
|
||||
|
||||
<beans:bean id="activatedService"
|
||||
class="org.springframework.integration.config.annotation.MessagingAnnotationPostProcessorAopIntegrationTests$AnnotatedService" />
|
||||
|
||||
<beans:bean id="handlerAspect"
|
||||
class="org.springframework.integration.config.annotation.MessagingAnnotationPostProcessorAopIntegrationTests$HandlerAspect" />
|
||||
|
||||
<beans:bean id="serviceAspect"
|
||||
class="org.springframework.integration.config.annotation.MessagingAnnotationPostProcessorAopIntegrationTests$ServiceAspect" />
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 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.
|
||||
@@ -17,16 +17,21 @@
|
||||
package org.springframework.integration.config.annotation;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.integration.annotation.MessageEndpoint;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.channel.SubscribableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
@@ -35,14 +40,21 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class MessagingAnnotationPostProcessorAopIntegrationTests {
|
||||
|
||||
@Qualifier("input")
|
||||
@Autowired
|
||||
SubscribableChannel input;
|
||||
private SubscribableChannel input;
|
||||
|
||||
@Qualifier("output")
|
||||
@Autowired
|
||||
private PollableChannel output;
|
||||
|
||||
|
||||
@Test
|
||||
public void parseConfig() throws Exception {
|
||||
@@ -51,32 +63,39 @@ public class MessagingAnnotationPostProcessorAopIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void sendMessage() throws Exception {
|
||||
input.send(MessageBuilder.withPayload("A test message").build());
|
||||
input.send(MessageBuilder.withPayload(new AtomicInteger(0)).build());
|
||||
Message<?> reply = output.receive(1000);
|
||||
assertEquals(111, ((Integer) reply.getPayload()).intValue());
|
||||
}
|
||||
|
||||
|
||||
@Aspect
|
||||
public static class HandlerAspect {
|
||||
|
||||
@Before("execution(* org.springframework.integration.message.MessageHandler+.*(..)) && args(message)")
|
||||
public void printMessage(Message<?> message) {
|
||||
System.out.println(message + " hit handler wrapping aspect");
|
||||
public void addOneHundred(Message<?> message) {
|
||||
((AtomicInteger) message.getPayload()).addAndGet(100);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Aspect
|
||||
public static class ServiceAspect {
|
||||
|
||||
@Before("execution(* printMessage(*)) && args(message)")
|
||||
public void printMessage(Message<?> message) {
|
||||
System.out.println(message + " hit service wrapping aspect");
|
||||
@Before("execution(* addOne(*)) && args(n)")
|
||||
public void addTen(AtomicInteger n) {
|
||||
n.addAndGet(10);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@MessageEndpoint
|
||||
public static class AnnotatedService {
|
||||
@ServiceActivator(inputChannel = "input")
|
||||
public void printMessage(Message<?> m) {
|
||||
System.out.println(m + " hit service");
|
||||
|
||||
@ServiceActivator(inputChannel = "input", outputChannel="output")
|
||||
public int addOne(AtomicInteger n) {
|
||||
return n.addAndGet(1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user