Search in sources :

Example 1 with FeatureToggle

use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggle in project gocd by gocd.

the class FeatureToggleRepositoryTest method shouldReadFeatureTogglesFromAvailableTogglesFile.

@Test
public void shouldReadFeatureTogglesFromAvailableTogglesFile() throws Exception {
    FeatureToggle featureToggle1 = new FeatureToggle("key1", "desc1", true);
    FeatureToggle featureToggle2 = new FeatureToggle("key2", "desc2", false);
    setupAvailableToggles(featureToggle1, featureToggle2);
    FeatureToggleRepository repository = new FeatureToggleRepository(environment);
    assertThat(repository.availableToggles(), is(new FeatureToggles(featureToggle1, featureToggle2)));
}
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 2 with FeatureToggle

use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggle in project gocd by gocd.

the class FeatureToggleRepositoryTest method shouldFailWhenUnableToWriteToUserTogglesFile_DuringChangingOfAToggleValue.

@Test
public void shouldFailWhenUnableToWriteToUserTogglesFile_DuringChangingOfAToggleValue() throws Exception {
    setupAvailableToggles(new FeatureToggle("key1", "desc1", true));
    File userTogglesFile = setupUserToggles(new FeatureToggle("key1", "desc1", true));
    userTogglesFile.setReadOnly();
    FeatureToggleRepository repository = new FeatureToggleRepository(environment);
    try {
        repository.changeValueOfToggle("key1", false);
        fail("Should have failed to write");
    } catch (RuntimeException e) {
        assertThat(e.getMessage(), containsString(userTogglesFile.getPath()));
    }
}
Also used : FeatureToggle(com.thoughtworks.go.server.domain.support.toggle.FeatureToggle) File(java.io.File) Test(org.junit.Test)

Example 3 with FeatureToggle

use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggle in project gocd by gocd.

the class FeatureToggleRepositoryTest method shouldAllowChangingValueOfAToggleWhenTheUserTogglesFileDoesNotExist.

@Test
public void shouldAllowChangingValueOfAToggleWhenTheUserTogglesFileDoesNotExist() throws Exception {
    File togglesDir = TestFileUtil.createTempFolder("toggles.dir");
    File nonExistentUserToggleFile = new File(togglesDir, "a-non-existent-file");
    setupUserToggleFileAs(nonExistentUserToggleFile);
    setupAvailableToggles(new FeatureToggle("key1", "desc1", true));
    FeatureToggleRepository repository = new FeatureToggleRepository(environment);
    repository.changeValueOfToggle("key1", false);
    assertThat(repository.availableToggles(), is(new FeatureToggles(new FeatureToggle("key1", "desc1", true))));
    assertThat(repository.userToggles(), is(new FeatureToggles(new FeatureToggle("key1", null, false))));
}
Also used : FeatureToggles(com.thoughtworks.go.server.domain.support.toggle.FeatureToggles) FeatureToggle(com.thoughtworks.go.server.domain.support.toggle.FeatureToggle) File(java.io.File) Test(org.junit.Test)

Example 4 with FeatureToggle

use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggle in project gocd by gocd.

the class FeatureToggleRepositoryTest method whileChangingAToggleValue_shouldNotPersist_ValueHasBeenChangedFlag.

@Test
public void whileChangingAToggleValue_shouldNotPersist_ValueHasBeenChangedFlag() throws Exception {
    String fieldForHasBeenChangedFlag = "hasBeenChangedFromDefault";
    assertNotNull("This can never be null, but can throw an exception. If you've renamed the field mentioned above" + "(in FeatureToggle class), please change it in this test too. Otherwise, this test can pass, wrongly.", FeatureToggle.class.getDeclaredField(fieldForHasBeenChangedFlag));
    setupAvailableToggles(new FeatureToggle("key1", "desc1", true));
    File userTogglesFile = setupUserToggles(new FeatureToggle("key1", "desc1", false).withValueHasBeenChangedFlag(true));
    FeatureToggleRepository repository = new FeatureToggleRepository(environment);
    repository.changeValueOfToggle("key1", false);
    assertThat(repository.userToggles(), is(new FeatureToggles(new FeatureToggle("key1", "desc1", false).withValueHasBeenChangedFlag(false))));
    assertThat(FileUtils.readFileToString(userTogglesFile), containsString("key1"));
    assertThat(FileUtils.readFileToString(userTogglesFile), containsString("desc1"));
    assertThat(FileUtils.readFileToString(userTogglesFile), not(containsString(fieldForHasBeenChangedFlag)));
    /* The first time the file is written, it is written by hand in this test. Force it to write again,
         * so that the actual JSON write logic is used.
         */
    repository.changeValueOfToggle("key1", true);
    assertThat(repository.userToggles(), is(new FeatureToggles(new FeatureToggle("key1", "desc1", true).withValueHasBeenChangedFlag(false))));
    assertThat(FileUtils.readFileToString(userTogglesFile), containsString("key1"));
    assertThat(FileUtils.readFileToString(userTogglesFile), containsString("desc1"));
    assertThat(FileUtils.readFileToString(userTogglesFile), not(containsString(fieldForHasBeenChangedFlag)));
}
Also used : FeatureToggles(com.thoughtworks.go.server.domain.support.toggle.FeatureToggles) FeatureToggle(com.thoughtworks.go.server.domain.support.toggle.FeatureToggle) File(java.io.File) Test(org.junit.Test)

Example 5 with FeatureToggle

use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggle in project gocd by gocd.

the class FeatureToggleRepositoryTest method shouldAllowChangingValueOfAToggleWhenTheUserTogglesFileDoesExist.

@Test
public void shouldAllowChangingValueOfAToggleWhenTheUserTogglesFileDoesExist() throws Exception {
    setupAvailableToggles(new FeatureToggle("key1", "desc1", true), new FeatureToggle("key2", "desc2", true));
    setupUserToggles(new FeatureToggle("key1", "desc1", true));
    FeatureToggleRepository repository = new FeatureToggleRepository(environment);
    repository.changeValueOfToggle("key1", false);
    assertThat(repository.availableToggles(), is(new FeatureToggles(new FeatureToggle("key1", "desc1", true), new FeatureToggle("key2", "desc2", true))));
    assertThat(repository.userToggles(), is(new FeatureToggles(new FeatureToggle("key1", "desc1", 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)

Aggregations

FeatureToggle (com.thoughtworks.go.server.domain.support.toggle.FeatureToggle)14 Test (org.junit.Test)14 FeatureToggles (com.thoughtworks.go.server.domain.support.toggle.FeatureToggles)13 File (java.io.File)3 StubGoCache (com.thoughtworks.go.server.service.StubGoCache)2 TestTransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager)2