Search in sources :

Example 31 with ProjectStatus

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)));
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) Test(org.junit.Test)

Example 32 with ProjectStatus

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")));
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) Date(java.util.Date) Test(org.junit.Test)

Example 33 with ProjectStatus

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")));
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) Date(java.util.Date) Test(org.junit.Test)

Example 34 with ProjectStatus

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()));
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) NullStage(com.thoughtworks.go.domain.NullStage) Stage(com.thoughtworks.go.domain.Stage) Test(org.junit.Test)

Example 35 with ProjectStatus

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"));
}
Also used : ProjectStatus(com.thoughtworks.go.domain.activity.ProjectStatus) NullStage(com.thoughtworks.go.domain.NullStage) Stage(com.thoughtworks.go.domain.Stage) 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