Search in sources :

Example 21 with TimeProvider

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

the class PipelineHistoryMother method stageHistory.

public static StageInstanceModels stageHistory(PipelineConfig pipelineConfig, Date modificationDate) {
    StageInstanceModels history = new StageInstanceModels();
    for (StageConfig stageConfig : pipelineConfig) {
        StageInstanceModel item = new StageInstanceModel(CaseInsensitiveString.str(stageConfig.name()), "1", buildHistory(stageConfig, modificationDate));
        item.setCounter("1");
        item.setApprovalType(new InstanceFactory().createStageInstance(stageConfig, new DefaultSchedulingContext("anyone"), md5, new TimeProvider()).getApprovalType());
        if (stageConfig.requiresApproval()) {
            item.setApprovedBy(APPROVED_BY);
        } else {
            item.setApprovedBy(GoConstants.DEFAULT_APPROVED_BY);
        }
        history.add(item);
    }
    return history;
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) InstanceFactory(com.thoughtworks.go.server.service.InstanceFactory) StageInstanceModels(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModels) StageInstanceModel(com.thoughtworks.go.presentation.pipelinehistory.StageInstanceModel) StageConfig(com.thoughtworks.go.config.StageConfig) DefaultSchedulingContext(com.thoughtworks.go.domain.DefaultSchedulingContext)

Example 22 with TimeProvider

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

the class ConfigMigrator method migrate.

public static GoConfigMigration migrate(final File configFile) {
    ConfigElementImplementationRegistry registry = ConfigElementImplementationRegistryMother.withNoPlugins();
    GoConfigMigration upgrader = new GoConfigMigration(new GoConfigMigration.UpgradeFailedHandler() {

        public void handle(Exception e) {
            String content = "";
            try {
                content = FileUtil.readContentFromFile(configFile);
            } catch (IOException e1) {
            }
            throw bomb(e.getMessage() + ": content=\n" + content + "\n" + (e.getCause() == null ? "" : e.getCause().getMessage()), e);
        }
    }, mock(ConfigRepository.class), new TimeProvider(), new ConfigCache(), registry);
    //TODO: LYH & GL GoConfigMigration should be able to handle stream instead of binding to file
    upgrader.upgradeIfNecessary(configFile, "N/A");
    return upgrader;
}
Also used : ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) TimeProvider(com.thoughtworks.go.util.TimeProvider) ConfigRepository(com.thoughtworks.go.service.ConfigRepository)

Example 23 with TimeProvider

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

the class GoConfigRevisionTest method shouldUnderstandEquality.

@Test
public void shouldUnderstandEquality() {
    GoConfigRevision rev1 = new GoConfigRevision("blah", "md5", "loser", "2.2.2", new TimeProvider());
    GoConfigRevision rev2 = new GoConfigRevision("blah blah", "md5", "loser 2", "2.2.3", new TimeProvider());
    assertThat(rev1, is(rev2));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Test(org.junit.Test)

Example 24 with TimeProvider

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

the class PipelineWithMultipleStages method scheduleAndCompleteFollowingStages.

protected void scheduleAndCompleteFollowingStages(Pipeline pipeline, JobResult result) {
    for (int index = 2; index <= stagesSize; index++) {
        StageConfig stageConfig = stageConfig(index);
        Stage instance = new InstanceFactory().createStageInstance(stageConfig, new DefaultSchedulingContext("anyone"), "md5-test", new TimeProvider());
        instance.setOrderId(index);
        dbHelper.getStageDao().saveWithJobs(pipeline, instance);
        dbHelper.completeStage(instance, result);
    }
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) InstanceFactory(com.thoughtworks.go.server.service.InstanceFactory) Stage(com.thoughtworks.go.domain.Stage) StageConfig(com.thoughtworks.go.config.StageConfig) DefaultSchedulingContext(com.thoughtworks.go.domain.DefaultSchedulingContext)

Example 25 with TimeProvider

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

the class PipelineWithRunOnAllJob method scheduleAndCompleteFollowingStages.

protected void scheduleAndCompleteFollowingStages(Pipeline pipeline, JobResult result) {
    Stage ft = new InstanceFactory().createStageInstance(ftStage(), new DefaultSchedulingContext("anyone"), "md5-test", new TimeProvider());
    ft.setOrderId(pipeline.getFirstStage().getOrderId() + 1);
    dbHelper.getStageDao().saveWithJobs(pipeline, ft);
    dbHelper.completeStage(ft, result);
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) InstanceFactory(com.thoughtworks.go.server.service.InstanceFactory) Stage(com.thoughtworks.go.domain.Stage) DefaultSchedulingContext(com.thoughtworks.go.domain.DefaultSchedulingContext)

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