Search in sources :

Example 1 with Event

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

Example 2 with Event

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

Example 3 with Event

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

Example 4 with Event

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

Example 5 with Event

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

Aggregations

Event (com.jeanchampemont.wtfdyum.dto.Event)22 Test (org.junit.Test)16 Principal (com.jeanchampemont.wtfdyum.dto.Principal)9 User (com.jeanchampemont.wtfdyum.dto.User)5 WTFDYUMException (com.jeanchampemont.wtfdyum.utils.WTFDYUMException)3 HashSet (java.util.HashSet)3 Feature (com.jeanchampemont.wtfdyum.dto.Feature)2 Scheduled (org.springframework.scheduling.annotation.Scheduled)2 StopWatch (org.springframework.util.StopWatch)2 AccessToken (twitter4j.auth.AccessToken)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 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 RedirectView (org.springframework.web.servlet.view.RedirectView)1