Search in sources :

Example 1 with TimelineOperations

use of org.springframework.social.twitter.api.TimelineOperations 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)

Aggregations

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