Search in sources :

Example 31 with Principal

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())));
}
Also used : User(com.jeanchampemont.wtfdyum.dto.User) Event(com.jeanchampemont.wtfdyum.dto.Event) Principal(com.jeanchampemont.wtfdyum.dto.Principal) Test(org.junit.Test)

Example 32 with Principal

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())));
}
Also used : User(com.jeanchampemont.wtfdyum.dto.User) Event(com.jeanchampemont.wtfdyum.dto.Event) Principal(com.jeanchampemont.wtfdyum.dto.Principal) Test(org.junit.Test)

Example 33 with Principal

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)));
}
Also used : User(com.jeanchampemont.wtfdyum.dto.User) Event(com.jeanchampemont.wtfdyum.dto.Event) Principal(com.jeanchampemont.wtfdyum.dto.Principal) Test(org.junit.Test)

Example 34 with Principal

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);
}
Also used : RequestToken(twitter4j.auth.RequestToken) AccessToken(twitter4j.auth.AccessToken) RedirectView(org.springframework.web.servlet.view.RedirectView) Event(com.jeanchampemont.wtfdyum.dto.Event) Principal(com.jeanchampemont.wtfdyum.dto.Principal) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 35 with Principal

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;
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) Principal(com.jeanchampemont.wtfdyum.dto.Principal) Bean(org.springframework.context.annotation.Bean)

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