use of org.springframework.social.twitter.api.TweetData in project spring-integration by spring-projects.
the class StatusUpdatingMessageHandlerTests method testStatusUpdatingMessageHandler.
@Test
public void testStatusUpdatingMessageHandler() {
TimelineOperations timelineOperations = Mockito.mock(TimelineOperations.class);
Mockito.when(this.twitter.timelineOperations()).thenReturn(timelineOperations);
ArgumentCaptor<TweetData> argument = ArgumentCaptor.forClass(TweetData.class);
this.in1.send(new GenericMessage<String>("foo"));
Mockito.verify(timelineOperations).updateStatus(argument.capture());
assertEquals("foo", argument.getValue().toRequestParameters().getFirst("status"));
Mockito.reset(timelineOperations);
ClassPathResource media = new ClassPathResource("log4j.properties");
this.in2.send(MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).setHeader("media", media).build());
Mockito.verify(timelineOperations).updateStatus(argument.capture());
TweetData tweetData = argument.getValue();
MultiValueMap<String, Object> requestParameters = tweetData.toRequestParameters();
assertEquals("bar", requestParameters.getFirst("status"));
assertNull(requestParameters.getFirst("media"));
MultiValueMap<String, Object> uploadMediaParameters = tweetData.toUploadMediaParameters();
assertEquals(media, uploadMediaParameters.getFirst("media"));
}
use of org.springframework.social.twitter.api.TweetData in project spring-integration by spring-projects.
the class StatusUpdatingMessageHandler method handleMessageInternal.
@Override
protected void handleMessageInternal(Message<?> message) throws Exception {
Object value;
if (this.tweetDataExpression != null) {
value = this.tweetDataExpression.getValue(this.evaluationContext, message);
} else {
value = message.getPayload();
}
Assert.notNull(value, "The tweetData cannot evaluate to 'null'.");
TweetData tweetData = null;
if (value instanceof TweetData) {
tweetData = (TweetData) value;
} else if (value instanceof Tweet) {
tweetData = new TweetData(((Tweet) value).getText());
} else if (value instanceof String) {
tweetData = new TweetData((String) value);
} else {
throw new MessageHandlingException(message, "Unsupported tweetData: " + value);
}
this.twitter.timelineOperations().updateStatus(tweetData);
}
Aggregations