Search in sources :

Example 1 with Feature

use of com.jeanchampemont.wtfdyum.dto.Feature in project WTFDYUM by jchampemont.

the class FeatureServiceTest method _init.

@Before
public void _init() {
    initMocks(this);
    final Map<Feature, FeatureStrategy> featureServices = new HashMap<>();
    featureServices.put(Feature.NOTIFY_UNFOLLOW, notifyUnfollowFeatureService);
    sut = new FeatureServiceImpl(featureServices);
}
Also used : HashMap(java.util.HashMap) FeatureServiceImpl(com.jeanchampemont.wtfdyum.service.impl.FeatureServiceImpl) Feature(com.jeanchampemont.wtfdyum.dto.Feature) NotifyUnfollowFeatureStrategy(com.jeanchampemont.wtfdyum.service.feature.impl.NotifyUnfollowFeatureStrategy) FeatureStrategy(com.jeanchampemont.wtfdyum.service.feature.FeatureStrategy) Before(org.junit.Before)

Example 2 with Feature

use of com.jeanchampemont.wtfdyum.dto.Feature 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 3 with Feature

use of com.jeanchampemont.wtfdyum.dto.Feature in project WTFDYUM by jchampemont.

the class AdminServiceImpl method countEnabledFeature.

@Override
public Map<Feature, Integer> countEnabledFeature(Set<Long> members) {
    Map<Feature, Integer> result = new HashMap<>();
    for (Feature f : Feature.values()) {
        int count = 0;
        for (Long member : members) {
            if (featureService.isEnabled(member, f)) {
                count++;
            }
        }
        result.put(f, count);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Feature(com.jeanchampemont.wtfdyum.dto.Feature)

Example 4 with Feature

use of com.jeanchampemont.wtfdyum.dto.Feature in project WTFDYUM by jchampemont.

the class RedisConfiguration method featureRedisTemplate.

@Bean
public RedisTemplate<String, Feature> featureRedisTemplate() {
    final RedisTemplate<String, Feature> template = new RedisTemplate<>();
    template.setConnectionFactory(redisConnectionFactory());
    template.setKeySerializer(new StringRedisSerializer());
    template.setHashKeySerializer(new EnumRedisSerializer<>(Feature.class));
    template.setValueSerializer(new EnumRedisSerializer<>(Feature.class));
    return template;
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) Feature(com.jeanchampemont.wtfdyum.dto.Feature) Bean(org.springframework.context.annotation.Bean)

Example 5 with Feature

use of com.jeanchampemont.wtfdyum.dto.Feature 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;
}
Also used : HashMap(java.util.HashMap) WTFDYUMException(com.jeanchampemont.wtfdyum.utils.WTFDYUMException) ModelAndView(org.springframework.web.servlet.ModelAndView) Feature(com.jeanchampemont.wtfdyum.dto.Feature) Secured(com.jeanchampemont.wtfdyum.security.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Feature (com.jeanchampemont.wtfdyum.dto.Feature)6 HashMap (java.util.HashMap)3 Event (com.jeanchampemont.wtfdyum.dto.Event)2 WTFDYUMException (com.jeanchampemont.wtfdyum.utils.WTFDYUMException)2 Secured (com.jeanchampemont.wtfdyum.security.Secured)1 FeatureStrategy (com.jeanchampemont.wtfdyum.service.feature.FeatureStrategy)1 NotifyUnfollowFeatureStrategy (com.jeanchampemont.wtfdyum.service.feature.impl.NotifyUnfollowFeatureStrategy)1 FeatureServiceImpl (com.jeanchampemont.wtfdyum.service.impl.FeatureServiceImpl)1 HashSet (java.util.HashSet)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Bean (org.springframework.context.annotation.Bean)1 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)1 StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1 StopWatch (org.springframework.util.StopWatch)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1