use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggles in project gocd by gocd.
the class FeatureToggleServiceTest method shouldAllowChangingValueOfAValidFeatureToggle.
@Test
public void shouldAllowChangingValueOfAValidFeatureToggle() throws Exception {
FeatureToggle availableToggle1 = new FeatureToggle("key1", "desc1", true);
when(repository.availableToggles()).thenReturn(new FeatureToggles(availableToggle1));
when(repository.userToggles()).thenReturn(new FeatureToggles());
FeatureToggleService service = new FeatureToggleService(repository, goCache);
service.changeValueOfToggle("key1", false);
verify(repository).changeValueOfToggle("key1", false);
}
use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggles in project gocd by gocd.
the class FeatureToggleServiceTest method shouldKnowWhetherAToggleIsOnOrOff.
@Test
public void shouldKnowWhetherAToggleIsOnOrOff() throws Exception {
FeatureToggles existingToggles = new FeatureToggles(new FeatureToggle("key1", "description1", true), new FeatureToggle("key2", "description2", false));
when(repository.availableToggles()).thenReturn(existingToggles);
when(repository.userToggles()).thenReturn(new FeatureToggles());
FeatureToggleService service = new FeatureToggleService(repository, goCache);
assertThat(service.isToggleOn("key1"), is(true));
assertThat(service.isToggleOn("key2"), is(false));
}
use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggles in project gocd by gocd.
the class FeatureToggleServiceTest method shouldCacheFeatureToggleStatus.
@Test
public void shouldCacheFeatureToggleStatus() throws Exception {
when(repository.availableToggles()).thenReturn(new FeatureToggles(new FeatureToggle("key1", "desc1", true)));
when(repository.userToggles()).thenReturn(new FeatureToggles());
FeatureToggleService service = new FeatureToggleService(repository, new StubGoCache(new TestTransactionSynchronizationManager()));
service.allToggles();
service.allToggles();
service.isToggleOn("key1");
service.isToggleOn("someOtherKey");
verify(repository, times(1)).availableToggles();
}
use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggles in project gocd by gocd.
the class FeatureToggleRepository method readTogglesFromStream.
private FeatureToggles readTogglesFromStream(InputStream streamForToggles, String kindOfToggle) {
try {
String existingToggleJSONContent = IOUtils.toString(streamForToggles);
FeatureToggleFileContentRepresentation toggleContent = gson.fromJson(existingToggleJSONContent, FeatureToggleFileContentRepresentation.class);
return new FeatureToggles(toggleContent.toggles);
} catch (Exception e) {
LOGGER.error("Failed to read " + kindOfToggle + " toggles. Saying there are no toggles.", e);
return new FeatureToggles();
} finally {
IOUtils.closeQuietly(streamForToggles);
}
}
use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggles in project gocd by gocd.
the class FeatureToggleRepositoryTest method shouldNotFailWhenContentOfUserTogglesFileIsInvalid.
@Test
public void shouldNotFailWhenContentOfUserTogglesFileIsInvalid() throws Exception {
File toggleFile = TestFileUtil.createTempFile("available.toggle.test");
FileUtils.writeStringToFile(toggleFile, "SOME-INVALID-CONTENT");
setupUserToggleFileAs(toggleFile);
FeatureToggleRepository repository = new FeatureToggleRepository(environment);
assertThat(repository.userToggles(), is(new FeatureToggles()));
}
Aggregations