Search in sources :

Example 1 with StubGoCache

use of com.thoughtworks.go.server.service.StubGoCache in project gocd by gocd.

the class UserSqlMapDaoTest method setUp.

@Before
public void setUp() {
    initMocks(this);
    goCache = new StubGoCache(new TestTransactionSynchronizationManager());
    dao = new UserSqlMapDao(sessionFactory, transactionTemplate, goCache, transactionSynchronizationManager);
}
Also used : StubGoCache(com.thoughtworks.go.server.service.StubGoCache) TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) Before(org.junit.Before)

Example 2 with StubGoCache

use of com.thoughtworks.go.server.service.StubGoCache in project gocd by gocd.

the class FeatureToggleServiceTest method shouldInvalidateCacheWhenAFeatureTogglesValueIsChanged.

@Test
public void shouldInvalidateCacheWhenAFeatureTogglesValueIsChanged() 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();
    verify(repository, times(1)).availableToggles();
    service.changeValueOfToggle("key1", false);
    verify(repository, times(1)).availableToggles();
    service.allToggles();
    verify(repository, times(2)).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 3 with StubGoCache

use of com.thoughtworks.go.server.service.StubGoCache 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 4 with StubGoCache

use of com.thoughtworks.go.server.service.StubGoCache in project gocd by gocd.

the class StageSqlMapDaoTest method setUp.

@Before
public void setUp() {
    goCache = new StubGoCache(new TestTransactionSynchronizationManager());
    sqlMapClientTemplate = mock(SqlMapClientTemplate.class);
    stageSqlMapDao = new StageSqlMapDao(mock(JobInstanceSqlMapDao.class), new Cache(true, false, false), mock(TransactionTemplate.class), mock(SqlMapClient.class), goCache, mock(TransactionSynchronizationManager.class), mock(SystemEnvironment.class), null);
    stageSqlMapDao.setSqlMapClientTemplate(sqlMapClientTemplate);
    cloner = mock(Cloner.class);
    ReflectionUtil.setField(stageSqlMapDao, "cloner", cloner);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            return invocationOnMock.getArguments()[0];
        }
    }).when(cloner).deepClone(anyObject());
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) StubGoCache(com.thoughtworks.go.server.service.StubGoCache) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SqlMapClientTemplate(org.springframework.orm.ibatis.SqlMapClientTemplate) Matchers.anyObject(org.mockito.Matchers.anyObject) TestTransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager) GoCache(com.thoughtworks.go.server.cache.GoCache) StubGoCache(com.thoughtworks.go.server.service.StubGoCache) Cache(com.opensymphony.oscache.base.Cache) Cloner(com.rits.cloning.Cloner) Before(org.junit.Before)

Aggregations

StubGoCache (com.thoughtworks.go.server.service.StubGoCache)4 TestTransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TestTransactionSynchronizationManager)4 FeatureToggle (com.thoughtworks.go.server.domain.support.toggle.FeatureToggle)2 FeatureToggles (com.thoughtworks.go.server.domain.support.toggle.FeatureToggles)2 Before (org.junit.Before)2 Test (org.junit.Test)2 Cache (com.opensymphony.oscache.base.Cache)1 Cloner (com.rits.cloning.Cloner)1 GoCache (com.thoughtworks.go.server.cache.GoCache)1 Matchers.anyObject (org.mockito.Matchers.anyObject)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 SqlMapClientTemplate (org.springframework.orm.ibatis.SqlMapClientTemplate)1