use of com.jeanchampemont.wtfdyum.dto.Event in project WTFDYUM by jchampemont.
the class CronServiceTest method cronTestNPEError.
@Test
public void cronTestNPEError() throws Exception {
principal(4L);
featureEnabled(4L, true, Feature.NOTIFY_UNFOLLOW);
when(featureService.cron(4L, Feature.NOTIFY_UNFOLLOW)).thenThrow(new NullPointerException());
sut.cron();
// should have an event UNKNOWN_ERROR
verify(userService, times(1)).addEvent(4L, new Event(EventType.UNKNOWN_ERROR, null));
}
use of com.jeanchampemont.wtfdyum.dto.Event in project WTFDYUM by jchampemont.
the class CronServiceTest method cronTestRateLimitError.
@Test
public void cronTestRateLimitError() throws Exception {
principal(3L);
featureEnabled(3L, true, Feature.NOTIFY_UNFOLLOW);
when(featureService.cron(3L, Feature.NOTIFY_UNFOLLOW)).thenThrow(new WTFDYUMException(WTFDYUMExceptionType.GET_FOLLOWERS_RATE_LIMIT_EXCEEDED));
sut.cron();
// should have an event RATE_LIMIT_EXCEEDED
verify(userService, times(1)).addEvent(3L, new Event(EventType.RATE_LIMIT_EXCEEDED, null));
}
use of com.jeanchampemont.wtfdyum.dto.Event in project WTFDYUM by jchampemont.
the class UserServiceTest method applyLimitTestReached.
@Test
public void applyLimitTestReached() {
when(longRedisTemplate.opsForValue()).thenReturn(longValueOperations);
when(eventRedisTemplate.opsForList()).thenReturn(eventListOperations);
when(longValueOperations.increment(UserLimitType.CREDENTIALS_INVALID.name() + "_442", 1)).thenReturn(5L);
final boolean result = sut.applyLimit(442L, UserLimitType.CREDENTIALS_INVALID);
assertThat(result).isTrue();
for (final Feature f : Feature.values()) {
verify(featureService, times(1)).disableFeature(442L, f);
}
final ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
verify(eventListOperations, times(1)).leftPush(eq("EVENTS_442"), eventCaptor.capture());
assertThat(eventCaptor.getValue().getType()).isEqualTo(EventType.CREDENTIALS_INVALID_LIMIT_REACHED);
assertThat(eventCaptor.getValue().getAdditionalData()).isEmpty();
assertThat(eventCaptor.getValue().getCreationDateTime()).isEqualTo(LocalDateTime.now(clock));
}
use of com.jeanchampemont.wtfdyum.dto.Event in project WTFDYUM by jchampemont.
the class UserServiceTest method getRecentEventsTest.
@Test
public void getRecentEventsTest() {
final List<Event> result = Arrays.asList(new Event(EventType.REGISTRATION, "reg"), new Event(EventType.UNFOLLOW, "unfoll"));
when(eventRedisTemplate.opsForList()).thenReturn(eventListOperations);
when(eventListOperations.range("EVENTS_1249", 0, 12)).thenReturn(result);
final List<Event> returnedResult = sut.getRecentEvents(1249L, 12);
assertThat(returnedResult).isNotNull();
assertThat(returnedResult.size()).isEqualTo(2);
assertThat(returnedResult).isEqualTo(result);
}
use of com.jeanchampemont.wtfdyum.dto.Event in project WTFDYUM by jchampemont.
the class UserServiceTest method addEventTest.
@Test
public void addEventTest() {
when(eventRedisTemplate.opsForList()).thenReturn(eventListOperations);
final Event event = new Event(EventType.REGISTRATION, "data");
sut.addEvent(31L, event);
verify(eventListOperations, times(1)).leftPush("EVENTS_31", event);
assertThat(event.getCreationDateTime()).isEqualTo(LocalDateTime.now(clock));
}
Aggregations