MongoTogglzRepository extends AbstractMongoRepository<String, FeatureState> implements StateRepository { @Override public void setFeatureState(final FeatureState featureState) { createOrUpdate(featureState); LOG.info((!isEmpty(userProvider.getCurrentUser().getName()) ? "User '" + userProvider.getCurrentUser().getName() + "'" : "Unknown user") + (featureState.isEnabled() ? " enabled " : " disabled ") + "feature " + featureState.getFeature().name()); } MongoTogglzRepository(final MongoDatabase mongoDatabase,
                                 final FeatureClassProvider featureClassProvider,
                                 final UserProvider userProvider,
                                 final MongoProperties mongoProperties); @Override FeatureState getFeatureState(final Feature feature); @Override void setFeatureState(final FeatureState featureState);  }
@Test public void shouldSetFeatureState() { final FeatureState featureState = new FeatureState(TestFeatures.TEST_FEATURE_1); featureState.setEnabled(true); featureState.setStrategyId("someStrategy"); featureState.setParameter("someKey1", "someValue1"); featureState.setParameter("someKey2", "someValue2"); testee.setFeatureState(featureState); final Optional<FeatureState> loadedFeatureState = testee.findOne(TestFeatures.TEST_FEATURE_1.name()); assertThat(loadedFeatureState.isPresent(), is(true)); assertThat(loadedFeatureState.get().getFeature(), is(TestFeatures.TEST_FEATURE_1)); assertThat(loadedFeatureState.get().getStrategyId(), is("someStrategy")); assertThat(loadedFeatureState.get().isEnabled(), is(true)); assertThat(loadedFeatureState.get().getParameter("someKey1"), is("someValue1")); assertThat(loadedFeatureState.get().getParameter("someKey2"), is("someValue2")); }