Search in sources :

Example 26 with Principal

use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.

the class TwitterServiceTest method getUserTestException.

@Test(expected = WTFDYUMException.class)
public void getUserTestException() throws Exception {
    when(twitter.users()).thenReturn(usersResources);
    when(usersResources.showUser(123L)).thenThrow(new TwitterException("msg"));
    sut.getUser(new Principal(1L, "", ""), 123L);
}
Also used : Principal(com.jeanchampemont.wtfdyum.dto.Principal) ResponseListMockForTest(com.jeanchampemont.wtfdyum.utils.ResponseListMockForTest) Test(org.junit.Test)

Example 27 with Principal

use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.

the class TwitterServiceTest method getUsersTwitterExceptionTest.

@Test
public void getUsersTwitterExceptionTest() throws Exception {
    final User userMock = mock(User.class);
    when(userMock.getName()).thenReturn("name");
    when(userMock.getScreenName()).thenReturn("screenName");
    when(userMock.getProfileImageURL()).thenReturn("profile img url");
    when(userMock.getURL()).thenReturn("user url");
    final ResponseList<User> users = new ResponseListMockForTest<User>();
    final long[] ids = new long[100];
    final Random rand = new Random();
    for (int i = 0; i < 100; i++) {
        users.add(userMock);
        final long id = rand.nextLong();
        when(userMock.getId()).thenReturn(id);
        ids[i] = id;
    }
    when(twitter.users()).thenReturn(usersResources);
    when(usersResources.lookupUsers(ids)).thenThrow(TwitterException.class);
    try {
        sut.getUsers(new Principal(1L, "", ""), ids);
        Assertions.failBecauseExceptionWasNotThrown(WTFDYUMException.class);
    } catch (WTFDYUMException e) {
        assertThat(e.getType()).isEqualTo(WTFDYUMExceptionType.TWITTER_ERROR);
    }
}
Also used : Random(java.util.Random) WTFDYUMException(com.jeanchampemont.wtfdyum.utils.WTFDYUMException) Principal(com.jeanchampemont.wtfdyum.dto.Principal) ResponseListMockForTest(com.jeanchampemont.wtfdyum.utils.ResponseListMockForTest) ResponseListMockForTest(com.jeanchampemont.wtfdyum.utils.ResponseListMockForTest) Test(org.junit.Test)

Example 28 with Principal

use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.

the class TwitterServiceTest method sendDirectMessageTest.

@Test
public void sendDirectMessageTest() throws Exception {
    final Principal principal = new Principal(123L, "toktok", "secsecret");
    sut.sendDirectMessage(principal, 555L, "text");
    verify(twitter, times(1)).sendDirectMessage(555L, "text");
}
Also used : Principal(com.jeanchampemont.wtfdyum.dto.Principal) ResponseListMockForTest(com.jeanchampemont.wtfdyum.utils.ResponseListMockForTest) Test(org.junit.Test)

Example 29 with Principal

use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.

the class TwitterServiceTest method sendDirectMessageTestException.

@Test
public void sendDirectMessageTestException() throws Exception {
    when(twitter.sendDirectMessage(444L, "text")).thenThrow(new TwitterException("msg"));
    try {
        sut.sendDirectMessage(new Principal(412L, "", ""), 444L, "text");
        Assertions.failBecauseExceptionWasNotThrown(WTFDYUMException.class);
    } catch (final WTFDYUMException e) {
        assertThat(e.getType()).isEqualTo(WTFDYUMExceptionType.TWITTER_ERROR);
    }
}
Also used : WTFDYUMException(com.jeanchampemont.wtfdyum.utils.WTFDYUMException) Principal(com.jeanchampemont.wtfdyum.dto.Principal) ResponseListMockForTest(com.jeanchampemont.wtfdyum.utils.ResponseListMockForTest) Test(org.junit.Test)

Example 30 with Principal

use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.

the class TwitterServiceTest method getFollowersMultiplePageTest.

@Test
public void getFollowersMultiplePageTest() throws Exception {
    final Optional<Principal> principal = Optional.of(new Principal(123L, "toktok", "secsecret"));
    final IDs firstPageMock = mock(IDs.class);
    final IDs secondPageMock = mock(IDs.class);
    final RateLimitStatus firstPageRateLimitMock = mock(RateLimitStatus.class);
    when(firstPageRateLimitMock.getRemaining()).thenReturn(1);
    when(firstPageMock.getRateLimitStatus()).thenReturn(firstPageRateLimitMock);
    when(firstPageMock.hasNext()).thenReturn(true);
    when(firstPageMock.getIDs()).thenReturn(new long[] { 12L, 34L, 44L, 42L, 42L, 999L });
    when(firstPageMock.getNextCursor()).thenReturn(42L);
    final RateLimitStatus secondPageRateLimitMock = mock(RateLimitStatus.class);
    when(secondPageRateLimitMock.getRemaining()).thenReturn(0);
    when(secondPageMock.getRateLimitStatus()).thenReturn(secondPageRateLimitMock);
    when(secondPageMock.hasNext()).thenReturn(false);
    when(secondPageMock.getIDs()).thenReturn(new long[] { 1001L, 1002L, 1003L });
    when(twitter.getFollowersIDs(444L, -1)).thenReturn(firstPageMock);
    when(twitter.getFollowersIDs(444L, 42)).thenReturn(secondPageMock);
    final Set<Long> followers = sut.getFollowers(444L, principal);
    assertThat(followers).isNotNull();
    assertThat(followers).containsOnly(12L, 34L, 44L, 42L, 999L, 1001L, 1002L, 1003L);
    verify(twitter, times(1)).setOAuthAccessToken(new AccessToken("toktok", "secsecret"));
}
Also used : AccessToken(twitter4j.auth.AccessToken) Principal(com.jeanchampemont.wtfdyum.dto.Principal) ResponseListMockForTest(com.jeanchampemont.wtfdyum.utils.ResponseListMockForTest) Test(org.junit.Test)

Aggregations

Principal (com.jeanchampemont.wtfdyum.dto.Principal)37 Test (org.junit.Test)27 ResponseListMockForTest (com.jeanchampemont.wtfdyum.utils.ResponseListMockForTest)15 Event (com.jeanchampemont.wtfdyum.dto.Event)9 User (com.jeanchampemont.wtfdyum.dto.User)5 Random (java.util.Random)4 AccessToken (twitter4j.auth.AccessToken)4 WTFDYUMException (com.jeanchampemont.wtfdyum.utils.WTFDYUMException)3 HashSet (java.util.HashSet)2 RequestToken (twitter4j.auth.RequestToken)2 HttpSession (javax.servlet.http.HttpSession)1 Bean (org.springframework.context.annotation.Bean)1 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)1 StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)1 MockHttpSession (org.springframework.mock.web.MockHttpSession)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1 StopWatch (org.springframework.util.StopWatch)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 RedirectView (org.springframework.web.servlet.view.RedirectView)1