use of org.springframework.social.twitter.api.SearchParameters 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));
}
use of org.springframework.social.twitter.api.SearchParameters 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));
}
use of org.springframework.social.twitter.api.SearchParameters 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));
}
use of org.springframework.social.twitter.api.SearchParameters in project spring-integration by spring-projects.
the class TwitterSearchOutboundGatewayTests method testStringQueryCustomLimit.
@Test
public void testStringQueryCustomLimit() {
this.gateway.setSearchArgsExpression(new SpelExpressionParser().parseExpression("{payload, 30}"));
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(30), 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));
}
use of org.springframework.social.twitter.api.SearchParameters in project spring-integration by spring-projects.
the class TwitterSearchOutboundGatewayTests method testSearchParamsQueryCustomExpression.
@Test
public void testSearchParamsQueryCustomExpression() {
this.gateway.setSearchArgsExpression(new SpelExpressionParser().parseExpression("new SearchParameters('foo' + payload).count(5).sinceId(11)"));
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("foobar", searchParameters.getQuery());
assertEquals(Integer.valueOf(5), searchParameters.getCount());
assertEquals(Long.valueOf(11), searchParameters.getSinceId());
return searchResults;
}).when(this.searchOps).search(any(SearchParameters.class));
this.gateway.handleMessage(new GenericMessage<String>("bar"));
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));
}
Aggregations