Search in sources :

Example 16 with FeatureToggles

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

the class FeatureToggleRepositoryTest method shouldNotFailWhenSpecifiedUserTogglesFileIsNotFound.

@Test
public void shouldNotFailWhenSpecifiedUserTogglesFileIsNotFound() throws Exception {
    setupUserToggleFileAs(new File("a-non-existent-file"));
    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)

Example 17 with FeatureToggles

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

the class FeatureToggleServiceTest method shouldOverrideAvailableToggleValuesWithValuesFromUsersToggles.

@Test
public void shouldOverrideAvailableToggleValuesWithValuesFromUsersToggles() throws Exception {
    FeatureToggle availableToggle1 = new FeatureToggle("key1", "desc1", true);
    FeatureToggle availableToggle2 = new FeatureToggle("key2", "desc2", true);
    FeatureToggle availableToggle3 = new FeatureToggle("key3", "desc3", true);
    when(repository.availableToggles()).thenReturn(new FeatureToggles(availableToggle1, availableToggle2, availableToggle3));
    FeatureToggle userToggle1 = new FeatureToggle("key1", "NEW_desc1_WITH_NO_change_to_value", true);
    FeatureToggle userToggle2 = new FeatureToggle("key2", "NEW_desc2_WITH_CHANGE_TO_VALUE", false);
    when(repository.userToggles()).thenReturn(new FeatureToggles(userToggle1, userToggle2));
    FeatureToggleService service = new FeatureToggleService(repository, goCache);
    FeatureToggles toggles = service.allToggles();
    assertThat(toggles.all().size(), is(3));
    assertThat(toggles.all().get(0), is(new FeatureToggle("key1", "NEW_desc1_WITH_NO_change_to_value", true).withValueHasBeenChangedFlag(false)));
    assertThat(toggles.all().get(1), is(new FeatureToggle("key2", "NEW_desc2_WITH_CHANGE_TO_VALUE", false).withValueHasBeenChangedFlag(true)));
    assertThat(toggles.all().get(2), is(new FeatureToggle("key3", "desc3", true).withValueHasBeenChangedFlag(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 18 with FeatureToggles

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

the class FeatureToggleServiceTest method shouldNotAllowChangingValueOfAnInvalidFeatureToggle.

@Test
public void shouldNotAllowChangingValueOfAnInvalidFeatureToggle() 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);
    try {
        service.changeValueOfToggle("keyNOTVALID", true);
        fail("This should have failed with an exception, since the feature toggle is invalid.");
    } catch (RuntimeException e) {
        assertThat(e.getMessage(), is("Feature toggle: 'keyNOTVALID' is not valid."));
    }
}
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 19 with FeatureToggles

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

the class FeatureToggleServiceTest method shouldSayThatNonExistentTogglesAreOff.

@Test
public void shouldSayThatNonExistentTogglesAreOff() 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("NON_EXISTENT_KEY"), 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)

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