use of com.thoughtworks.go.config.CruiseConfig in project gocd by gocd.
the class ArtifactsDiskSpaceFullCheckerTest method mockGoConfigServiceToHaveSiteUrl.
public static GoConfigService mockGoConfigServiceToHaveSiteUrl() {
CruiseConfig cruiseConfig = configWithSiteUrl();
GoConfigService goConfigService = mock(GoConfigService.class);
when(goConfigService.artifactsDir()).thenReturn(new File("."));
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
when(goConfigService.adminEmail()).thenReturn("admin@email.com");
return goConfigService;
}
use of com.thoughtworks.go.config.CruiseConfig in project gocd by gocd.
the class PipelineSqlMapDaoCachingTest method shouldRemovePipelineIdFromCacheWhenStageFinishesForNonLatestPipeline.
@Test
public void shouldRemovePipelineIdFromCacheWhenStageFinishesForNonLatestPipeline() {
final String pipelineName = "pipeline";
CruiseConfig mockCruiseConfig = mock(BasicCruiseConfig.class);
GoConfigDao mockconfigFileDao = mock(GoConfigDao.class);
when(mockconfigFileDao.load()).thenReturn(mockCruiseConfig);
when(mockCruiseConfig.getAllPipelineNames()).thenReturn(Arrays.asList(new CaseInsensitiveString(pipelineName)));
// need to mock configfileDao for this test
pipelineDao = new PipelineSqlMapDao(null, repository, goCache, environmentVariableDao, transactionTemplate, null, transactionSynchronizationManager, null, mockconfigFileDao, null, mock(SessionFactory.class));
pipelineDao.setSqlMapClientTemplate(mockTemplate);
PipelineInstanceModel first = model(1, JobState.Building, JobResult.Unknown);
PipelineInstanceModel second = model(2, JobState.Building, JobResult.Unknown);
PipelineInstanceModels pims = PipelineInstanceModels.createPipelineInstanceModels(first, second);
when(mockTemplate.queryForList("allActivePipelines")).thenReturn(pims);
when(mockTemplate.queryForObject("getPipelineHistoryById", arguments("id", 1L).asMap())).thenReturn(first);
when(mockTemplate.queryForObject("getPipelineHistoryById", arguments("id", 2L).asMap())).thenReturn(second);
// ensure cache is initialized
pipelineDao.loadActivePipelines();
Stage stage = new Stage("first", new JobInstances(JobInstanceMother.assigned("job")), "me", "whatever", new TimeProvider());
stage.fail();
stage.calculateResult();
changeStageStatus(stage, 1);
// notifying latest id should not remove it from the cache
stage.setPipelineId(2l);
pipelineDao.stageStatusChanged(stage);
PipelineInstanceModels models = pipelineDao.loadActivePipelines();
assertThat(models.size(), is(1));
assertThat(models.get(0).getId(), is(2L));
}
use of com.thoughtworks.go.config.CruiseConfig in project gocd by gocd.
the class PipelineSqlMapDaoCachingTest method shouldRemovePipelineIdFromCacheWhenPipelineCeasesToBeTheLatestAndIsNotActive.
@Test
public void shouldRemovePipelineIdFromCacheWhenPipelineCeasesToBeTheLatestAndIsNotActive() {
final String pipelineName = "pipeline";
CruiseConfig mockCruiseConfig = mock(BasicCruiseConfig.class);
GoConfigDao mockconfigFileDao = mock(GoConfigDao.class);
when(mockconfigFileDao.load()).thenReturn(mockCruiseConfig);
when(mockCruiseConfig.getAllPipelineNames()).thenReturn(Arrays.asList(new CaseInsensitiveString(pipelineName)));
// need to mock configfileDao for this test
pipelineDao = new PipelineSqlMapDao(null, repository, goCache, environmentVariableDao, transactionTemplate, null, transactionSynchronizationManager, null, mockconfigFileDao, null, mock(SessionFactory.class));
pipelineDao.setSqlMapClientTemplate(mockTemplate);
PipelineInstanceModel first = model(1, JobState.Completed, JobResult.Passed);
PipelineInstanceModel second = model(2, JobState.Building, JobResult.Unknown);
PipelineInstanceModels pims = PipelineInstanceModels.createPipelineInstanceModels(first);
when(mockTemplate.queryForList("allActivePipelines")).thenReturn(pims);
when(mockTemplate.queryForObject("getPipelineHistoryById", arguments("id", 1L).asMap())).thenReturn(first);
when(mockTemplate.queryForObject("getPipelineHistoryById", arguments("id", 2L).asMap())).thenReturn(second);
// ensure cache is initialized
pipelineDao.loadActivePipelines();
changeStageStatus(2);
PipelineInstanceModels models = pipelineDao.loadActivePipelines();
assertThat(models.size(), is(1));
assertThat(models.get(0).getId(), is(2L));
}
use of com.thoughtworks.go.config.CruiseConfig in project gocd by gocd.
the class CcTrayActivityListenerTest method shouldInvokeConfigChangeHandlerWhenSecurityConfigChanges.
@Test
public void shouldInvokeConfigChangeHandlerWhenSecurityConfigChanges() throws InterruptedException {
CcTrayConfigChangeHandler ccTrayConfigChangeHandler = mock(CcTrayConfigChangeHandler.class);
CruiseConfig cruiseConfig = mock(CruiseConfig.class);
ArgumentCaptor<ConfigChangedListener> captor = ArgumentCaptor.forClass(ConfigChangedListener.class);
doNothing().when(goConfigService).register(captor.capture());
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
CcTrayActivityListener listener = new CcTrayActivityListener(goConfigService, mock(CcTrayJobStatusChangeHandler.class), mock(CcTrayStageStatusChangeHandler.class), ccTrayConfigChangeHandler);
listener.initialize();
listener.startDaemon();
List<ConfigChangedListener> listeners = captor.getAllValues();
assertThat(listeners.get(2) instanceof SecurityConfigChangeListener, is(true));
SecurityConfigChangeListener securityConfigChangeListener = (SecurityConfigChangeListener) listeners.get(2);
securityConfigChangeListener.onEntityConfigChange(new PluginRoleConfig());
waitForProcessingToHappen();
verify(ccTrayConfigChangeHandler).call(cruiseConfig);
}
use of com.thoughtworks.go.config.CruiseConfig in project gocd by gocd.
the class BaseUrlChangeListenerTest method shouldFlushCacheWhenBaseUrlConfigChangesAndUpdateTheSiteURLAndSecureSiteURLToTheNewValues.
@Test
public void shouldFlushCacheWhenBaseUrlConfigChangesAndUpdateTheSiteURLAndSecureSiteURLToTheNewValues() throws IOException {
GoCache cache = mock(GoCache.class);
BaseUrlChangeListener listener = new BaseUrlChangeListener(new ServerSiteUrlConfig(""), new ServerSiteUrlConfig(""), cache);
CruiseConfig newCruiseConfig = new BasicCruiseConfig();
newCruiseConfig.setServerConfig(serverConfigWith("http://blah.com", "https://blah.com"));
listener.onConfigChange(newCruiseConfig);
listener.onConfigChange(newCruiseConfig);
verify(cache, times(1)).remove("urls_cache");
}
Aggregations