Search in sources :

Example 1 with SearchMetadata

use of org.springframework.social.twitter.api.SearchMetadata in project spring-integration by spring-projects.

the class TwitterSearchOutboundGatewayTests method testStringQueryCustomExpression.

@Test
public void testStringQueryCustomExpression() {
    this.gateway.setSearchArgsExpression(new SpelExpressionParser().parseExpression("{'bar', 1, 2, 3}"));
    Tweet tweet = mock(Tweet.class);
    SearchMetadata searchMetadata = mock(SearchMetadata.class);
    final SearchResults searchResults = new SearchResults(Collections.singletonList(tweet), searchMetadata);
    doAnswer(invocation -> {
        SearchParameters searchParameters = invocation.getArgument(0);
        assertEquals("bar", searchParameters.getQuery());
        assertEquals(Integer.valueOf(1), searchParameters.getCount());
        assertEquals(Long.valueOf(2), searchParameters.getSinceId());
        assertEquals(Long.valueOf(3), searchParameters.getMaxId());
        return searchResults;
    }).when(this.searchOps).search(any(SearchParameters.class));
    this.gateway.handleMessage(new GenericMessage<String>("foo"));
    Message<?> reply = this.outputChannel.receive(0);
    assertNotNull(reply);
    @SuppressWarnings("unchecked") List<Tweet> tweets = (List<Tweet>) reply.getPayload();
    assertEquals(1, tweets.size());
    assertSame(tweet, tweets.get(0));
    assertSame(searchMetadata, reply.getHeaders().get(TwitterHeaders.SEARCH_METADATA));
}
Also used : SearchParameters(org.springframework.social.twitter.api.SearchParameters) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Tweet(org.springframework.social.twitter.api.Tweet) ArrayList(java.util.ArrayList) List(java.util.List) SearchMetadata(org.springframework.social.twitter.api.SearchMetadata) SearchResults(org.springframework.social.twitter.api.SearchResults) Test(org.junit.Test)

Example 2 with SearchMetadata

use of org.springframework.social.twitter.api.SearchMetadata in project spring-integration by spring-projects.

the class SearchReceivingMessageSourceTests method testPollForTweetsThreeResults.

/**
 * Verify that a polling operation returns in fact 3 results.
 */
@Test
public void testPollForTweetsThreeResults() {
    final TwitterTemplate twitterTemplate;
    final SearchOperations so = mock(SearchOperations.class);
    final List<Tweet> tweets = new ArrayList<Tweet>();
    tweets.add(mock(Tweet.class));
    tweets.add(mock(Tweet.class));
    tweets.add(mock(Tweet.class));
    final SearchResults results = new SearchResults(tweets, new SearchMetadata(111, 111));
    twitterTemplate = mock(TwitterTemplate.class);
    when(twitterTemplate.searchOperations()).thenReturn(so);
    SearchParameters params = new SearchParameters(SEARCH_QUERY).count(20).sinceId(0);
    when(twitterTemplate.searchOperations().search(params)).thenReturn(results);
    final SearchReceivingMessageSource messageSource = new SearchReceivingMessageSource(twitterTemplate, "foo");
    messageSource.setQuery(SEARCH_QUERY);
    final List<Tweet> tweetSearchResults = messageSource.pollForTweets(0);
    assertNotNull(tweetSearchResults);
    assertEquals(3, tweetSearchResults.size());
}
Also used : TwitterTemplate(org.springframework.social.twitter.api.impl.TwitterTemplate) SearchParameters(org.springframework.social.twitter.api.SearchParameters) Tweet(org.springframework.social.twitter.api.Tweet) ArrayList(java.util.ArrayList) SearchMetadata(org.springframework.social.twitter.api.SearchMetadata) SearchResults(org.springframework.social.twitter.api.SearchResults) SearchOperations(org.springframework.social.twitter.api.SearchOperations) Test(org.junit.Test)

Example 3 with SearchMetadata

use of org.springframework.social.twitter.api.SearchMetadata in project spring-integration by spring-projects.

the class TwitterSearchOutboundGatewayTests method testStringQuery.

