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;
}
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);
}
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);
}
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);
}
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();
}
Aggregations