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"));
}
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")));
}
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"));
}
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));
}
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));
}
Aggregations