use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method shouldFixToAsFromForDependencyMaterialRevisionWhileSavingAndUpdating.
@Test
public void shouldFixToAsFromForDependencyMaterialRevisionWhileSavingAndUpdating() throws Exception {
Material material = new DependencyMaterial(new CaseInsensitiveString("pipeline_name"), new CaseInsensitiveString("stage_name"));
MaterialRevision firstRevision = new MaterialRevision(material, new Modifications(modification("pipeline_name/10/stage_name/1"), modification("pipeline_name/9/stage_name/2"), modification("pipeline_name/8/stage_name/2")));
saveMaterialRev(firstRevision);
Pipeline firstPipeline = createPipeline();
savePMR(firstRevision, firstPipeline);
MaterialRevisions revisionsFor11 = repo.findMaterialRevisionsForPipeline(firstPipeline.getId());
assertThat(revisionsFor11.getModifications(material).size(), is(1));
assertThat(revisionsFor11.getModifications(material).get(0).getRevision(), is("pipeline_name/10/stage_name/1"));
MaterialRevision secondRevision = new MaterialRevision(material, new Modifications(modification("pipeline_name/11/stage_name/2"), modification("pipeline_name/11/stage_name/1")));
saveMaterialRev(secondRevision);
Pipeline secondPipeline = createPipeline();
savePMR(secondRevision, secondPipeline);
MaterialRevisions revisionsFor12 = repo.findMaterialRevisionsForPipeline(secondPipeline.getId());
assertThat(revisionsFor12.getModifications(material).size(), is(1));
assertThat(revisionsFor12.getModifications(material).get(0).getRevision(), is("pipeline_name/11/stage_name/2"));
MaterialRevision thirdRevision = new MaterialRevision(material, new Modifications(modification("pipeline_name/12/stage_name/1")));
saveMaterialRev(thirdRevision);
Pipeline thirdPipeline = createPipeline();
savePMR(thirdRevision, thirdPipeline);
savePMR(thirdRevision, thirdPipeline);
MaterialRevisions revisionsFor13 = repo.findMaterialRevisionsForPipeline(thirdPipeline.getId());
assertThat(revisionsFor13.getModifications(material).size(), is(1));
assertThat(revisionsFor13.getModifications(material).get(0).getRevision(), is("pipeline_name/12/stage_name/1"));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method shouldMatchPipelineLabelForDependencyModifications.
@Test
public void shouldMatchPipelineLabelForDependencyModifications() throws Exception {
DependencyMaterial material = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
repo.saveOrUpdate(material.createMaterialInstance());
MaterialRevision first = saveOneDependencyModification(material, "pipeline-name/1/stage-name/3", "my-random-label-123");
MaterialRevision second = saveOneDependencyModification(material, "pipeline-name/3/stage-name/1", "other-label-456");
List<MatchedRevision> revisions = repo.findRevisionsMatching(material.config(), "my-random");
assertThat(revisions.size(), is(1));
assertMatchedRevision(revisions.get(0), first.getLatestShortRevision(), first.getLatestRevisionString(), null, first.getDateOfLatestModification(), "my-random-label-123");
revisions = repo.findRevisionsMatching(material.config(), "other-label");
assertThat(revisions.size(), is(1));
assertMatchedRevision(revisions.get(0), second.getLatestShortRevision(), second.getLatestRevisionString(), null, second.getDateOfLatestModification(), "other-label-456");
revisions = repo.findRevisionsMatching(material.config(), "something-else");
assertThat(revisions.size(), is(0));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method shouldUseTheFromIdAsActualFromIdWhenThePipelineIsBeingBuiltForTheFirstTime.
@Test
public void shouldUseTheFromIdAsActualFromIdWhenThePipelineIsBeingBuiltForTheFirstTime() throws Exception {
Material material = new DependencyMaterial(new CaseInsensitiveString("pipeline_name"), new CaseInsensitiveString("stage_name"));
Modification actualFrom = modification("pipeline_name/8/stage_name/2");
MaterialRevision firstRevision = new MaterialRevision(material, new Modifications(modification("pipeline_name/9/stage_name/2"), actualFrom));
saveMaterialRev(firstRevision);
HgMaterial hgMaterial = new HgMaterial("sdg", null);
MaterialRevision hgRevision = new MaterialRevision(hgMaterial, new Modifications(modification("10"), modification("9")));
saveMaterialRev(hgRevision);
Modification from = modification("pipeline_name/10/stage_name/1");
firstRevision = new MaterialRevision(material, new Modifications(from));
saveMaterialRev(firstRevision);
Pipeline firstPipeline = createPipeline();
savePMR(firstRevision, firstPipeline);
List<PipelineMaterialRevision> pmrs = repo.findPipelineMaterialRevisions(firstPipeline.getId());
assertThat(pmrs.get(0).getActualFromRevisionId(), is(from.getId()));
assertEquals(from, pmrs.get(0).getFromModification());
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class MaterialRepositoryIntegrationTest method hasPipelineEverRunWithMultipleMaterials.
@Test
public void hasPipelineEverRunWithMultipleMaterials() {
HgMaterial hgMaterial = MaterialsMother.hgMaterial("hgUrl", "dest");
MaterialRevision hgMaterialRevision = saveOneScmModification(hgMaterial, "user", "file");
DependencyMaterial depMaterial = new DependencyMaterial(new CaseInsensitiveString("blahPipeline"), new CaseInsensitiveString("blahStage"));
MaterialRevision depMaterialRevision = saveOneDependencyModification(depMaterial, "blahPipeline/1/blahStage/1");
PipelineConfig pipelineConfig = PipelineMother.createPipelineConfig("mingle", new MaterialConfigs(hgMaterial.config(), depMaterial.config()), "dev");
MaterialRevisions materialRevisions = new MaterialRevisions(hgMaterialRevision, depMaterialRevision);
Pipeline pipeline = instanceFactory.createPipelineInstance(pipelineConfig, BuildCause.createManualForced(materialRevisions, Username.ANONYMOUS), new DefaultSchedulingContext(DEFAULT_APPROVED_BY), md5, new TimeProvider());
pipelineSqlMapDao.save(pipeline);
MaterialRevisions revisions = new MaterialRevisions(new MaterialRevision(depMaterial, depMaterialRevision.getLatestModification()), new MaterialRevision(hgMaterial, hgMaterialRevision.getLatestModification()));
assertThat(repo.hasPipelineEverRunWith("mingle", revisions), is(true));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class MaterialRevisionBuilder method depInstance.
public Tuple depInstance(String pipelineName, int counter, Date modifiedTime, Tuple... buildCause) {
String key = key(pipelineName, counter, modifiedTime);
if (!instanceToRevision.containsKey(key)) {
if (buildCause.length == 0) {
throw new RuntimeException("Cannot create instance without a buildcause. You can retrive it without buildcause once it has been created");
}
DependencyMaterial material = new DependencyMaterial(new CaseInsensitiveString(pipelineName), new CaseInsensitiveString(STAGE_NAME));
DependencyMaterialRevision revision = DependencyMaterialRevision.create(pipelineName, counter, "label", STAGE_NAME, 1);
instanceToRevision.put(key, revision.convert(material, modifiedTime));
final long id = getNextId();
org.mockito.Mockito.when(pipelineDao.findPipelineByNameAndCounter(pipelineName, counter)).thenReturn(pipeline(id));
org.mockito.Mockito.when(materialRepository.findMaterialRevisionsForPipeline(id)).thenReturn(buildCauseOfThisPipeline(buildCause));
}
MaterialRevision materialRevision = instanceToRevision.get(key);
Materials materials = new Materials();
for (MaterialRevision revision : buildCauseOfThisPipeline(buildCause)) {
materials.add(revision.getMaterial());
}
PipelineConfig config = new PipelineConfig(new CaseInsensitiveString(pipelineName), materials.convertToConfigs(), new StageConfig(new CaseInsensitiveString(STAGE_NAME), new JobConfigs()));
return new Tuple(new PipelineConfigDependencyGraph(config, dependencyGraphsFor(buildCause)), materialRevision);
}
Aggregations