Search in sources :

Example 36 with HttpOperationResult

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));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Test(org.junit.jupiter.api.Test)

Example 37 with HttpOperationResult

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);
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Test(org.junit.jupiter.api.Test)

Example 38 with HttpOperationResult

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);
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult)

Example 39 with HttpOperationResult

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());
}
Also used : Pagination(com.thoughtworks.go.server.util.Pagination) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.jupiter.api.Test)

Example 40 with HttpOperationResult

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;
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) SvnTestRepo(com.thoughtworks.go.helper.SvnTestRepo) TransactionStatus(org.springframework.transaction.TransactionStatus) HgTestRepo(com.thoughtworks.go.helper.HgTestRepo) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) Filter(com.thoughtworks.go.config.materials.Filter) IgnoredFiles(com.thoughtworks.go.config.materials.IgnoredFiles) SvnCommand(com.thoughtworks.go.domain.materials.svn.SvnCommand) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)146 Test (org.junit.jupiter.api.Test)64 Test (org.junit.Test)53 Username (com.thoughtworks.go.server.domain.Username)34 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)23 TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)12 Pagination (com.thoughtworks.go.server.util.Pagination)7 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)6 StageStatusCache (com.thoughtworks.go.domain.activity.StageStatusCache)6 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)6 StageStatusTopic (com.thoughtworks.go.server.messaging.StageStatusTopic)6 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)5 AgentInstance (com.thoughtworks.go.domain.AgentInstance)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)4 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)4 NullStage (com.thoughtworks.go.domain.NullStage)4 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)4 PipelineStatusModel (com.thoughtworks.go.presentation.PipelineStatusModel)4 Stage (com.thoughtworks.go.domain.Stage)3