Search in sources :

Example 51 with CruiseConfig

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;
}
Also used : File(java.io.File) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig)

Example 52 with CruiseConfig

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));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) GoConfigDao(com.thoughtworks.go.config.GoConfigDao) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 53 with CruiseConfig

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));
}
Also used : CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) GoConfigDao(com.thoughtworks.go.config.GoConfigDao) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 54 with CruiseConfig

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);
}
Also used : EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) ConfigChangedListener(com.thoughtworks.go.listener.ConfigChangedListener) SecurityConfigChangeListener(com.thoughtworks.go.listener.SecurityConfigChangeListener) PluginRoleConfig(com.thoughtworks.go.config.PluginRoleConfig) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) Test(org.junit.Test)

Example 55 with 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");
}
Also used : GoCache(com.thoughtworks.go.server.cache.GoCache) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) ServerSiteUrlConfig(com.thoughtworks.go.domain.ServerSiteUrlConfig) Test(org.junit.Test)

Aggregations

CruiseConfig (com.thoughtworks.go.config.CruiseConfig)95 Test (org.junit.Test)77 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)54 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)35 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)33 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)32 ServerConfig (com.thoughtworks.go.config.ServerConfig)11 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)7 ServerHealthStateOperationResult (com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult)5 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)5 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)4 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)4 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)4 ServerSiteUrlConfig (com.thoughtworks.go.domain.ServerSiteUrlConfig)4 File (java.io.File)4 ConfigCache (com.thoughtworks.go.config.ConfigCache)3 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)3 MagicalGoConfigXmlLoader (com.thoughtworks.go.config.MagicalGoConfigXmlLoader)3 SecurityConfig (com.thoughtworks.go.config.SecurityConfig)3 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)3