Search in sources :

Example 6 with Principal

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

the class TwitterServiceTest method verifyCredentialsTestTrue.

@Test
public void verifyCredentialsTestTrue() throws TwitterException {
    when(twitter.verifyCredentials()).thenReturn(null);
    final boolean result = sut.verifyCredentials(new Principal(12L, "tre", "tr"));
    assertThat(result).isTrue();
}
Also used : Principal(com.jeanchampemont.wtfdyum.dto.Principal) ResponseListMockForTest(com.jeanchampemont.wtfdyum.utils.ResponseListMockForTest) Test(org.junit.Test)

Example 7 with Principal

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

the class TwitterServiceTest method getUserTest.

@Test
public void getUserTest() throws Exception {
    final User userMock = mock(User.class);
    when(twitter.users()).thenReturn(usersResources);
    when(usersResources.showUser(123L)).thenReturn(userMock);
    when(userMock.getId()).thenReturn(123L);
    when(userMock.getName()).thenReturn("name");
    when(userMock.getScreenName()).thenReturn("screenName");
    when(userMock.getProfileImageURL()).thenReturn("profile img url");
    when(userMock.getURL()).thenReturn("user url");
    final com.jeanchampemont.wtfdyum.dto.User result = sut.getUser(new Principal(1L, "", ""), 123L);
    assertThat(result).isNotNull();
    assertThat(result.getId()).isEqualTo(123L);
    assertThat(result.getName()).isEqualTo("name");
    assertThat(result.getScreenName()).isEqualTo("screenName");
    assertThat(result.getProfileImageURL()).isEqualTo("profile img url");
    assertThat(result.getURL()).isEqualTo("user url");
}
Also used : Principal(com.jeanchampemont.wtfdyum.dto.Principal) ResponseListMockForTest(com.jeanchampemont.wtfdyum.utils.ResponseListMockForTest) Test(org.junit.Test)

Example 8 with Principal

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

the class TwitterServiceTest method tweetTestException.

@Test(expected = WTFDYUMException.class)
public void tweetTestException() throws Exception {
    when(twitter.updateStatus("my brand new tweet")).thenThrow(new TwitterException(""));
    sut.tweet(new Principal(144L, "tok", "toksec"), "my brand new tweet");
}
Also used : Principal(com.jeanchampemont.wtfdyum.dto.Principal) ResponseListMockForTest(com.jeanchampemont.wtfdyum.utils.ResponseListMockForTest) Test(org.junit.Test)

Example 9 with Principal

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

the class TwitterServiceTest method getFollowersTest.

@Test
public void getFollowersTest() throws Exception {
    final Optional<Principal> principal = Optional.of(new Principal(123L, "toktok", "secsecret"));
    final IDs idsMock = mock(IDs.class);
    when(twitter.getFollowersIDs(444L, -1)).thenReturn(idsMock);
    final RateLimitStatus rateLimitStatusMock = mock(RateLimitStatus.class);
    when(idsMock.getRateLimitStatus()).thenReturn(rateLimitStatusMock);
    when(rateLimitStatusMock.getRemaining()).thenReturn(1);
    when(idsMock.getIDs()).thenReturn(new long[] { 12L, 34L, 44L, 42L, 42L, 999L });
    final Set<Long> followers = sut.getFollowers(444L, principal);
    assertThat(followers).isNotNull();
    assertThat(followers.contains(12L));
    assertThat(followers.contains(34L));
    assertThat(followers.contains(44L));
    assertThat(followers.contains(42L));
    assertThat(followers.contains(999L));
    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)

Example 10 with Principal

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

the class TwitterServiceTest method getUsersMultiplePageTest.

@Test
public void getUsersMultiplePageTest() 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[150];
    final long[] first100 = new long[100];
    final long[] next50 = new long[50];
    final Random rand = new Random();
    for (int i = 0; i < 150; i++) {
        users.add(userMock);
        final long id = rand.nextLong();
        when(userMock.getId()).thenReturn(id);
        ids[i] = id;
        if (i < 100) {
            first100[i] = id;
        } else {
            next50[i - 100] = id;
        }
    }
    final ResponseList<User> first100Users = new ResponseListMockForTest<>();
    first100Users.addAll(users.subList(0, 100));
    final ResponseList<User> next50Users = new ResponseListMockForTest<>();
    next50Users.addAll(users.subList(100, 150));
    when(twitter.users()).thenReturn(usersResources);
    when(usersResources.lookupUsers(first100)).thenReturn(first100Users);
    when(usersResources.lookupUsers(next50)).thenReturn(next50Users);
    final List<com.jeanchampemont.wtfdyum.dto.User> result = sut.getUsers(new Principal(1L, "", ""), ids);
    assertThat(result).isNotNull();
    assertThat(result.size()).isEqualTo(150);
}
Also used : Random(java.util.Random) Principal(com.jeanchampemont.wtfdyum.dto.Principal) ResponseListMockForTest(com.jeanchampemont.wtfdyum.utils.ResponseListMockForTest) 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