use of com.thoughtworks.go.server.transaction.TransactionSynchronizationManager in project gocd by gocd.
the class StageServiceTest method canGetFailureRunForThreeStages.
@Test
public void canGetFailureRunForThreeStages() {
TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
StageRunFinder runFinder = new StageService(stageDao, jobInstanceService, mock(StageStatusTopic.class), mock(StageStatusCache.class), securityService, pipelineDao, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
List<StageIdentifier> expectedStages = new ArrayList<>();
expectedStages.add(new StageIdentifier(PIPELINE_NAME, 3, STAGE_NAME, "1"));
expectedStages.add(new StageIdentifier(PIPELINE_NAME, 2, STAGE_NAME, "2"));
expectedStages.add(new StageIdentifier(PIPELINE_NAME, 1, STAGE_NAME, "1"));
Pipeline pipeline = pipeline(10.0);
Pipeline pipelineThatLastPassed = pipeline(5.0);
when(pipelineDao.findPipelineByNameAndCounter(PIPELINE_NAME, 3)).thenReturn(pipeline);
when(pipelineDao.findEarlierPipelineThatPassedForStage(PIPELINE_NAME, STAGE_NAME, 10.0)).thenReturn(pipelineThatLastPassed);
when(stageDao.findFailedStagesBetween(PIPELINE_NAME, STAGE_NAME, 5.0, 10.0)).thenReturn(asList(identifier(3, "1"), identifier(2, "2"), identifier(1, "1")));
assertEquals(expectedStages, runFinder.findRunForStage(new StageIdentifier(PIPELINE_NAME, 3, STAGE_NAME, "1")));
}
use of com.thoughtworks.go.server.transaction.TransactionSynchronizationManager in project gocd by gocd.
the class StageServiceTest method findStageSummaryByIdentifierShouldRespondWith404WhenStagesHavingGivenCounterIsNotFound.
@Test
public void findStageSummaryByIdentifierShouldRespondWith404WhenStagesHavingGivenCounterIsNotFound() throws Exception {
SecurityService securityService = mock(SecurityService.class);
when(securityService.hasViewPermissionForPipeline(ALWAYS_ALLOW_USER, "dev")).thenReturn(true);
TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
StageService service = new StageService(stageDao, null, null, null, securityService, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
Stages stages = new Stages();
Stage stage1 = new Stage();
stage1.setIdentifier(new StageIdentifier("dev/10/stage_name/1"));
stages.add(stage1);
StageIdentifier stageId = new StageIdentifier("dev/10/stage_name/9999999999");
when(stageDao.getAllRunsOfStageForPipelineInstance(stageId.getPipelineName(), stageId.getPipelineCounter(), stageId.getStageName())).thenReturn(stages);
StageSummaryModel model = service.findStageSummaryByIdentifier(stageId, ALWAYS_ALLOW_USER, result);
assertThat(model, is(nullValue()));
assertThat(result.httpCode(), is(404));
}
use of com.thoughtworks.go.server.transaction.TransactionSynchronizationManager in project gocd by gocd.
the class StageServiceTest method shouldUpdateJobInstanceAndStageOnCancellingJob.
@Test
public void shouldUpdateJobInstanceAndStageOnCancellingJob() throws SQLException {
JobInstance job = new JobInstance("job");
job.setIdentifier(new JobIdentifier("pipeline", 10, "label", STAGE_NAME, "5", "job"));
TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
StageService service = new StageService(stageDao, jobInstanceService, null, null, null, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
JobInstance foundJob = new JobInstance("job");
foundJob.setState(JobState.Scheduled);
foundJob.setResult(JobResult.Unknown);
JobInstances foundJobInstances = new JobInstances(foundJob);
Stage foundStage = new Stage(STAGE_NAME, foundJobInstances, "jez", "manual", new TimeProvider());
foundStage.calculateResult();
assertThat(foundStage.getState(), is(not(StageState.Cancelled)));
assertThat(foundStage.getResult(), is(not(StageResult.Cancelled)));
foundJob.setState(JobState.Completed);
foundJob.setResult(JobResult.Cancelled);
when(stageDao.findStageWithIdentifier(job.getIdentifier().getStageIdentifier())).thenReturn(foundStage);
service.cancelJob(job);
assertThat(foundStage.getState(), is(StageState.Cancelled));
assertThat(foundStage.getResult(), is(StageResult.Cancelled));
verify(jobInstanceService).cancelJob(job);
verify(stageDao).updateResult(foundStage, StageResult.Cancelled);
}
Aggregations