use of com.thoughtworks.go.domain.MaterialRevision in project gocd by gocd.
the class MaterialCheckerTest method shouldUseLatestMaterialDuringCreationOfNewRevisionsSince_bug7486.
@Test
public void shouldUseLatestMaterialDuringCreationOfNewRevisionsSince_bug7486() throws Exception {
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
PackageMaterial oldPkgMaterial = MaterialsMother.packageMaterial("repo-id", "repo-old-name", "pkg-id", "pkg-old-name", ConfigurationPropertyMother.create("key", false, "value"));
Stage passedStage = StageMother.passedStageInstance("stage-name", "job-name", "pipeline-name");
MaterialRevision previousDependantRevision = new MaterialRevision(dependencyMaterial, new Modification("Unknown", "Unknown", null, passedStage.completedDate(), "pipeline-name/1[LABEL-1]/stage-name/0"));
Modification dependencyModification = new Modification("Unknown", "Unknown", null, passedStage.completedDate(), "pipeline-name/2[LABEL-2]/stage-name/0");
Modification oldPkgMod = mod(1L);
MaterialRevision previousPkgRevision = new MaterialRevision(oldPkgMaterial, oldPkgMod);
PackageMaterial newPkgMaterial = MaterialsMother.packageMaterial("repo-id", "repo-new-name", "pkg-id", "pkg-new-name", ConfigurationPropertyMother.create("key", false, "value"));
Modification newPkgMod = mod(2L);
Mockito.when(materialRepository.findModificationsSince(oldPkgMaterial, previousPkgRevision)).thenReturn(modifications(newPkgMod));
MaterialRevisions alreadyFoundRevisions = new MaterialRevisions(new MaterialRevision(dependencyMaterial, dependencyModification));
// will not be used, as no new materials have appeared
MaterialRevisions latestRevisions = new MaterialRevisions();
MaterialRevisions revisionsSince = materialChecker.findRevisionsSince(alreadyFoundRevisions, new Materials(dependencyMaterial, newPkgMaterial), new MaterialRevisions(previousDependantRevision, previousPkgRevision), latestRevisions);
assertThat(revisionsSince, is(new MaterialRevisions(new MaterialRevision(dependencyMaterial, dependencyModification), new MaterialRevision(oldPkgMaterial, newPkgMod))));
// since name is not part of equals
assertThat(((PackageMaterial) revisionsSince.getMaterialRevision(1).getMaterial()).getPackageDefinition().getName(), is("pkg-new-name"));
assertThat(((PackageMaterial) revisionsSince.getMaterialRevision(1).getMaterial()).getPackageDefinition().getRepository().getName(), is("repo-new-name"));
Mockito.verify(materialRepository, never()).findLatestModification(dependencyMaterial);
Mockito.verify(materialRepository).findModificationsSince(oldPkgMaterial, previousPkgRevision);
}
use of com.thoughtworks.go.domain.MaterialRevision in project gocd by gocd.
the class MaterialServiceTest method shouldUnderstandIfMaterialHasModifications.
@Test
public void shouldUnderstandIfMaterialHasModifications() {
assertHasModifcation(new MaterialRevisions(new MaterialRevision(new HgMaterial("foo.com", null), new Modification(new Date(), "2", "MOCK_LABEL-12", null))), true);
assertHasModifcation(new MaterialRevisions(), false);
}
use of com.thoughtworks.go.domain.MaterialRevision in project gocd by gocd.
the class AutoBuildCauseTest method shouldNotFallbackToFanInOffTriangleDependencyBehaviourOnNoCompatibleUpstreamRevisionsException.
@Test
public void shouldNotFallbackToFanInOffTriangleDependencyBehaviourOnNoCompatibleUpstreamRevisionsException() throws Exception {
PipelineConfigDependencyGraph dependencyGraph = dependencyGraphOfDepthOne(MaterialConfigsMother.hgMaterialConfig());
String targetPipeline = dependencyGraph.getCurrent().name().toLower();
MaterialRevisions revisions = createHgMaterialWithMultipleRevisions(1, oneModifiedFile("2"));
MaterialRevision dependencyRevision = dependencyMaterialRevision("up1", 1, "label", "first", 1, new Date());
dependencyRevision.markAsChanged();
revisions.addRevision(dependencyRevision);
NoCompatibleUpstreamRevisionsException expectedException = NoCompatibleUpstreamRevisionsException.failedToFindCompatibleRevision(new CaseInsensitiveString("downstream"), null);
when(goConfigService.upstreamDependencyGraphOf(targetPipeline, cruiseConfig)).thenReturn(dependencyGraph);
when(pipelineService.getRevisionsBasedOnDependencies(eq(revisions), eq(cruiseConfig), eq(dependencyGraph.getCurrent().name()))).thenThrow(expectedException);
when(systemEnvironment.enforceRevisionCompatibilityWithUpstream()).thenReturn(true);
try {
new AutoBuild(goConfigService, pipelineService, targetPipeline, systemEnvironment, materialChecker).onModifications(revisions, false, null);
fail("should have thrown exception");
} catch (NoCompatibleUpstreamRevisionsException e) {
assertThat(e, is(expectedException));
}
}
use of com.thoughtworks.go.domain.MaterialRevision in project gocd by gocd.
the class AutoBuildCauseTest method shouldTurnOffFanInFallbackBehaviourWhenSystemEnvironmentVariableIsOff.
@Test
public void shouldTurnOffFanInFallbackBehaviourWhenSystemEnvironmentVariableIsOff() throws Exception {
PipelineConfigDependencyGraph dependencyGraph = dependencyGraphOfDepthOne(MaterialConfigsMother.hgMaterialConfig());
String targetPipeline = dependencyGraph.getCurrent().name().toLower();
MaterialRevisions revisions = createHgMaterialWithMultipleRevisions(1, oneModifiedFile("2"));
MaterialRevision dependencyRevision = dependencyMaterialRevision("up1", 1, "label", "first", 1, new Date());
dependencyRevision.markAsChanged();
revisions.addRevision(dependencyRevision);
RuntimeException expectedException = new RuntimeException("failed");
when(goConfigService.upstreamDependencyGraphOf(targetPipeline, cruiseConfig)).thenReturn(dependencyGraph);
when(pipelineService.getRevisionsBasedOnDependencies(eq(revisions), eq(cruiseConfig), eq(dependencyGraph.getCurrent().name()))).thenThrow(expectedException);
when(systemEnvironment.enforceRevisionCompatibilityWithUpstream()).thenReturn(true);
try {
new AutoBuild(goConfigService, pipelineService, targetPipeline, systemEnvironment, materialChecker).onModifications(revisions, false, null);
fail("should have thrown exception");
} catch (RuntimeException e) {
assertThat(e, is(expectedException));
}
}
use of com.thoughtworks.go.domain.MaterialRevision in project gocd by gocd.
the class AutoBuildCauseTest method shouldReturnPeggedRevisionsForUpstreamMaterialWhenFirstOrderDependencyMaterialIsChanged.
@Test
public void shouldReturnPeggedRevisionsForUpstreamMaterialWhenFirstOrderDependencyMaterialIsChanged() throws Exception {
HgMaterialConfig hg = MaterialConfigsMother.hgMaterialConfig();
PipelineConfig third = PipelineConfigMother.pipelineConfig("third", MaterialConfigsMother.dependencyMaterialConfig("second", "mingle"), new JobConfigs());
PipelineConfig second = PipelineConfigMother.pipelineConfig("second", MaterialConfigsMother.dependencyMaterialConfig("first", "mingle"), new JobConfigs());
PipelineConfig first = PipelineConfigMother.pipelineConfig("first", hg, new JobConfigs());
PipelineConfigDependencyGraph dependencyGraph = new PipelineConfigDependencyGraph(third, new PipelineConfigDependencyGraph(second, new PipelineConfigDependencyGraph(first)), new PipelineConfigDependencyGraph(first));
MaterialRevisions revisions = new MaterialRevisions();
MaterialRevision firstRev = dependencyMaterialRevision("first", 10, "label", "mingle", 1, new Date());
firstRev.markAsNotChanged();
MaterialRevision secondRev = dependencyMaterialRevision("second", 1, "label", "mingle", 1, new Date());
secondRev.markAsChanged();
revisions.addRevision(secondRev);
revisions.addRevision(firstRev);
when(goConfigService.upstreamDependencyGraphOf("third", cruiseConfig)).thenReturn(dependencyGraph);
MaterialRevisions expectedRevisions = new MaterialRevisions();
when(pipelineService.getRevisionsBasedOnDependencies(eq(revisions), eq(cruiseConfig), eq(dependencyGraph.getCurrent().name()))).thenReturn(expectedRevisions);
assertThat(new AutoBuild(goConfigService, pipelineService, "third", new SystemEnvironment(), materialChecker).onModifications(revisions, false, null).getMaterialRevisions(), sameInstance(expectedRevisions));
}
Aggregations