Update Spring Social Twitter version to 1.0.4

(Refactor) Use SearchParameters for searching Twitter

bundlor updates
This commit is contained in:
Craig Walls
2013-06-04 16:29:21 -05:00
committed by Mark Fisher
parent 8f8ce7fb6e
commit 95df8e92e1
5 changed files with 20 additions and 16 deletions

View File

@@ -50,7 +50,7 @@ subprojects { subproject ->
springDataRedisVersion = '1.0.0.RELEASE'
springGemfireVersion = '1.1.0.RELEASE'
springSecurityVersion = '3.1.0.RELEASE'
springSocialTwitterVersion = '1.0.1.RELEASE'
springSocialTwitterVersion = '1.0.4.RELEASE'
springWsVersion = '2.0.3.RELEASE'
eclipse {
@@ -768,7 +768,7 @@ project('spring-integration-twitter') {
'org.springframework.beans.*;version="[3.0.5, 4.0.0)"',
'org.springframework.context;version="[3.0.5, 4.0.0)"',
'org.springframework.core.*;version="[3.0.5, 4.0.0)"',
'org.springframework.social.*;version="[1.0.0, 1.1.0)"',
'org.springframework.social.twitter.*;version="[1.0.4, 1.1.0)"',
'org.springframework.security.crypto.*;version="[3.1.0, 3.2.0)"',
'org.springframework.scheduling.*;version="[3.0.5, 4.0.0)"',
'org.springframework.util;version="[3.0.5, 4.0.0)"',

View File

@@ -42,7 +42,7 @@ public class MentionsReceivingMessageSource extends AbstractTwitterMessageSource
@Override
protected List<Tweet> pollForTweets(long sinceId) {
return this.getTwitter().timelineOperations().getMentions(1, 20, sinceId, 0);
return this.getTwitter().timelineOperations().getMentions(20, sinceId, 0);
}
}

View File

@@ -22,6 +22,7 @@ import java.util.List;
import org.springframework.social.twitter.api.SearchResults;
import org.springframework.social.twitter.api.Tweet;
import org.springframework.social.twitter.api.Twitter;
import org.springframework.social.twitter.api.impl.SearchParameters;
import org.springframework.util.Assert;
/**
@@ -51,7 +52,8 @@ public class SearchReceivingMessageSource extends AbstractTwitterMessageSource<T
@Override
protected List<Tweet> pollForTweets(long sinceId) {
SearchResults results = this.getTwitter().searchOperations().search(query, 1, 20, sinceId, 0);
SearchParameters searchParameters = new SearchParameters(query).count(20).sinceId(sinceId);
SearchResults results = this.getTwitter().searchOperations().search(searchParameters);
return (results != null) ? results.getTweets() : Collections.<Tweet>emptyList();
}

View File

@@ -43,7 +43,7 @@ public class TimelineReceivingMessageSource extends AbstractTwitterMessageSource
@Override
protected List<Tweet> pollForTweets(long sinceId) {
return this.getTwitter().timelineOperations().getHomeTimeline(1, 20, sinceId, 0);
return this.getTwitter().timelineOperations().getHomeTimeline(20, sinceId, 0);
}
}

View File

@@ -28,15 +28,18 @@ import static junit.framework.Assert.*;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.integration.Message;
import org.springframework.integration.store.SimpleMetadataStore;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.social.twitter.api.SearchMetadata;
import org.springframework.social.twitter.api.SearchOperations;
import org.springframework.social.twitter.api.SearchResults;
import org.springframework.social.twitter.api.Tweet;
import org.springframework.social.twitter.api.Twitter;
import org.springframework.social.twitter.api.impl.SearchParameters;
import org.springframework.social.twitter.api.impl.TwitterTemplate;
@@ -78,7 +81,7 @@ public class SearchReceivingMessageSourceTests {
@Test
public void testSearchReceivingMessageSourceInit() {
final SearchReceivingMessageSource messageSource = new SearchReceivingMessageSource(new TwitterTemplate());
final SearchReceivingMessageSource messageSource = new SearchReceivingMessageSource(new TwitterTemplate("test"));
messageSource.setComponentName("twitterSearchMessageSource");
final Object metadataStore = TestUtils.getPropertyValue(messageSource, "metadataStore");
@@ -112,10 +115,10 @@ public class SearchReceivingMessageSourceTests {
public void testPollForTweetsNullResults() {
final TwitterTemplate twitterTemplate = mock(TwitterTemplate.class);
final SearchOperations so = mock(SearchOperations.class);
final SearchOperations so = mock(SearchOperations.class);
when(twitterTemplate.searchOperations()).thenReturn(so);
when(twitterTemplate.searchOperations().search(SEARCH_QUERY, 1, 20, 0, 0)).thenReturn(null);
when(twitterTemplate.searchOperations().search(SEARCH_QUERY, 20, 0, 0)).thenReturn(null);
final SearchReceivingMessageSource messageSource = new SearchReceivingMessageSource(twitterTemplate);
messageSource.setQuery(SEARCH_QUERY);
@@ -127,9 +130,8 @@ public class SearchReceivingMessageSourceTests {
final List<Tweet> tweets = messageSource.pollForTweets(0);
assertNotNull(tweets);
assertTrue(tweets.isEmpty());
assertNotNull(tweets);
assertTrue(tweets.isEmpty());
}
/**
@@ -152,12 +154,13 @@ public class SearchReceivingMessageSourceTests {
tweets.add(tweet2);
tweets.add(tweet3);
final SearchResults results = new SearchResults(tweets, 111, 111);
final SearchResults results = new SearchResults(tweets, new SearchMetadata(111, 111));
twitterTemplate = mock(TwitterTemplate.class);
when(twitterTemplate.searchOperations()).thenReturn(so);
when(twitterTemplate.searchOperations().search(SEARCH_QUERY, 1, 20, 0, 0)).thenReturn(results);
SearchParameters params = new SearchParameters(SEARCH_QUERY).count(20).sinceId(0);
when(twitterTemplate.searchOperations().search(params)).thenReturn(results);
final SearchReceivingMessageSource messageSource = new SearchReceivingMessageSource(twitterTemplate);
@@ -165,9 +168,8 @@ public class SearchReceivingMessageSourceTests {
final List<Tweet> tweetSearchResults = messageSource.pollForTweets(0);
assertNotNull(tweetSearchResults);
assertTrue(tweetSearchResults.size() == 3);
assertNotNull(tweetSearchResults);
assertEquals(3, tweetSearchResults.size());
}
}