use of com.thoughtworks.go.domain.activity.ProjectStatus in project gocd by gocd.
the class CcTrayConfigChangeHandlerTest method shouldHandleNewStagesInConfig_ByReplacingStagesMissingInDBWithNullStagesAndJobs.
@Test
public void shouldHandleNewStagesInConfig_ByReplacingStagesMissingInDBWithNullStagesAndJobs() throws Exception {
CruiseConfig config = new BasicCruiseConfig();
goConfigMother.addPipeline(config, "pipeline1", "stage1", "job1");
goConfigMother.addStageToPipeline(config, "pipeline1", "stage2", "job2");
String stage1ProjectName = "pipeline1 :: stage1";
String job1ProjectName = "pipeline1 :: stage1 :: job1";
String stage2ProjectName = "pipeline1 :: stage2";
String job2ProjectName = "pipeline1 :: stage2 :: job2";
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");
when(cache.get(stage1ProjectName)).thenReturn(statusOfStage1InCache);
when(cache.get(job1ProjectName)).thenReturn(statusOfJob1InCache);
when(cache.get(stage2ProjectName)).thenReturn(null);
when(stageStatusLoader.getStatusesForStageAndJobsOf(pipelineConfigFor(config, "pipeline1"), stageConfigFor(config, "pipeline1", "stage2"))).thenReturn(Collections.<ProjectStatus>emptyList());
handler.call(config);
ProjectStatus expectedNullStatusForStage2 = new ProjectStatus.NullProjectStatus(stage2ProjectName);
ProjectStatus expectedNullStatusForJob2 = new ProjectStatus.NullProjectStatus(job2ProjectName);
verify(cache).replaceAllEntriesInCacheWith(eq(asList(statusOfStage1InCache, statusOfJob1InCache, expectedNullStatusForStage2, expectedNullStatusForJob2)));
}
use of com.thoughtworks.go.domain.activity.ProjectStatus in project gocd by gocd.
the class CcTrayJobStatusChangeHandlerTest method shouldCreateNewStatusWithOldValuesFromCache_WhenNewJob_HasNotCompleted.
@Test
public void shouldCreateNewStatusWithOldValuesFromCache_WhenNewJob_HasNotCompleted() throws Exception {
ProjectStatus oldStatusInCache = new ProjectStatus(projectNameFor("job1"), "OldActivity", "OldStatus", "OldLabel", new Date(), webUrlFor("job1"));
when(cache.get(projectNameFor("job1"))).thenReturn(oldStatusInCache);
CcTrayJobStatusChangeHandler handler = new CcTrayJobStatusChangeHandler(cache);
ProjectStatus newStatus = handler.statusFor(JobInstanceMother.building("job1"), new HashSet<>());
assertThat(newStatus.getLastBuildStatus(), is(oldStatusInCache.getLastBuildStatus()));
assertThat(newStatus.getLastBuildLabel(), is(oldStatusInCache.getLastBuildLabel()));
assertThat(newStatus.getLastBuildTime(), is(oldStatusInCache.getLastBuildTime()));
assertThat(newStatus.getBreakers(), is(oldStatusInCache.getBreakers()));
assertThat(webUrlOf(newStatus), is(webUrlFor("job1")));
}
use of com.thoughtworks.go.domain.activity.ProjectStatus in project gocd by gocd.
the class CcTrayJobStatusChangeHandlerTest method shouldCreateNewStatusWithNoPartsUsedFromCache_WhenNewJob_HasCompleted.
@Test
public void shouldCreateNewStatusWithNoPartsUsedFromCache_WhenNewJob_HasCompleted() throws Exception {
ProjectStatus oldStatusInCache = new ProjectStatus(projectNameFor("job1"), "OldActivity", "OldStatus", "OldLabel", new Date(), webUrlFor("job1"));
when(cache.get(projectNameFor("job1"))).thenReturn(oldStatusInCache);
CcTrayJobStatusChangeHandler handler = new CcTrayJobStatusChangeHandler(cache);
ProjectStatus newStatus = handler.statusFor(JobInstanceMother.completed("job1"), new HashSet<>());
assertThat(activityOf(newStatus), is("Sleeping"));
assertThat(newStatus.getLastBuildStatus(), is("Success"));
assertThat(newStatus.getLastBuildLabel(), is("label-1"));
assertThat(newStatus.getBreakers(), is(Collections.<String>emptySet()));
assertThat(webUrlOf(newStatus), is(webUrlFor("job1")));
}
use of com.thoughtworks.go.domain.activity.ProjectStatus in project gocd by gocd.
the class CcTrayStageStatusChangeHandlerTest method shouldLeaveBuildDetailsOfStageSameAsTheOneInCache_WhenStageIsNotCompleted_AndThereIsAnExistingStageInCache.
@Test
public void shouldLeaveBuildDetailsOfStageSameAsTheOneInCache_WhenStageIsNotCompleted_AndThereIsAnExistingStageInCache() throws Exception {
String projectName = "pipeline :: stage1";
ProjectStatus existingStageStatus = new ProjectStatus(projectName, "OldActivity", "OldStatus", "OldLabel", new Date(), webUrlFor("stage1"));
when(cache.get(projectName)).thenReturn(existingStageStatus);
Stage stage = StageMother.custom("stage1", JobInstanceMother.building("job1"));
List<ProjectStatus> statuses = handler.statusesOfStageAndItsJobsFor(stage);
ProjectStatus statusOfStage = statuses.get(0);
assertThat(stage.getState().completed(), is(not(true)));
assertThat(statusOfStage.getLastBuildStatus(), is(existingStageStatus.getLastBuildStatus()));
assertThat(statusOfStage.getLastBuildTime(), is(existingStageStatus.getLastBuildTime()));
assertThat(statusOfStage.getLastBuildLabel(), is(existingStageStatus.getLastBuildLabel()));
}
use of com.thoughtworks.go.domain.activity.ProjectStatus in project gocd by gocd.
the class CcTrayStageStatusChangeHandlerTest method shouldUpdateBuildDetailsOfStageWhenStageIsCompleted.
@Test
public void shouldUpdateBuildDetailsOfStageWhenStageIsCompleted() throws Exception {
Stage completedStage = StageMother.createPassedStage("pipeline", 1, "stage1", 1, "job1", new Date());
completedStage.setCompletedByTransitionId(1L);
List<ProjectStatus> statuses = handler.statusesOfStageAndItsJobsFor(completedStage);
ProjectStatus statusOfStage = statuses.get(0);
assertThat(completedStage.isCompleted(), is(true));
assertThat(statusOfStage.getLastBuildStatus(), is("Success"));
assertThat(statusOfStage.getLastBuildTime(), is(completedStage.completedDate()));
assertThat(statusOfStage.getLastBuildLabel(), is("LABEL-1"));
}
Aggregations