@Test
public void testStringQuery() {
    Tweet tweet = mock(Tweet.class);
    SearchMetadata searchMetadata = mock(SearchMetadata.class);
    final SearchResults searchResults = new SearchResults(Collections.singletonList(tweet), searchMetadata);
    doAnswer(invocation -> {
        SearchParameters searchParameters = invocation.getArgument(0);
        assertEquals("foo", searchParameters.getQuery());
        assertEquals(Integer.valueOf(20), searchParameters.getCount());
        return searchResults;
    }).when(this.searchOps).search(any(SearchParameters.class));
    this.gateway.handleMessage(new GenericMessage<String>("foo"));
    Message<?> reply = this.outputChannel.receive(0);
    assertNotNull(reply);
    @SuppressWarnings("unchecked") List<Tweet> tweets = (List<Tweet>) reply.getPayload();
    assertEquals(1, tweets.size());
    assertSame(tweet, tweets.get(0));
    assertSame(searchMetadata, reply.getHeaders().get(TwitterHeaders.SEARCH_METADATA));
}
Also used : SearchParameters(org.springframework.social.twitter.api.SearchParameters) Tweet(org.springframework.social.twitter.api.Tweet) ArrayList(java.util.ArrayList) List(java.util.List) SearchMetadata(org.springframework.social.twitter.api.SearchMetadata) SearchResults(org.springframework.social.twitter.api.SearchResults) Test(org.junit.Test)

Example 4 with SearchMetadata

use of org.springframework.social.twitter.api.SearchMetadata in project spring-integration by spring-projects.

the class TwitterSearchOutboundGatewayTests method testSearchParamsQuery.

@Test
public void testSearchParamsQuery() {
    Tweet tweet = mock(Tweet.class);
    SearchMetadata searchMetadata = mock(SearchMetadata.class);
    final SearchResults searchResults = new SearchResults(Collections.singletonList(tweet), searchMetadata);
    final SearchParameters parameters = new SearchParameters("bar");
    doAnswer(invocation -> {
        SearchParameters searchParameters = invocation.getArgument(0);
        assertSame(parameters, searchParameters);
        return searchResults;
    }).when(this.searchOps).search(any(SearchParameters.class));
    this.gateway.handleMessage(new GenericMessage<SearchParameters>(parameters));
    Message<?> reply = this.outputChannel.receive(0);
    assertNotNull(reply);
    @SuppressWarnings("unchecked") List<Tweet> tweets = (List<Tweet>) reply.getPayload();
    assertEquals(1, tweets.size());
    assertSame(tweet, tweets.get(0));
    assertSame(searchMetadata, reply.getHeaders().get(TwitterHeaders.SEARCH_METADATA));
}
Also used : SearchParameters(org.springframework.social.twitter.api.SearchParameters) Tweet(org.springframework.social.twitter.api.Tweet) ArrayList(java.util.ArrayList) List(java.util.List) SearchMetadata(org.springframework.social.twitter.api.SearchMetadata) SearchResults(org.springframework.social.twitter.api.SearchResults) Test(org.junit.Test)

Example 5 with SearchMetadata

use of org.springframework.social.twitter.api.SearchMetadata in project spring-integration by spring-projects.

the class TwitterSearchOutboundGatewayTests method testEmptyResult.

@Test
public void testEmptyResult() {
    SearchMetadata searchMetadata = mock(SearchMetadata.class);
    List<Tweet> empty = new ArrayList<Tweet>(0);
    final SearchResults searchResults = new SearchResults(empty, searchMetadata);
    doAnswer(invocation -> {
        SearchParameters searchParameters = invocation.getArgument(0);
        assertEquals("foo", searchParameters.getQuery());
        assertEquals(Integer.valueOf(20), searchParameters.getCount());
        return searchResults;
    }).when(this.searchOps).search(any(SearchParameters.class));
    this.gateway.handleMessage(new GenericMessage<String>("foo"));
    Message<?> reply = this.outputChannel.receive(0);
    assertNotNull(reply);
    @SuppressWarnings("unchecked") List<Tweet> tweets = (List<Tweet>) reply.getPayload();
    assertEquals(0, tweets.size());
    assertSame(searchMetadata, reply.getHeaders().get(TwitterHeaders.SEARCH_METADATA));
}
Also used : SearchParameters(org.springframework.social.twitter.api.SearchParameters) Tweet(org.springframework.social.twitter.api.Tweet) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SearchMetadata(org.springframework.social.twitter.api.SearchMetadata) SearchResults(org.springframework.social.twitter.api.SearchResults) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 SearchMetadata (org.springframework.social.twitter.api.SearchMetadata)7 SearchParameters (org.springframework.social.twitter.api.SearchParameters)7 SearchResults (org.springframework.social.twitter.api.SearchResults)7 Tweet (org.springframework.social.twitter.api.Tweet)7 List (java.util.List)6 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)3 SearchOperations (org.springframework.social.twitter.api.SearchOperations)1 TwitterTemplate (org.springframework.social.twitter.api.impl.TwitterTemplate)1