Search in sources :

Example 11 with FeatureToggles

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);
}
Also used : FeatureToggles(com.thoughtworks.go.server.domain.support.toggle.FeatureToggles) FeatureToggle(com.thoughtworks.go.server.domain.support.toggle.FeatureToggle) Test(org.junit.Test)

Example 12 with FeatureToggles

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));
}
Also used : FeatureToggles(com.thoughtworks.go.server.domain.support.toggle.FeatureToggles) FeatureToggle(com.thoughtworks.go.server.domain.support.toggle.FeatureToggle) Test(org.junit.Test)

Example 13 with FeatureToggles

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();
}
Also used : FeatureToggles(com.thoughtworks.go.server.domain.support.toggle.FeatureToggles) FeatureToggle(com.thoughtworks.go.server.domain.support.toggle.FeatureToggle) StubGoCache(com.thoughtworks.go.server.service.StubGoCache) TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) Test(org.junit.Test)

Example 14 with FeatureToggles

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);
    }
}
Also used : FeatureToggles(com.thoughtworks.go.server.domain.support.toggle.FeatureToggles) FileNotFoundException(java.io.FileNotFoundException)

Example 15 with FeatureToggles

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()));
}
Also used : FeatureToggles(com.thoughtworks.go.server.domain.support.toggle.FeatureToggles) File(java.io.File) Test(org.junit.Test)

Aggregations

FeatureToggles (com.thoughtworks.go.server.domain.support.toggle.FeatureToggles)19 Test (org.junit.Test)15 FeatureToggle (com.thoughtworks.go.server.domain.support.toggle.FeatureToggle)13 File (java.io.File)4 StubGoCache (com.thoughtworks.go.server.service.StubGoCache)2 TestTransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1