Merge branch 'master' into buildSrc-extraction

Conflicts:
	spring-integration-twitter/src/main/java/org/springframework/integration/twitter/core/Twitter4jTemplate.java
This commit is contained in:
Chris Beams
2010-11-11 10:13:14 -08:00
104 changed files with 2458 additions and 1470 deletions

View File

@@ -21,25 +21,25 @@
<channel id="inbound_mentions"/>
<twitter:inbound-mention-channel-adapter id="mentionAdapter"
<twitter:mentions-inbound-channel-adapter id="mentionAdapter"
twitter-template="twitter"
channel="inbound_mentions"
auto-startup="false">
<poller fixed-rate="5000" max-messages-per-poll="3"/>
</twitter:inbound-mention-channel-adapter>
</twitter:mentions-inbound-channel-adapter>
<twitter:inbound-dm-channel-adapter id="dmAdapter"
<twitter:dm-inbound-channel-adapter id="dmAdapter"
twitter-template="twitter"
channel="inbound_mentions"
auto-startup="false">
<poller fixed-rate="5000" max-messages-per-poll="3"/>
</twitter:inbound-dm-channel-adapter>
<twitter:inbound-update-channel-adapter id="updateAdapter"
</twitter:dm-inbound-channel-adapter>
<twitter:inbound-channel-adapter id="updateAdapter"
twitter-template="twitter"
channel="inbound_mentions"
auto-startup="false">
<poller fixed-rate="5000" max-messages-per-poll="3"/>
</twitter:inbound-update-channel-adapter>
</twitter:inbound-channel-adapter>
</beans:beans>

View File

@@ -24,9 +24,9 @@
<channel id="inputChannel"/>
<twitter:outbound-dm-channel-adapter twitter-template="twitter" channel="inputChannel" />
<twitter:dm-outbound-channel-adapter twitter-template="twitter" channel="inputChannel" />
<twitter:outbound-update-channel-adapter twitter-template="twitter" channel="inputChannel" />
<twitter:outbound-channel-adapter twitter-template="twitter" channel="inputChannel" />
</beans:beans>

View File

