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);
}
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));
}
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;
}
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;
}
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;
}
Aggregations