use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class JobRerunScheduleServiceTest method shouldReturnNullWhenThereIsNoFailedJobsInStage.
@Test
void shouldReturnNullWhenThereIsNoFailedJobsInStage() {
Stage stage = mock(Stage.class);
HttpOperationResult result = new HttpOperationResult();
when(stage.getIdentifier()).thenReturn(new StageIdentifier("up42/1/stage1/1"));
when(stage.jobsWithResult(JobResult.Cancelled, JobResult.Failed)).thenReturn(new JobInstances());
ScheduleService scheduleServiceSpy = spy(service);
scheduleServiceSpy.rerunFailedJobs(stage, result);
assertThat(result.httpCode()).isEqualTo(400);
assertThat(result.message()).isEqualTo("There are no failed jobs in the stage that could be re-run");
verify(scheduleServiceSpy, never()).rerunJobs(any(Stage.class), anyList(), any(HttpOperationResult.class));
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class JobRerunScheduleServiceTest method shouldRerunFailedJobs.
@Test
void shouldRerunFailedJobs() {
Stage stage = mock(Stage.class);
HttpOperationResult result = new HttpOperationResult();
when(stage.getIdentifier()).thenReturn(new StageIdentifier("up42/1/stage1/1"));
when(stage.jobsWithResult(JobResult.Cancelled, JobResult.Failed)).thenReturn(new JobInstances(new JobInstance("job1")));
ScheduleService scheduleServiceSpy = spy(service);
scheduleServiceSpy.rerunFailedJobs(stage, result);
verify(scheduleServiceSpy).rerunJobs(stage, Arrays.asList("job1"), result);
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class JobRerunScheduleServiceTest method assertScheduleFailure.
private void assertScheduleFailure(String jobName, Stage oldStage, String failureMessage, int statusCode) {
HttpOperationResult result = new HttpOperationResult();
Stage stage = service.rerunJobs(oldStage, a(jobName), result);
assertThat(stage).isNull();
assertThat(result.message()).isEqualTo(failureMessage);
assertThat(result.httpCode()).isEqualTo(statusCode);
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class JobInstanceServiceTest method shouldDelegateToDAO_findJobHistoryPage.
@Test
public void shouldDelegateToDAO_findJobHistoryPage() {
when(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipeline"))).thenReturn(true);
when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
when(securityService.hasViewPermissionForPipeline(Username.valueOf("looser"), "pipeline")).thenReturn(true);
final JobInstanceService jobService = new JobInstanceService(jobInstanceDao, topic, jobStatusCache, transactionTemplate, transactionSynchronizationManager, null, null, goConfigService, securityService, serverHealthService);
Pagination pagination = Pagination.pageStartingAt(1, 1, 1);
jobService.findJobHistoryPage("pipeline", "stage", "job", pagination, "looser", new HttpOperationResult());
verify(jobInstanceDao).findJobHistoryPage("pipeline", "stage", "job", pagination.getPageSize(), pagination.getOffset());
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class BuildCauseProducerServiceIntegrationTest method setup.
@BeforeEach
public void setup(@TempDir Path tempDir) throws Exception {
diskSpaceSimulator = new DiskSpaceSimulator();
new HgTestRepo("testHgRepo", tempDir);
svnRepository = new SvnTestRepo(tempDir);
dbHelper.onSetUp();
configHelper.usingCruiseConfigDao(goConfigDao);
configHelper.onSetUp();
repository = new SvnCommand(null, svnRepository.projectRepositoryUrl());
configHelper.addPipeline(GO_PIPELINE_UPSTREAM, STAGE_NAME, new MaterialConfigs(git("foo-bar")), "unit");
goPipelineConfig = configHelper.addPipeline(GO_PIPELINE_NAME, STAGE_NAME, repository, "unit");
svnMaterialRevs = new MaterialRevisions();
svnMaterial = new SvnMaterial(repository);
svnMaterialRevs.addRevision(svnMaterial, svnMaterial.latestModification(null, new ServerSubprocessExecutionContext(goConfigService, new SystemEnvironment())));
final MaterialRevisions materialRevisions = new MaterialRevisions();
SvnMaterial anotherSvnMaterial = new SvnMaterial(repository);
materialRevisions.addRevision(anotherSvnMaterial, anotherSvnMaterial.latestModification(null, subprocessExecutionContext));
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
materialRepository.save(svnMaterialRevs);
}
});
BuildCause buildCause = BuildCause.createWithModifications(svnMaterialRevs, "");
mingleConfig = configHelper.addPipeline(MINGLE_PIPELINE_NAME, STAGE_NAME, repository, new Filter(new IgnoredFiles("**/*.doc")), "unit", "functional");
latestPipeline = PipelineMother.schedule(this.mingleConfig, buildCause);
latestPipeline = pipelineDao.saveWithStages(latestPipeline);
dbHelper.passStage(latestPipeline.getStages().first());
pipelineScheduleQueue.clear();
result = new HttpOperationResult();
scheduleOptions = new ScheduleOptions();
u = new ScheduleTestUtil(transactionTemplate, materialRepository, dbHelper, configHelper);
materialForManualTriggerPipeline = u.wf(new SvnMaterial("svn", "username", "password", false), "folder1");
u.checkinInOrder(materialForManualTriggerPipeline, u.d(1), "s1");
manualTriggerPipeline = configHelper.addPipeline(UUID.randomUUID().toString(), STAGE_NAME, materialForManualTriggerPipeline.config(), "build");
username = Username.ANONYMOUS;
}
Aggregations