INT-1553 first round of refactoring to introduce dependency on Tweet from Spring Social
This commit is contained in:
@@ -110,8 +110,10 @@ public class Twitter4jTemplateTests {
|
||||
|
||||
@Test
|
||||
public void testUpdateStatus() throws Exception{
|
||||
StatusUpdate status = new StatusUpdate("writing twitter test");
|
||||
template.updateStatus(status);
|
||||
Tweet tweet = new Tweet();
|
||||
tweet.setToUserId((long) 123);
|
||||
tweet.setText("writing twitter test");
|
||||
template.updateStatus(tweet);
|
||||
verify(twitter, times(1)).updateStatus(Mockito.any(StatusUpdate.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,27 +26,28 @@
|
||||
<channel id="inbound_mentions"/>
|
||||
<channel id="inbound_updates"/>
|
||||
|
||||
<twitter:twitter-connection id="tc"
|
||||
access-token="${twitter.oauth.accessToken}"
|
||||
access-token-secret="${twitter.oauth.accessTokenSecret}"
|
||||
consumer-key="${twitter.oauth.consumerKey}"
|
||||
consumer-secret="${twitter.oauth.consumerSecret}"/>
|
||||
<beans:bean id="twitterTemplate" class="org.springframework.integration.twitter.core.Twitter4jTemplate">
|
||||
<beans:constructor-arg value="${twitter.oauth.consumerKey}"/>
|
||||
<beans:constructor-arg value="${twitter.oauth.consumerSecret}"/>
|
||||
<beans:constructor-arg value="${twitter.oauth.accessToken}"/>
|
||||
<beans:constructor-arg value="${twitter.oauth.accessTokenSecret}"/>
|
||||
</beans:bean>
|
||||
|
||||
|
||||
<twitter:inbound-mention-channel-adapter twitter-connection="tc" channel="inbound_mentions">
|
||||
<poller fixed-rate="5000" max-messages-per-poll="3"/>
|
||||
</twitter:inbound-mention-channel-adapter>
|
||||
<service-activator input-channel="inbound_mentions" ref="twitterAnnouncer" method="mention"/>
|
||||
<!-- <twitter:inbound-mention-channel-adapter twitter-template="twitterTemplate" channel="inbound_mentions">-->
|
||||
<!-- <poller fixed-rate="5000" max-messages-per-poll="3"/>-->
|
||||
<!-- </twitter:inbound-mention-channel-adapter>-->
|
||||
<!-- <service-activator input-channel="inbound_mentions" ref="twitterAnnouncer" method="mention"/>-->
|
||||
|
||||
<twitter:inbound-dm-channel-adapter twitter-connection="tc" channel="inbound_dm">
|
||||
<twitter:inbound-dm-channel-adapter twitter-template="twitterTemplate" channel="inbound_dm">
|
||||
<poller fixed-rate="5000" max-messages-per-poll="3"/>
|
||||
</twitter:inbound-dm-channel-adapter>
|
||||
<service-activator input-channel="inbound_dm" ref="twitterAnnouncer" method="dm"/>
|
||||
|
||||
<twitter:inbound-update-channel-adapter id="twitterInbound" twitter-connection="tc" channel="inbound_updates">
|
||||
<poller fixed-rate="5000" max-messages-per-poll="3"/>
|
||||
</twitter:inbound-update-channel-adapter>
|
||||
<service-activator input-channel="inbound_updates" ref="twitterAnnouncer" method="updates"/>
|
||||
<!-- <twitter:inbound-update-channel-adapter id="twitterInbound" twitter-template="twitterTemplate" channel="inbound_updates">-->
|
||||
<!-- <poller fixed-rate="5000" max-messages-per-poll="3"/>-->
|
||||
<!-- </twitter:inbound-update-channel-adapter>-->
|
||||
<!-- <service-activator input-channel="inbound_updates" ref="twitterAnnouncer" method="updates"/>-->
|
||||
|
||||
<beans:bean id="twitterAnnouncer" class="org.springframework.integration.twitter.ignored.TwitterAnnouncer"/>
|
||||
</beans:beans>
|
||||
|
||||
@@ -15,24 +15,22 @@
|
||||
*/
|
||||
package org.springframework.integration.twitter.ignored;
|
||||
|
||||
import org.springframework.integration.twitter.core.Tweet;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import twitter4j.DirectMessage;
|
||||
import twitter4j.Status;
|
||||
|
||||
|
||||
@Component
|
||||
public class TwitterAnnouncer {
|
||||
public void dm(DirectMessage directMessage) {
|
||||
public void dm(Tweet directMessage) {
|
||||
System.out.println("A direct message has been received from " +
|
||||
directMessage.getSender().getScreenName() + " with text " + directMessage.getText());
|
||||
directMessage.getFromUser() + " with text " + directMessage.getText());
|
||||
}
|
||||
|
||||
public void mention(Status s) {
|
||||
public void mention(Tweet s) {
|
||||
System.out.println("A tweet mentioning (or replying) to " + "you was received having text " + s.getText() + " from " + s.getSource());
|
||||
}
|
||||
|
||||
public void updates(Status t) {
|
||||
public void updates(Tweet t) {
|
||||
System.out.println("Received timeline update: " + t.getText() + " from " + t.getSource());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.twitter.core.Tweet;
|
||||
import org.springframework.integration.twitter.core.TwitterOperations;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -43,9 +44,9 @@ import twitter4j.ResponseList;
|
||||
*/
|
||||
public class DirectMessageReceivingMessageSourceTests {
|
||||
|
||||
private DirectMessage firstMessage;
|
||||
private Tweet firstMessage;
|
||||
|
||||
private DirectMessage secondMessage;
|
||||
private Tweet secondMessage;
|
||||
|
||||
private TwitterOperations twitter;
|
||||
|
||||
@@ -53,12 +54,12 @@ public class DirectMessageReceivingMessageSourceTests {
|
||||
@Before
|
||||
public void prepare() throws Exception{
|
||||
twitter = mock(TwitterOperations.class);
|
||||
firstMessage = mock(DirectMessage.class);
|
||||
firstMessage = mock(Tweet.class);
|
||||
when(firstMessage.getCreatedAt()).thenReturn(new Date(5555555555L));
|
||||
when(firstMessage.getId()).thenReturn(200);
|
||||
secondMessage = mock(DirectMessage.class);
|
||||
when(firstMessage.getId()).thenReturn((long) 200);
|
||||
secondMessage = mock(Tweet.class);
|
||||
when(secondMessage.getCreatedAt()).thenReturn(new Date(2222222222L));
|
||||
when(secondMessage.getId()).thenReturn(2000);
|
||||
when(secondMessage.getId()).thenReturn((long) 2000);
|
||||
|
||||
|
||||
when(twitter.getProfileId()).thenReturn("kermit");
|
||||
@@ -95,7 +96,7 @@ public class DirectMessageReceivingMessageSourceTests {
|
||||
Queue msg = (Queue) TestUtils.getPropertyValue(source, "tweets");
|
||||
assertTrue(!CollectionUtils.isEmpty(msg));
|
||||
assertEquals(1, msg.size()); // because the other message has a older timestamp and is assumed to be read by
|
||||
DirectMessage message = (DirectMessage) msg.poll();
|
||||
Tweet message = (Tweet) msg.poll();
|
||||
assertEquals(secondMessage, message);
|
||||
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.mockito.Mockito;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.twitter.core.Tweet;
|
||||
import org.springframework.integration.twitter.core.Twitter4jTemplate;
|
||||
import org.springframework.integration.twitter.core.TwitterHeaders;
|
||||
import org.springframework.integration.twitter.core.TwitterOperations;
|
||||
@@ -58,8 +59,10 @@ public class TimelineUpdateSendingMessageHandlerTests {
|
||||
@Test
|
||||
public void testSendingStatusUpdate() throws Exception{
|
||||
TimelineUpdateSendingMessageHandler handler = new TimelineUpdateSendingMessageHandler(twitterOperations);
|
||||
handler.handleMessage(new GenericMessage("writing twitter tests"));
|
||||
verify(twitterOperations, times(1)).updateStatus(Mockito.any(StatusUpdate.class));
|
||||
Tweet tweet = new Tweet();
|
||||
tweet.setText("writing twitter tests");
|
||||
handler.handleMessage(new GenericMessage(tweet));
|
||||
verify(twitterOperations, times(1)).updateStatus(Mockito.any(Tweet.class));
|
||||
verify(twitter, times(1)).updateStatus(Mockito.any(StatusUpdate.class));
|
||||
}
|
||||
@Test
|
||||
@@ -72,7 +75,7 @@ public class TimelineUpdateSendingMessageHandlerTests {
|
||||
.setHeader(TwitterHeaders.DISPLAY_COORDINATES, true)
|
||||
.build();
|
||||
handler.handleMessage(message);
|
||||
verify(twitterOperations, times(1)).updateStatus(Mockito.any(StatusUpdate.class));
|
||||
verify(twitterOperations, times(1)).updateStatus(Mockito.any(Tweet.class));
|
||||
verify(twitter, times(1)).updateStatus(Mockito.any(StatusUpdate.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# oauth setup for prosibook twitter account
|
||||
twitter.oauth.consumerKey=
|
||||
twitter.oauth.consumerSecret=
|
||||
twitter.oauth.pin=
|
||||
twitter.oauth.accessToken=
|
||||
twitter.oauth.accessTokenSecret=
|
||||
twitter.oauth.consumerKey=OU4CbkHKIWl1SI0VwiOgAQ
|
||||
twitter.oauth.consumerSecret=p6pPukUG6d0ebSXuLSI9iaq2MIpzxJoLZyj6ilRmO3o
|
||||
twitter.oauth.accessToken=61091649-vWVUNginOL069jjpm2lHEuxGXjW163kK3CPNZCdcc
|
||||
twitter.oauth.accessTokenSecret=dufKyVlcngRitGDFfqiTlJC5leh6lsxPaq8FbeBc
|
||||
Reference in New Issue
Block a user