use of com.thoughtworks.go.server.dao.StageDao in project gocd by gocd.
the class StageServiceIntegrationTest method shouldNotifyListenersWhenJobCancelledSuccessfully.
@Test
public void shouldNotifyListenersWhenJobCancelledSuccessfully() {
StageStatusListener listener = mock(StageStatusListener.class);
JobInstanceService jobInstanceService = mock(JobInstanceService.class);
JobInstance job = JobInstanceMother.building("foo");
JobIdentifier jobId = new JobIdentifier("pipeline", 10, "label-10", "stage", "1", "foo");
job.setIdentifier(jobId);
StageDao stageDao = mock(StageDao.class);
Stage stage = StageMother.custom("stage");
when(stageDao.findStageWithIdentifier(jobId.getStageIdentifier())).thenReturn(stage);
StageService service = new StageService(stageDao, jobInstanceService, null, null, null, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache, listener);
service.cancelJob(job);
verify(listener).stageStatusChanged(stage);
}
use of com.thoughtworks.go.server.dao.StageDao in project gocd by gocd.
the class StageServiceIntegrationTest method shouldNotNotifyListenersWhenJobCancellationTransactionRollsback.
@Test
public void shouldNotNotifyListenersWhenJobCancellationTransactionRollsback() {
StageStatusListener listener = mock(StageStatusListener.class);
JobInstanceService jobInstanceService = mock(JobInstanceService.class);
JobInstance job = JobInstanceMother.building("foo");
doThrow(new RuntimeException("test exception")).when(jobInstanceService).cancelJob(job);
JobIdentifier jobId = new JobIdentifier("pipeline", 10, "label-10", "stage", "1", "foo");
job.setIdentifier(jobId);
StageDao stageDao = mock(StageDao.class);
Stage stage = StageMother.custom("stage");
when(stageDao.findStageWithIdentifier(jobId.getStageIdentifier())).thenReturn(stage);
StageService service = new StageService(stageDao, jobInstanceService, null, null, null, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache, listener);
try {
service.cancelJob(job);
fail("should have thrown up when underlying service bombed");
} catch (Exception e) {
assertThat(e.getMessage(), is("test exception"));
}
verify(listener, never()).stageStatusChanged(any(Stage.class));
}
use of com.thoughtworks.go.server.dao.StageDao in project gocd by gocd.
the class StageStatusCacheTest method shouldQueryTheDbOnlyOnceForStagesThatHaveNeverBeenBuilt.
@Test
public void shouldQueryTheDbOnlyOnceForStagesThatHaveNeverBeenBuilt() throws SQLException {
final StageDao stageDao = Mockito.mock(StageDao.class);
final StageConfigIdentifier identifier = new StageConfigIdentifier("cruise", "dev");
StageStatusCache cache = new StageStatusCache(stageDao);
when(stageDao.mostRecentStage(identifier)).thenReturn(null);
assertThat(cache.currentStage(identifier), is(nullValue()));
assertThat(cache.currentStage(identifier), is(nullValue()));
verify(stageDao, times(1)).mostRecentStage(identifier);
}
use of com.thoughtworks.go.server.dao.StageDao in project gocd by gocd.
the class JobStatusCacheTest method shouldRemoveTheNeverRunInstanceWhenTheJobRunsForTheFirstTime.
@Test
public void shouldRemoveTheNeverRunInstanceWhenTheJobRunsForTheFirstTime() {
StageDao dao = mock(StageDao.class);
when(dao.mostRecentJobsForStage("cruise", "dev")).thenReturn(new ArrayList<>());
JobStatusCache cache = new JobStatusCache(dao);
assertThat(cache.currentJobs(new JobConfigIdentifier("cruise", "dev", "linux-firefox")).isEmpty(), is(true));
JobInstance instance = jobInstance("linux-firefox");
cache.jobStatusChanged(instance);
assertThat(cache.currentJobs(new JobConfigIdentifier("cruise", "dev", "linux-firefox")).get(0), is(instance));
Mockito.verify(dao, times(1)).mostRecentJobsForStage("cruise", "dev");
}
use of com.thoughtworks.go.server.dao.StageDao in project gocd by gocd.
the class JobStatusCacheTest method shouldHitTheDatabaseOnlyOnceIfTheJobIsNeverScheduledEver.
@Test
public void shouldHitTheDatabaseOnlyOnceIfTheJobIsNeverScheduledEver() {
StageDao dao = mock(StageDao.class);
when(dao.mostRecentJobsForStage("cruise", "dev")).thenReturn(new ArrayList<>());
JobStatusCache cache = new JobStatusCache(dao);
assertThat(cache.currentJobs(new JobConfigIdentifier("cruise", "dev", "linux-firefox")).isEmpty(), is(true));
assertThat(cache.currentJobs(new JobConfigIdentifier("cruise", "dev", "linux-firefox")).isEmpty(), is(true));
Mockito.verify(dao, times(1)).mostRecentJobsForStage("cruise", "dev");
}
Aggregations