Search in sources :

Example 1 with TweetData

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"));
}
Also used : TweetData(org.springframework.social.twitter.api.TweetData) TimelineOperations(org.springframework.social.twitter.api.TimelineOperations) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 2 with TweetData

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);
}
Also used : Tweet(org.springframework.social.twitter.api.Tweet) TweetData(org.springframework.social.twitter.api.TweetData) MessageHandlingException(org.springframework.messaging.MessageHandlingException)

Aggregations

TweetData (org.springframework.social.twitter.api.TweetData)2 Test (org.junit.Test)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 MessageHandlingException (org.springframework.messaging.MessageHandlingException)1 TimelineOperations (org.springframework.social.twitter.api.TimelineOperations)1 Tweet (org.springframework.social.twitter.api.Tweet)1