Search in sources :

Example 51 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class JobInstanceSqlMapDaoTest method createNewPipeline.

private Pipeline createNewPipeline(PipelineConfig pipelineConfig) {
    Pipeline pipeline = instanceFactory.createPipelineInstance(pipelineConfig, modifySomeFiles(pipelineConfig), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), "md5-test", new TimeProvider());
    dbHelper.savePipelineWithStagesAndMaterials(pipeline);
    return pipeline;
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider)

Example 52 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class JobInstanceSqlMapDaoTest method shouldLoadRerunOfCounterValueForScheduledBuilds.

@Test
public void shouldLoadRerunOfCounterValueForScheduledBuilds() {
    List<JobPlan> jobPlans = jobInstanceDao.orderedScheduledBuilds();
    assertThat(jobPlans.size(), is(2));
    assertThat(jobPlans.get(0).getIdentifier().getRerunOfCounter(), is(nullValue()));
    assertThat(jobPlans.get(1).getIdentifier().getRerunOfCounter(), is(nullValue()));
    dbHelper.passStage(savedStage);
    Stage stage = instanceFactory.createStageForRerunOfJobs(savedStage, a(JOB_NAME), schedulingContext, pipelineConfig.getStage(new CaseInsensitiveString(STAGE_NAME)), new TimeProvider(), "md5");
    dbHelper.saveStage(savedPipeline, stage, stage.getOrderId() + 1);
    jobPlans = jobInstanceDao.orderedScheduledBuilds();
    assertThat(jobPlans.size(), is(1));
    assertThat(jobPlans.get(0).getIdentifier().getRerunOfCounter(), is(savedStage.getCounter()));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Test(org.junit.Test)

Example 53 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class StageServiceIntegrationTest method shouldReturnStageWithSpecificCounter.

@Test
public void shouldReturnStageWithSpecificCounter() throws Exception {
    Stage firstStage = savedPipeline.getStages().first();
    Stage newInstance = instanceFactory.createStageInstance(pipelineConfig.first(), new DefaultSchedulingContext("anonymous"), md5, new TimeProvider());
    Stage newSavedStage = stageService.save(savedPipeline, newInstance);
    Stage latestStage = stageService.findStageWithIdentifier(new StageIdentifier(CaseInsensitiveString.str(pipelineConfig.name()), null, savedPipeline.getLabel(), firstStage.getName(), String.valueOf(newSavedStage.getCounter())));
    assertThat(latestStage, is(newSavedStage));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Test(org.junit.Test)

Example 54 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class StageServiceIntegrationTest method shouldIgnoreErrorsWhenNotifyingListenersDuringSave.

@Test
public void shouldIgnoreErrorsWhenNotifyingListenersDuringSave() throws Exception {
    List<StageStatusListener> original = new ArrayList<>(stageService.getStageStatusListeners());
    try {
        stageService.getStageStatusListeners().clear();
        StageStatusListener failingListener = mock(StageStatusListener.class);
        doThrow(new RuntimeException("Should not be rethrown by save")).when(failingListener).stageStatusChanged(any(Stage.class));
        StageStatusListener passingListener = mock(StageStatusListener.class);
        stageService.getStageStatusListeners().add(failingListener);
        stageService.getStageStatusListeners().add(passingListener);
        Stage newInstance = instanceFactory.createStageInstance(pipelineConfig.first(), new DefaultSchedulingContext("anonumous"), md5, new TimeProvider());
        Stage savedStage = stageService.save(savedPipeline, newInstance);
        assertThat("Got: " + savedStage.getId(), savedStage.getId() > 0L, is(true));
        verify(passingListener).stageStatusChanged(any(Stage.class));
    } finally {
        stageService.getStageStatusListeners().clear();
        stageService.getStageStatusListeners().addAll(original);
    }
}
Also used : StageStatusListener(com.thoughtworks.go.server.domain.StageStatusListener) TimeProvider(com.thoughtworks.go.util.TimeProvider) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 55 with TimeProvider

use of com.thoughtworks.go.util.TimeProvider in project gocd by gocd.

the class StageServiceIntegrationTest method shouldSaveStageWithStateBuilding.

@Test
public void shouldSaveStageWithStateBuilding() throws Exception {
    Stage stage = instanceFactory.createStageInstance(pipelineConfig.first(), new DefaultSchedulingContext("anonumous"), md5, new TimeProvider());
    stageService.save(savedPipeline, stage);
    Stage latestStage = stageService.findLatestStage(CaseInsensitiveString.str(pipelineConfig.name()), CaseInsensitiveString.str(pipelineConfig.first().name()));
    assertThat(latestStage.getState(), is(StageState.Building));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Test(org.junit.Test)

Aggregations

TimeProvider (com.thoughtworks.go.util.TimeProvider)137 Test (org.junit.Test)91 Date (java.util.Date)23 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)22 DateTime (org.joda.time.DateTime)17 GoConfigRevision (com.thoughtworks.go.domain.GoConfigRevision)13 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)11 DefaultSchedulingContext (com.thoughtworks.go.domain.DefaultSchedulingContext)11 Before (org.junit.Before)11 Username (com.thoughtworks.go.server.domain.Username)10 Pipeline (com.thoughtworks.go.domain.Pipeline)9 PipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels)9 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)8 Stage (com.thoughtworks.go.domain.Stage)7 TransactionStatus (org.springframework.transaction.TransactionStatus)7 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)6 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)6 Material (com.thoughtworks.go.domain.materials.Material)5 TestingMaterial (com.thoughtworks.go.domain.materials.TestingMaterial)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5