Search in sources :

Example 1 with FeatureToggles

use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggles 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 FeatureToggles

use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggles 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 3 with FeatureToggles

use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggles 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 4 with FeatureToggles

use of com.thoughtworks.go.server.domain.support.toggle.FeatureToggles 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)

Example 5 with FeatureToggles

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

the class FeatureToggleRepositoryTest method shouldReadFeatureTogglesFromUsersTogglesFile.

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

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