Search in sources :

Example 11 with Principal

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

the class AbstractFeatureStrategyTest method principal.

protected Principal principal(final long id) {
    when(principalService.getMembers()).thenReturn(new HashSet<>(Arrays.asList(id)));
    final Principal principal = new Principal(id, "Principal 1 Token", "Principal 1 Token Secret");
    when(principalService.get(id)).thenReturn(principal);
    return principal;
}
Also used : Principal(com.jeanchampemont.wtfdyum.dto.Principal)

Example 12 with Principal

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

the class NotifyUnfollowFeatureStrategyTest method completeCronTest.

@Test
public void completeCronTest() throws Exception {
    final Principal principal = principal(1L);
    final Set<Long> followers = followers(principal, (s, f) -> s.thenReturn(f));
    sut.completeCron(1L);
    // New followers list should be saved
    verify(followersService, times(1)).saveFollowers(1L, followers);
}
Also used : Principal(com.jeanchampemont.wtfdyum.dto.Principal) Test(org.junit.Test)

Example 13 with Principal

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

the class TweetUnfollowFeatureStrategyTest method completeCronTest.

@Test
public void completeCronTest() throws Exception {
    final Principal principal = principal(1L);
    final Set<Long> followers = followers(principal, (s, f) -> s.thenReturn(f));
    sut.completeCron(1L);
    // New followers list should be saved
    verify(followersService, times(1)).saveFollowers(1L, followers);
}
Also used : Principal(com.jeanchampemont.wtfdyum.dto.Principal) Test(org.junit.Test)

Example 14 with Principal

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

the class MainControllerTest method signinCallbackTest.

@Test
public void signinCallbackTest() throws Exception {
    final RequestToken returnedRequestToken = new RequestToken("my_super_token", "");
    when(twitterService.signin(anyString())).thenReturn(returnedRequestToken);
    when(principalService.get(1203L)).thenReturn(null);
    final HttpSession session = mockMvc.perform(get("/signin")).andExpect(status().is3xxRedirection()).andExpect(redirectedUrlPattern("http*://**/**my_super_token")).andReturn().getRequest().getSession();
    assertThat(session).isNotNull();
    assertThat(session.getAttribute(MainController.SESSION_REQUEST_TOKEN)).isNotNull();
    assertThat(session.getAttribute(MainController.SESSION_REQUEST_TOKEN)).isEqualTo(returnedRequestToken);
    final AccessToken returnedAccessToken = new AccessToken("TOken", "secret");
    ReflectionTestUtils.setField(returnedAccessToken, "userId", 1203L);
    when(twitterService.completeSignin(returnedRequestToken, "42")).thenReturn(returnedAccessToken);
    mockMvc.perform(get("/signin/callback?oauth_verifier=42").session((MockHttpSession) session)).andExpect(status().is3xxRedirection()).andExpect(redirectedUrl("/user"));
    final Principal builtUser = new Principal(1203L, "TOken", "secret");
    verify(userService, times(1)).addEvent(1203L, new Event(EventType.REGISTRATION, null));
    verify(principalService, times(1)).saveUpdate(builtUser);
    verify(authenticationService, times(1)).authenticate(builtUser);
}
Also used : RequestToken(twitter4j.auth.RequestToken) HttpSession(javax.servlet.http.HttpSession) MockHttpSession(org.springframework.mock.web.MockHttpSession) AccessToken(twitter4j.auth.AccessToken) MockHttpSession(org.springframework.mock.web.MockHttpSession) Event(com.jeanchampemont.wtfdyum.dto.Event) Principal(com.jeanchampemont.wtfdyum.dto.Principal) Test(org.junit.Test)

Example 15 with Principal

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

the class UserControllerTest method indexTestTwitterErrorException.

@Test
public void indexTestTwitterErrorException() throws Exception {
    final Principal principal = new Principal(1L, "tok", "toksec");
    SessionManager.setPrincipal(principal);
    when(authenticationService.getCurrentUserId()).thenReturn(12340L);
    when(twitterService.getUser(principal, 12340L)).thenThrow(new WTFDYUMException(WTFDYUMExceptionType.TWITTER_ERROR));
    mockMvc.perform(get("/user")).andExpect(status().is3xxRedirection()).andExpect(redirectedUrl("/"));
    verify(authenticationService, times(1)).logOut();
}
Also used : WTFDYUMException(com.jeanchampemont.wtfdyum.utils.WTFDYUMException) Principal(com.jeanchampemont.wtfdyum.dto.Principal) 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