use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class NotifyUnfollowFeatureStrategyTest method cronTest.
@Test
public void cronTest() throws Exception {
final Principal principal = principal(1L);
final Set<Long> followers = followers(principal, (s, f) -> s.thenReturn(f));
final List<User> unfollowers = unfollowers(principal, followers, (s, u) -> s.thenReturn(u));
final Set<Event> events = sut.cron(1L);
verifyUnfollowDM(principal, unfollowers.get(0));
verifyUnfollowDM(principal, unfollowers.get(1));
assertThat(events.contains(new Event(EventType.UNFOLLOW, unfollowers.get(0).getScreenName())));
assertThat(events.contains(new Event(EventType.UNFOLLOW, unfollowers.get(1).getScreenName())));
}
use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class TweetUnfollowFeatureStrategyTest method cronTest.
@Test
public void cronTest() throws Exception {
final Principal principal = principal(1L);
final Set<Long> followers = followers(principal, (s, f) -> s.thenReturn(f));
final List<User> unfollowers = unfollowers(principal, followers, (s, u) -> s.thenReturn(u));
final Set<Event> events = sut.cron(1L);
verifyUnfollowTweet(principal, unfollowers.get(0));
verifyUnfollowTweet(principal, unfollowers.get(1));
assertThat(events.contains(new Event(EventType.UNFOLLOW, unfollowers.get(0).getScreenName())));
assertThat(events.contains(new Event(EventType.UNFOLLOW, unfollowers.get(1).getScreenName())));
}
use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class UserControllerTest method indexTest.
@Test
public void indexTest() throws Exception {
final Principal principal = new Principal(1L, "tok", "toksec");
SessionManager.setPrincipal(principal);
final User u = new User();
final List<Event> events = Arrays.asList(new Event(), new Event(EventType.REGISTRATION, ""));
when(authenticationService.getCurrentUserId()).thenReturn(12340L);
when(twitterService.getUser(principal, 12340L)).thenReturn(u);
when(userService.getRecentEvents(12340L, 10)).thenReturn(events);
when(featureService.isEnabled(12340L, Feature.NOTIFY_UNFOLLOW)).thenReturn(true);
mockMvc.perform(get("/user")).andExpect(status().isOk()).andExpect(view().name("user/index")).andExpect(model().attribute("user", u)).andExpect(model().attribute("events", events)).andExpect(model().attribute("availableFeatures", Feature.values())).andExpect(model().attribute("featuresStatus", hasEntry(Feature.NOTIFY_UNFOLLOW.name(), true)));
}
use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class MainController method signinCallback.
@RequestMapping(value = "/signin/callback", method = RequestMethod.GET)
public RedirectView signinCallback(@RequestParam("oauth_verifier") final String verifier, final HttpServletRequest request) throws WTFDYUMException {
final RequestToken requestToken = (RequestToken) request.getSession().getAttribute(SESSION_REQUEST_TOKEN);
request.getSession().removeAttribute(SESSION_REQUEST_TOKEN);
final AccessToken accessToken = twitterService.completeSignin(requestToken, verifier);
if (principalService.get(accessToken.getUserId()) == null) {
userService.addEvent(accessToken.getUserId(), new Event(EventType.REGISTRATION, null));
}
final Principal user = new Principal(accessToken.getUserId(), accessToken.getToken(), accessToken.getTokenSecret());
principalService.saveUpdate(user);
authenticationService.authenticate(user);
return new RedirectView("/user", true);
}
use of com.jeanchampemont.wtfdyum.dto.Principal in project WTFDYUM by jchampemont.
the class RedisConfiguration method principalRedisTemplate.
@Bean
public RedisTemplate<String, Principal> principalRedisTemplate() {
final RedisTemplate<String, Principal> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory());
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(jsonSerializer(Principal.class, objectMapper()));
template.setValueSerializer(jsonSerializer(Principal.class, objectMapper()));
return template;
}
Aggregations