Search in sources :

Example 26 with ProjectStatus

use of com.thoughtworks.go.domain.activity.ProjectStatus in project gocd by gocd.

the class CcTrayConfigChangeHandlerTest method shouldPopulateNewCacheWithStageAndJobFromDB_WhenAStageIsNotFoundInTheOldCache.

@Test
public void shouldPopulateNewCacheWithStageAndJobFromDB_WhenAStageIsNotFoundInTheOldCache() throws Exception {
    CruiseConfig config = GoConfigMother.configWithPipelines("pipeline1");
    String stageProjectName = "pipeline1 :: stage";
    String jobProjectName = "pipeline1 :: stage :: job";
    ProjectStatus statusOfStageInDB = new ProjectStatus(stageProjectName, "OldActivity", "OldStatus", "OldLabel", new Date(), "stage-url");
    ProjectStatus statusOfJobInDB = new ProjectStatus(jobProjectName, "OldActivity-Job", "OldStatus-Job", "OldLabel-Job", new Date(), "job-url");
    when(cache.get(stageProjectName)).thenReturn(null);
    when(stageStatusLoader.getStatusesForStageAndJobsOf(pipelineConfigFor(config, "pipeline1"), stageConfigFor(config, "pipeline1", "stage"))).thenReturn(asList(statusOfStageInDB, statusOfJobInDB));
    handler.call(config);
    verify(cache).replaceAllEntriesInCacheWith(eq(asList(statusOfStageInDB, statusOfJobInDB)));
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) Test(org.junit.Test)

Example 27 with ProjectStatus

use of com.thoughtworks.go.domain.activity.ProjectStatus in project gocd by gocd.

the class CcTrayConfigChangeHandlerTest method shouldRemoveExtraJobsFromCache_WhichAreNoLongerInConfig.

@Test
public void shouldRemoveExtraJobsFromCache_WhichAreNoLongerInConfig() throws Exception {
    String stage1ProjectName = "pipeline1 :: stage1";
    String job1ProjectName = "pipeline1 :: stage1 :: job1";
    String projectNameOfJobWhichWillBeRemoved = "pipeline1 :: stage1 :: JOB_IN_OLD_CONFIG";
    ProjectStatus statusOfStage1InCache = new ProjectStatus(stage1ProjectName, "OldActivity", "OldStatus", "OldLabel", new Date(), "stage-url");
    ProjectStatus statusOfJob1InCache = new ProjectStatus(job1ProjectName, "OldActivity-Job", "OldStatus-Job", "OldLabel-Job", new Date(), "job1-url");
    ProjectStatus statusOfOldJobInCache = new ProjectStatus(projectNameOfJobWhichWillBeRemoved, "OldActivity-Job", "OldStatus-Job", "OldLabel-Job", new Date(), "job2-url");
    when(cache.get(stage1ProjectName)).thenReturn(statusOfStage1InCache);
    when(cache.get(job1ProjectName)).thenReturn(statusOfJob1InCache);
    when(cache.get(projectNameOfJobWhichWillBeRemoved)).thenReturn(statusOfOldJobInCache);
    CruiseConfig config = new BasicCruiseConfig();
    goConfigMother.addPipeline(config, "pipeline1", "stage1", "job1");
    handler.call(config);
    verify(cache).replaceAllEntriesInCacheWith(eq(asList(statusOfStage1InCache, statusOfJob1InCache)));
    verifyZeroInteractions(stageStatusLoader);
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) Test(org.junit.Test)

Example 28 with ProjectStatus

use of com.thoughtworks.go.domain.activity.ProjectStatus in project gocd by gocd.

the class CcTrayConfigChangeHandlerTest method shouldUpdateCacheWithPipelineDetailsWhenPipelineConfigChanges.

@Test
public void shouldUpdateCacheWithPipelineDetailsWhenPipelineConfigChanges() {
    String pipeline1Stage = "pipeline1 :: stage1";
    String pipeline1job = "pipeline1 :: stage1 :: job1";
    String pipeline2stage = "pipeline2 :: stage1";
    String pipeline2job = "pipeline2 :: stage1 :: job1";
    ProjectStatus statusOfPipeline1StageInCache = new ProjectStatus(pipeline1Stage, "OldActivity", "OldStatus", "OldLabel", new Date(), "p1-stage-url");
    ProjectStatus statusOfPipeline1JobInCache = new ProjectStatus(pipeline1job, "OldActivity-Job", "OldStatus-Job", "OldLabel-Job", new Date(), "p1-job-url");
    ProjectStatus statusOfPipeline2StageInCache = new ProjectStatus(pipeline1Stage, "OldActivity", "OldStatus", "OldLabel", new Date(), "p2-stage-url");
    ProjectStatus statusOfPipeline2JobInCache = new ProjectStatus(pipeline1job, "OldActivity-Job", "OldStatus-Job", "OldLabel-Job", new Date(), "p2-job2-url");
    when(cache.get(pipeline1Stage)).thenReturn(statusOfPipeline1StageInCache);
    when(cache.get(pipeline1job)).thenReturn(statusOfPipeline1JobInCache);
    when(cache.get(pipeline2stage)).thenReturn(statusOfPipeline2StageInCache);
    when(cache.get(pipeline2job)).thenReturn(statusOfPipeline2JobInCache);
    PipelineConfig pipeline1Config = GoConfigMother.pipelineHavingJob("pipeline1", "stage1", "job1", "arts", "dir").pipelineConfigByName(new CaseInsensitiveString("pipeline1"));
    handler.call(pipeline1Config);
    ArgumentCaptor<ArrayList<ProjectStatus>> argumentCaptor = new ArgumentCaptor<>();
    verify(cache).putAll(argumentCaptor.capture());
    List<ProjectStatus> allValues = argumentCaptor.getValue();
    assertThat(allValues.get(0).name(), is(pipeline1Stage));
    assertThat(allValues.get(1).name(), is(pipeline1job));
    verify(cache, atLeastOnce()).get(pipeline1Stage);
    verify(cache, atLeastOnce()).get(pipeline1job);
    verifyNoMoreInteractions(cache);
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) ArgumentCaptor(org.mockito.ArgumentCaptor) Test(org.junit.Test)

