INT-1636 added 'target-user-expression' to the Twitter DM adapter

This commit is contained in:
Oleg Zhurakousky
2010-12-10 16:00:13 -05:00
parent 69c0a8bdcf
commit 2a456d9373
6 changed files with 89 additions and 7 deletions

View File

@@ -24,7 +24,10 @@
<channel id="inputChannel"/>
<twitter:dm-outbound-channel-adapter twitter-template="twitter" channel="inputChannel" />
<twitter:dm-outbound-channel-adapter id="dmAdapter"
twitter-template="twitter"
channel="inputChannel"
target-user-expression="'z' + '_oleg'"/>
<twitter:outbound-channel-adapter twitter-template="twitter" channel="inputChannel" />

View File

@@ -16,8 +16,16 @@
package org.springframework.integration.twitter.config;
import static junit.framework.Assert.assertEquals;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.expression.Expression;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.twitter.outbound.DirectMessageSendingMessageHandler;
/**
* @author Oleg Zhurakousky
@@ -27,8 +35,12 @@ public class TestSendingMessageHandlerParserTests {
@Test
public void testSendingMessageHandlerSuccessfulBootstrap(){
new ClassPathXmlApplicationContext("TestSendingMessageHandlerParser-context.xml", this.getClass());
// the fact that no exception was thrown satisfies this test
ApplicationContext ac = new ClassPathXmlApplicationContext("TestSendingMessageHandlerParser-context.xml", this.getClass());
EventDrivenConsumer dmAdapter = ac.getBean("dmAdapter", EventDrivenConsumer.class);
DirectMessageSendingMessageHandler handler =
(DirectMessageSendingMessageHandler) TestUtils.getPropertyValue(dmAdapter, "handler");
Expression targetUserExpression = (Expression) TestUtils.getPropertyValue(handler, "targetUserExpression");
assertEquals("'z' + '_oleg'", targetUserExpression.getExpressionString());
}
}

View File

@@ -23,6 +23,7 @@ import static org.mockito.Mockito.verify;
import org.junit.Test;
import org.springframework.integration.Message;
import org.springframework.integration.config.ExpressionFactoryBean;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.twitter.core.TwitterHeaders;
import org.springframework.integration.twitter.core.TwitterOperations;
@@ -47,5 +48,17 @@ public class DirectMessageSendingMessageHandlerTests {
handler.handleMessage(message2);
verify(twitter, times(1)).sendDirectMessage(123, "hello");
}
@Test
public void validateSendDirectMessageWithTargetUserExpression() throws Exception{
Message<?> message1 = MessageBuilder.withPayload("hello").build();
DirectMessageSendingMessageHandler handler = new DirectMessageSendingMessageHandler(twitter);
ExpressionFactoryBean efb = new ExpressionFactoryBean("'z' + '_oleg'");
efb.afterPropertiesSet();
handler.setTargetUserExpression(efb.getObject());
handler.afterPropertiesSet();
handler.handleMessage(message1);
verify(twitter, times(1)).sendDirectMessage("z_oleg", "hello");
}
}