Search in sources :

Example 11 with FeatureToggle

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

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

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

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

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