Example 29 with ProjectStatus

use of com.thoughtworks.go.domain.activity.ProjectStatus in project gocd by gocd.

the class CcTrayConfigChangeHandlerTest method shouldHandleNewJobsInConfig_ByReplacingJobsMissingInDBWithNullJob.

/* Simulate adding a job, when server is down. DB does not know anything about that job. */
@Test
public void shouldHandleNewJobsInConfig_ByReplacingJobsMissingInDBWithNullJob() throws Exception {
    CruiseConfig config = new BasicCruiseConfig();
    goConfigMother.addPipeline(config, "pipeline1", "stage1", "job1", "NEW_JOB_IN_CONFIG");
    String stage1ProjectName = "pipeline1 :: stage1";
    String job1ProjectName = "pipeline1 :: stage1 :: job1";
    String projectNameOfNewJob = "pipeline1 :: stage1 :: NEW_JOB_IN_CONFIG";
    ProjectStatus statusOfStage1InDB = new ProjectStatus(stage1ProjectName, "OldActivity", "OldStatus", "OldLabel", new Date(), "stage-url");
    ProjectStatus statusOfJob1InDB = new ProjectStatus(job1ProjectName, "OldActivity-Job", "OldStatus-Job", "OldLabel-Job", new Date(), "job1-url");
    when(cache.get(stage1ProjectName)).thenReturn(null);
    when(stageStatusLoader.getStatusesForStageAndJobsOf(pipelineConfigFor(config, "pipeline1"), stageConfigFor(config, "pipeline1", "stage1"))).thenReturn(asList(statusOfStage1InDB, statusOfJob1InDB));
    handler.call(config);
    ProjectStatus expectedNullStatusForNewJob = new ProjectStatus.NullProjectStatus(projectNameOfNewJob);
    verify(cache).replaceAllEntriesInCacheWith(eq(asList(statusOfStage1InDB, statusOfJob1InDB, expectedNullStatusForNewJob)));
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) Test(org.junit.Test)

Example 30 with ProjectStatus

use of com.thoughtworks.go.domain.activity.ProjectStatus in project gocd by gocd.

the class CcTrayConfigChangeHandlerTest method shouldPopulateNewCacheWithProjectsFromOldCacheWhenTheyExist.

@Test
public void shouldPopulateNewCacheWithProjectsFromOldCacheWhenTheyExist() throws Exception {
    String stageProjectName = "pipeline1 :: stage";
    String jobProjectName = "pipeline1 :: stage :: job";
    ProjectStatus existingStageStatus = new ProjectStatus(stageProjectName, "OldActivity", "OldStatus", "OldLabel", new Date(), "stage-url");
    when(cache.get(stageProjectName)).thenReturn(existingStageStatus);
    ProjectStatus existingJobStatus = new ProjectStatus(jobProjectName, "OldActivity-Job", "OldStatus-Job", "OldLabel-Job", new Date(), "job-url");
    when(cache.get(jobProjectName)).thenReturn(existingJobStatus);
    handler.call(GoConfigMother.configWithPipelines("pipeline1"));
    verify(cache).replaceAllEntriesInCacheWith(eq(asList(existingStageStatus, existingJobStatus)));
    verifyZeroInteractions(stageStatusLoader);
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) Test(org.junit.Test)

Aggregations

ProjectStatus (com.thoughtworks.go.domain.activity.ProjectStatus)43 Test (org.junit.Test)34 Date (java.util.Date)14 Stage (com.thoughtworks.go.domain.Stage)9 NullStage (com.thoughtworks.go.domain.NullStage)8 Permissions (com.thoughtworks.go.config.security.Permissions)4 Users (com.thoughtworks.go.config.security.users.Users)4 ArrayList (java.util.ArrayList)4 AllowedUsers (com.thoughtworks.go.config.security.users.AllowedUsers)3 JobInstance (com.thoughtworks.go.domain.JobInstance)3 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)2 StageIdentity (com.thoughtworks.go.server.domain.StageIdentity)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 PipelineGroupVisitor (com.thoughtworks.go.domain.PipelineGroupVisitor)1 Viewers (com.thoughtworks.go.domain.cctray.viewers.Viewers)1 HashSet (java.util.HashSet)1