use of com.jeanchampemont.wtfdyum.utils.WTFDYUMException in project WTFDYUM by jchampemont.
the class MainController method signin.
@RequestMapping(value = "/signin", method = RequestMethod.GET)
public RedirectView signin(final HttpServletRequest request) throws WTFDYUMException {
if (authenticationService.isAuthenticated()) {
return new RedirectView("/user", true);
}
if (maxMembers > 0 && principalService.countMembers() >= maxMembers) {
throw new WTFDYUMException(WTFDYUMExceptionType.MEMBER_LIMIT_EXCEEDED);
}
final RequestToken requestToken = twitterService.signin("/signin/callback");
request.getSession().setAttribute(SESSION_REQUEST_TOKEN, requestToken);
return new RedirectView(requestToken.getAuthenticationURL());
}
use of com.jeanchampemont.wtfdyum.utils.WTFDYUMException in project WTFDYUM by jchampemont.
the class CronServiceTest method cronTestTwitterError.
@Test
public void cronTestTwitterError() throws Exception {
principal(2L);
featureEnabled(2L, true, Feature.NOTIFY_UNFOLLOW);
when(featureService.cron(2L, Feature.NOTIFY_UNFOLLOW)).thenThrow(new WTFDYUMException(WTFDYUMExceptionType.TWITTER_ERROR));
sut.cron();
// should have an event TWITTER_ERROR
verify(userService, times(1)).addEvent(2L, new Event(EventType.TWITTER_ERROR, null));
}
use of com.jeanchampemont.wtfdyum.utils.WTFDYUMException in project WTFDYUM by jchampemont.
the class TwitterServiceTest method getUsersTwitterExceptionTest.
@Test
public void getUsersTwitterExceptionTest() 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)).thenThrow(TwitterException.class);
try {
sut.getUsers(new Principal(1L, "", ""), ids);
Assertions.failBecauseExceptionWasNotThrown(WTFDYUMException.class);
} catch (WTFDYUMException e) {
assertThat(e.getType()).isEqualTo(WTFDYUMExceptionType.TWITTER_ERROR);
}
}
use of com.jeanchampemont.wtfdyum.utils.WTFDYUMException in project WTFDYUM by jchampemont.
the class TwitterServiceTest method sendDirectMessageTestException.
@Test
public void sendDirectMessageTestException() throws Exception {
when(twitter.sendDirectMessage(444L, "text")).thenThrow(new TwitterException("msg"));
try {
sut.sendDirectMessage(new Principal(412L, "", ""), 444L, "text");
Assertions.failBecauseExceptionWasNotThrown(WTFDYUMException.class);
} catch (final WTFDYUMException e) {
assertThat(e.getType()).isEqualTo(WTFDYUMExceptionType.TWITTER_ERROR);
}
}
use of com.jeanchampemont.wtfdyum.utils.WTFDYUMException in project WTFDYUM by jchampemont.
the class UserController method index.
@RequestMapping(method = RequestMethod.GET)
@Secured
public ModelAndView index() {
final ModelAndView result = new ModelAndView("user/index");
final Long userId = authenticationService.getCurrentUserId();
try {
result.getModel().put("user", twitterService.getUser(SessionManager.getPrincipal(), userId));
} catch (final WTFDYUMException e) {
authenticationService.logOut();
return new ModelAndView("redirect:/");
}
result.getModel().put("events", userService.getRecentEvents(userId, 10));
result.getModel().put("availableFeatures", Feature.values());
final Map<String, Boolean> featuresStatus = new HashMap<>();
for (final Feature f : Feature.values()) {
featuresStatus.put(f.name(), featureService.isEnabled(userId, f));
}
result.getModel().put("featuresStatus", featuresStatus);
return result;
}
Aggregations