@@ -16,6 +16,7 @@
package org.springframework.integration.twitter.core;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -23,6 +24,8 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
@@ -30,6 +33,8 @@ import org.mockito.Mockito;
import org.springframework.integration.test.util.TestUtils;
import twitter4j.Paging;
import twitter4j.Query;
import twitter4j.QueryResult;
import twitter4j.StatusUpdate;
import twitter4j.Twitter;
import twitter4j.http.AccessToken;
@@ -89,10 +94,10 @@ public class Twitter4jTemplateTests {
@Test
public void testGetFriendsTimeline() throws Exception{
template.getFriendsTimeline();
template.getFriendsTimeline(123);
verify(twitter, times(1)).getFriendsTimeline();
verify(twitter, times(1)).getFriendsTimeline(Mockito.any(Paging.class));
template.getHomeTimeline();
template.getHomeTimeline(123);
verify(twitter, times(1)).getHomeTimeline();
verify(twitter, times(1)).getHomeTimeline(Mockito.any(Paging.class));
}
@Test
@@ -105,10 +110,31 @@ public class Twitter4jTemplateTests {
@Test
public void testUpdateStatus() throws Exception{
Tweet tweet = new Tweet();
tweet.setToUserId((long) 123);
tweet.setText("writing twitter test");
template.updateStatus(tweet);
template.updateStatus("writing twitter test");
verify(twitter, times(1)).updateStatus(Mockito.any(StatusUpdate.class));
}
@Test
public void testSearch() throws Exception{
// set up test
QueryResult result = mock(QueryResult.class);
List<twitter4j.Tweet> t4jTweets = new ArrayList<twitter4j.Tweet>();
t4jTweets.add(mock(twitter4j.Tweet.class));
t4jTweets.add(mock(twitter4j.Tweet.class));
t4jTweets.add(mock(twitter4j.Tweet.class));
when(result.getTweets()).thenReturn(t4jTweets);
when(twitter.search(Mockito.any(Query.class))).thenReturn(result);
// end setup test
SearchResults results = template.search("#s2gx");
List<Tweet> tweets = results.getTweets();
assertNotNull(tweets);
assertEquals(3, tweets.size());
assertTrue(tweets.get(0) instanceof Tweet);
assertTrue(tweets.get(1) instanceof Tweet);
assertTrue(tweets.get(2) instanceof Tweet);
}
}

View File

@@ -33,20 +33,19 @@
<beans:constructor-arg value="${twitter.oauth.accessTokenSecret}"/>
</beans:bean>
<twitter:inbound-mention-channel-adapter twitter-template="twitterTemplate" channel="inbound_mentions">
<twitter:mentions-inbound-channel-adapter twitter-template="twitterTemplate" channel="inbound_mentions">
<poller fixed-rate="5000" max-messages-per-poll="3"/>
</twitter:inbound-mention-channel-adapter>
</twitter:mentions-inbound-channel-adapter>
<service-activator input-channel="inbound_mentions" ref="twitterAnnouncer" method="mention"/>
<twitter:inbound-dm-channel-adapter twitter-template="twitterTemplate" channel="inbound_dm">
<twitter:dm-inbound-channel-adapter twitter-template="twitterTemplate" channel="inbound_dm">
<poller fixed-rate="5000" max-messages-per-poll="3"/>
</twitter:inbound-dm-channel-adapter>
</twitter:dm-inbound-channel-adapter>
<service-activator input-channel="inbound_dm" ref="twitterAnnouncer" method="dm"/>
<twitter:inbound-update-channel-adapter id="twitterInbound" twitter-template="twitterTemplate" channel="inbound_updates">
<twitter:inbound-channel-adapter id="twitterInbound" twitter-template="twitterTemplate" channel="inbound_updates">
<poller fixed-rate="5000" max-messages-per-poll="3"/>
</twitter:inbound-update-channel-adapter>
</twitter:inbound-channel-adapter>
<service-activator input-channel="inbound_updates" ref="twitterAnnouncer" method="updates"/>
<beans:bean id="twitterAnnouncer" class="org.springframework.integration.twitter.ignored.TwitterAnnouncer"/>

View File

@@ -31,7 +31,7 @@
<channel id="inputChannel"/>
<twitter:outbound-dm-channel-adapter twitter-template="twitterTemplate" channel="inputChannel"/>
<twitter:dm-outbound-channel-adapter twitter-template="twitterTemplate" channel="inputChannel"/>
</beans:beans>

View File

@@ -31,7 +31,7 @@
<channel id="out"/>
<twitter:outbound-update-channel-adapter twitter-template="twitterTemplate" channel="out"/>
<twitter:outbound-channel-adapter twitter-template="twitterTemplate" channel="out"/>
</beans:beans>

View File

@@ -0,0 +1,58 @@
/**
*
*/
package org.springframework.integration.twitter.inbound;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.MessagingException;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.twitter.core.Tweet;
import org.springframework.integration.twitter.core.Twitter4jTemplate;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
/**
* @author ozhurakousky
*
*/
public class SearchReceivingMessageSourceTests {
@Test
@Ignore
public void testSearchReceiving() throws Exception{
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.afterPropertiesSet();
bf.registerSingleton("taskScheduler", scheduler);
SearchReceivingMessageSource ms = new SearchReceivingMessageSource(new Twitter4jTemplate());
DirectChannel channel = new DirectChannel();
channel.subscribe(new MessageHandler() {
public void handleMessage(Message<?> message) throws MessagingException {
System.out.println("Message: " + ((Tweet)message.getPayload()).getCreatedAt() + " - " + ((Tweet)message.getPayload()).getText());
}
});
SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
adapter.setSource(ms);
adapter.setBeanFactory(bf);
adapter.setOutputChannel(channel);
adapter.afterPropertiesSet();
adapter.start();
ms.setBeanFactory(bf);
ms.setQuery("#springintegration");
ms.setTaskScheduler(scheduler);
ms.afterPropertiesSet();
ms.start();
System.in.read();
}
}

View File

@@ -131,7 +131,7 @@ public class TimelineUpdateReceivingMessageSourceTests {
Tweet message = (Tweet) msg.poll();
assertEquals(2000, message.getId());
Thread.sleep(1000);
verify(twitter, times(1)).getFriendsTimeline(2000);
verify(twitter, times(1)).getHomeTimeline(2000);
// based on the Mock, the Queue shoud now have 2 mopre messages third and fourth
assertTrue(((Queue)TestUtils.getPropertyValue(source, "tweets")).size() == 2);
source.stop();
@@ -209,12 +209,12 @@ public class TimelineUpdateReceivingMessageSourceTests {
SampleResoponceList testMessages = new SampleResoponceList();
testMessages.add(firstMessage);
testMessages.add(secondMessage);
when(tw.getFriendsTimeline()).thenReturn(testMessages);
when(tw.getHomeTimeline()).thenReturn(testMessages);
testMessages = new SampleResoponceList();
testMessages.add(thirdMessage);
testMessages.add(fourthMessage);
when(tw.getFriendsTimeline(Mockito.any(Paging.class))).thenReturn(testMessages);
when(tw.getHomeTimeline(Mockito.any(Paging.class))).thenReturn(testMessages);
}
@SuppressWarnings({ "rawtypes", "serial" })

View File

@@ -62,7 +62,7 @@ public class TimelineUpdateSendingMessageHandlerTests {
Tweet tweet = new Tweet();
tweet.setText("writing twitter tests");
handler.handleMessage(new GenericMessage(tweet));
verify(twitterOperations, times(1)).updateStatus(Mockito.any(Tweet.class));
verify(twitterOperations, times(1)).updateStatus(Mockito.any(String.class));
verify(twitter, times(1)).updateStatus(Mockito.any(StatusUpdate.class));
}
@Test
@@ -75,7 +75,7 @@ public class TimelineUpdateSendingMessageHandlerTests {
.setHeader(TwitterHeaders.DISPLAY_COORDINATES, true)
.build();
handler.handleMessage(message);
verify(twitterOperations, times(1)).updateStatus(Mockito.any(Tweet.class));
verify(twitterOperations, times(1)).updateStatus(Mockito.any(String.class));
verify(twitter, times(1)).updateStatus(Mockito.any(StatusUpdate.class));
}
}