Search in sources :

Example 1 with TimeProvider

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

the class ConfigRepositoryTest method shouldBeAbleToCheckin.

@Test
public void shouldBeAbleToCheckin() throws Exception {
    configRepo.checkin(new GoConfigRevision("v1", "md5-v1", "user-name", "100.3.9", new TimeProvider()));
    configRepo.checkin(new GoConfigRevision("v1 v2", "md5-v2", "user-name", "100.9.8", new TimeProvider()));
    assertThat(configRepo.getRevision("md5-v1").getContent(), is("v1"));
    assertThat(configRepo.getRevision("md5-v2").getContent(), is("v1 v2"));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) Test(org.junit.Test)

Example 2 with TimeProvider

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

the class ConfigRepositoryTest method shouldRemoveUnwantedDataFromDiff.

@Test
public void shouldRemoveUnwantedDataFromDiff() throws Exception {
    configRepo.checkin(goConfigRevision(ConfigFileFixture.configWithPipeline(ConfigFileFixture.SIMPLE_PIPELINE, 33), "md5-1"));
    String configXml = ConfigFileFixture.configWithPipeline(ConfigFileFixture.SIMPLE_PIPELINE, 60);
    configRepo.checkin(new GoConfigRevision(configXml, "md5-2", "user-2", "13.2", new TimeProvider()));
    String configChangesLine1 = "-<cruise schemaVersion='33'>";
    String configChangesLine2 = "+<cruise schemaVersion='60'>";
    String actual = configRepo.configChangesFor("md5-2", "md5-1");
    assertThat(actual, containsString(configChangesLine1));
    assertThat(actual, containsString(configChangesLine2));
    assertThat(actual, not(containsString("--- a/cruise-config.xml")));
    assertThat(actual, not(containsString("+++ b/cruise-config.xml")));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) Test(org.junit.Test)

Example 3 with TimeProvider

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

the class ConfigRepositoryTest method shouldGetCommitsCorrectly.

@Test
public void shouldGetCommitsCorrectly() throws Exception {
    configRepo.checkin(new GoConfigRevision("v1", "md5-v1", "user-name", "100.3.9", new TimeProvider()));
    configRepo.checkin(new GoConfigRevision("v2", "md5-v2", "user-name", "100.3.9", new TimeProvider()));
    configRepo.checkin(new GoConfigRevision("v3", "md5-v3", "user-name", "100.3.9", new TimeProvider()));
    configRepo.checkin(new GoConfigRevision("v4", "md5-v4", "user-name", "100.3.9", new TimeProvider()));
    GoConfigRevisions goConfigRevisions = configRepo.getCommits(3, 0);
    assertThat(goConfigRevisions.size(), is(3));
    assertThat(goConfigRevisions.get(0).getContent(), is(nullValue()));
    assertThat(goConfigRevisions.get(0).getMd5(), is("md5-v4"));
    assertThat(goConfigRevisions.get(1).getMd5(), is("md5-v3"));
    assertThat(goConfigRevisions.get(2).getMd5(), is("md5-v2"));
    goConfigRevisions = configRepo.getCommits(3, 3);
    assertThat(goConfigRevisions.size(), is(1));
    assertThat(goConfigRevisions.get(0).getMd5(), is("md5-v1"));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) GoConfigRevisions(com.thoughtworks.go.GoConfigRevisions) Test(org.junit.Test)

Example 4 with TimeProvider

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

the class ConfigRepositoryTest method shouldNotCommitWhenNothingChanged.

