Search in sources :

Example 21 with Principal

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

the class CronServiceTest method checkCredentialsTestInvalid.

@Test
public void checkCredentialsTestInvalid() throws Exception {
    final Principal principal = principal(1L);
    when(twitterService.verifyCredentials(principal)).thenReturn(false);
    sut.checkCredentials();
    verify(userService, times(1)).addEvent(1L, new Event(EventType.INVALID_TWITTER_CREDENTIALS, ""));
    verify(userService, times(1)).applyLimit(1L, UserLimitType.CREDENTIALS_INVALID);
}
Also used : Event(com.jeanchampemont.wtfdyum.dto.Event) Principal(com.jeanchampemont.wtfdyum.dto.Principal) Test(org.junit.Test)

Example 22 with Principal

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

the class CronServiceTest method checkCredentialsTest.

@Test
public void checkCredentialsTest() throws Exception {
    final Principal principal = principal(1L);
    when(twitterService.verifyCredentials(principal)).thenReturn(true);
    sut.checkCredentials();
    verify(userService, times(1)).resetLimit(1L, UserLimitType.CREDENTIALS_INVALID);
}
Also used : Principal(com.jeanchampemont.wtfdyum.dto.Principal) Test(org.junit.Test)

Example 23 with Principal

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

the class PrincipalServiceTest method saveUpdateTest.

@Test
public void saveUpdateTest() {
    final Principal u = new Principal(12L, "tokdf", "secrrr");
    when(principalRedisTemplate.opsForValue()).thenReturn(valueOperations);
    when(longRedisTemplate.opsForSet()).thenReturn(setOperations);
    sut.saveUpdate(u);
    verify(valueOperations, times(1)).set("12", u);
    verify(setOperations, times(1)).add("MEMBERS", 12L);
}
Also used : Principal(com.jeanchampemont.wtfdyum.dto.Principal) Test(org.junit.Test)

Example 24 with Principal

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

the class TwitterServiceTest method getUsersTwitterExceptionButJustOneUserLookedUpTest.

@Test
public void getUsersTwitterExceptionButJustOneUserLookedUpTest() 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[1];
    users.add(userMock);
    final long id = new Random().nextLong();
    when(userMock.getId()).thenReturn(id);
    ids[0] = id;
    when(twitter.users()).thenReturn(usersResources);
    TwitterException exception = mock(TwitterException.class);
    when(exception.getErrorCode()).thenReturn(17);
    when(usersResources.lookupUsers(ids)).thenThrow(exception);
    List<com.jeanchampemont.wtfdyum.dto.User> result = sut.getUsers(new Principal(1L, "", ""), ids);
    assertThat(result).isNotNull().isEmpty();
}
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)

Example 25 with Principal

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

the class TwitterServiceTest method getUsersTest.

@Test
public void getUsersTest() 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)).thenReturn(users);
    final List<com.jeanchampemont.wtfdyum.dto.User> result = sut.getUsers(new Principal(1L, "", ""), ids);
    assertThat(result).isNotNull();
    assertThat(result.size()).isEqualTo(100);
}
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