@Test
public void shouldNotCommitWhenNothingChanged() throws Exception {
    configRepo.checkin(new GoConfigRevision("v1", "md5-v1", "user-name", "100.3.9", new TimeProvider()));
    //md5 is solely trusted
    configRepo.checkin(new GoConfigRevision("v1 v2", "md5-v1", "loser-name", "501.9.8", new TimeProvider()));
    Iterator<RevCommit> commitIterator = configRepo.revisions().iterator();
    int size = 0;
    while (commitIterator.hasNext()) {
        size++;
        commitIterator.next();
    }
    assertThat(size, is(1));
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 5 with TimeProvider

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

the class RescheduleJobTest method shouldRescheduleBuildAlongWithAssociatedEntitiesCorrectly.

@Test
public void shouldRescheduleBuildAlongWithAssociatedEntitiesCorrectly() throws Exception {
    dbHelper.cancelStage(stage);
    Resources resources = new Resources(new Resource("r1"), new Resource("r2"));
    ArtifactPlans artifactPlans = new ArtifactPlans(Arrays.asList(new ArtifactPlan("s1", "d1"), new ArtifactPlan("s2", "d2")));
    ArtifactPropertiesGenerators artifactPropertiesGenerators = new ArtifactPropertiesGenerators(new ArtifactPropertiesGenerator("n1", "s1", "x1"), new ArtifactPropertiesGenerator("n2", "s2", "x2"));
    configHelper.addAssociatedEntitiesForAJob(PIPELINE_NAME, STAGE_NAME, JOB_NAME, resources, artifactPlans, artifactPropertiesGenerators);
    dbHelper.schedulePipeline(configHelper.currentConfig().getPipelineConfigByName(new CaseInsensitiveString(PIPELINE_NAME)), new TimeProvider());
    JobPlan oldJobPlan = dbHelper.getBuildInstanceDao().orderedScheduledBuilds().get(0);
    assertThat(oldJobPlan.getResources().size(), is(2));
    assertThat(oldJobPlan.getArtifactPlans().size(), is(2));
    assertThat(oldJobPlan.getPropertyGenerators().size(), is(2));
    JobInstance oldJobInstance = dbHelper.getBuildInstanceDao().buildById(oldJobPlan.getJobId());
    scheduleService.rescheduleJob(oldJobInstance);
    JobInstance reloadedOldJobInstance = dbHelper.getBuildInstanceDao().buildById(oldJobInstance.getId());
    assertThat(reloadedOldJobInstance.isIgnored(), is(true));
    assertThat(reloadedOldJobInstance.getState(), is(JobState.Rescheduled));
    JobPlan newJobPlan = dbHelper.getBuildInstanceDao().orderedScheduledBuilds().get(1);
    assertThat(newJobPlan.getJobId(), is(not(oldJobInstance.getId())));
    assertThat(newJobPlan.getResources().size(), is(2));
    for (int i = 0; i < newJobPlan.getResources().size(); i++) {
        Resource newResource = newJobPlan.getResources().get(i);
        Resource oldResource = oldJobPlan.getResources().get(i);
        assertThat(newResource.getId(), is(not(oldResource.getId())));
        assertThat(newResource.getName(), is(oldResource.getName()));
        assertThat(ReflectionUtil.getField(newResource, "buildId"), is(newJobPlan.getJobId()));
    }
    assertThat(newJobPlan.getArtifactPlans().size(), is(2));
    for (int i = 0; i < newJobPlan.getArtifactPlans().size(); i++) {
        ArtifactPlan newArtifactPlan = newJobPlan.getArtifactPlans().get(i);
        ArtifactPlan oldArtifactPlan = oldJobPlan.getArtifactPlans().get(i);
        assertThat(newArtifactPlan.getId(), is(not(oldArtifactPlan.getId())));
        assertThat(newArtifactPlan.getArtifactType(), is(oldArtifactPlan.getArtifactType()));
        assertThat(newArtifactPlan.getSrc(), is(oldArtifactPlan.getSrc()));
        assertThat(newArtifactPlan.getDest(), is(oldArtifactPlan.getDest()));
        assertThat(newArtifactPlan.getArtifactType(), is(oldArtifactPlan.getArtifactType()));
        assertThat(ReflectionUtil.getField(newArtifactPlan, "buildId"), is(newJobPlan.getJobId()));
    }
    assertThat(newJobPlan.getPropertyGenerators().size(), is(2));
    for (int i = 0; i < newJobPlan.getPropertyGenerators().size(); i++) {
        ArtifactPropertiesGenerator newArtifactPropertiesGenerator = newJobPlan.getPropertyGenerators().get(i);
        ArtifactPropertiesGenerator oldArtifactPropertiesGenerator = oldJobPlan.getPropertyGenerators().get(i);
        assertThat(newArtifactPropertiesGenerator.getId(), is(not(oldArtifactPropertiesGenerator.getId())));
        assertThat(newArtifactPropertiesGenerator.getName(), is(oldArtifactPropertiesGenerator.getName()));
        assertThat(newArtifactPropertiesGenerator.getSrc(), is(oldArtifactPropertiesGenerator.getSrc()));
        assertThat(newArtifactPropertiesGenerator.getXpath(), is(oldArtifactPropertiesGenerator.getXpath()));
        assertThat(ReflectionUtil.getField(newArtifactPropertiesGenerator, "jobId"), is(newJobPlan.getJobId()));
    }
    JobInstance newJobInstance = dbHelper.getBuildInstanceDao().buildById(newJobPlan.getJobId());
    assertThat(newJobInstance.getState(), is(JobState.Scheduled));
}
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