use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.
the class AutoBuildCauseTest method shouldUseTheMaterialRevisionsAfterGettingTheRightVersionsBasedOnDependency.
@Test
public void shouldUseTheMaterialRevisionsAfterGettingTheRightVersionsBasedOnDependency() 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);
MaterialRevisions expectedRevisions = createHgMaterialWithMultipleRevisions(1, oneModifiedFile("1"));
expectedRevisions.addRevision(dependencyRevision);
when(goConfigService.upstreamDependencyGraphOf(targetPipeline, cruiseConfig)).thenReturn(dependencyGraph);
when(pipelineService.getRevisionsBasedOnDependencies(eq(revisions), eq(cruiseConfig), eq(dependencyGraph.getCurrent().name()))).thenReturn(expectedRevisions);
BuildCause buildCause = new AutoBuild(goConfigService, pipelineService, targetPipeline, new SystemEnvironment(), materialChecker).onModifications(revisions, false, null);
MaterialRevision expected = expectedRevisions.getMaterialRevision(0);
assertThat(buildCause.getMaterialRevisions().getMaterialRevision(0), is(expected));
}
use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.
the class AutoBuildCauseTest method shouldReturnCorrectRevisionsIfUpstreamIgnoresAllTheModificationsAndFirstOrderMaterialNotChanged.
@Test
public void shouldReturnCorrectRevisionsIfUpstreamIgnoresAllTheModificationsAndFirstOrderMaterialNotChanged() throws Exception {
PipelineConfigDependencyGraph dependencyGraph = dependencyGraphOfDepthOne(MaterialConfigsMother.hgMaterialConfig(), MaterialConfigsMother.svnMaterialConfig());
String targetPipeline = dependencyGraph.getCurrent().name().toLower();
firstHgMaterial(dependencyGraph).setFilter(new Filter(new IgnoredFiles("**/*.xml")));
MaterialRevisions revisions = createHgMaterialWithMultipleRevisions(1, oneModifiedFile("2"));
MaterialRevisions firstOrderRevision = createSvnMaterialWithMultipleRevisions(1, oneModifiedFile("2"));
MaterialRevision dependencyRevision = dependencyMaterialRevision("up1", 1, "label", "first", 1, new Date());
revisions.addAll(firstOrderRevision);
revisions.addRevision(dependencyRevision);
dependencyRevision.markAsNotChanged();
firstOrderRevision.getMaterialRevision(0).markAsNotChanged();
revisions.getMaterialRevision(0).markAsChanged();
MaterialRevisions expectedRevisions = createHgMaterialWithMultipleRevisions(1, oneModifiedFile("2"));
expectedRevisions.addRevision(dependencyRevision);
when(goConfigService.upstreamDependencyGraphOf(targetPipeline, cruiseConfig)).thenReturn(dependencyGraph);
when(pipelineService.getRevisionsBasedOnDependencies(eq(revisions), eq(cruiseConfig), eq(dependencyGraph.getCurrent().name()))).thenReturn(expectedRevisions);
assertThat(new AutoBuild(goConfigService, pipelineService, targetPipeline, new SystemEnvironment(), materialChecker).onModifications(revisions, false, null).getMaterialRevisions(), is(expectedRevisions));
}
use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.
the class AutoBuildCauseTest method shouldThrowExceptionIfNoChanges.
@Test
public void shouldThrowExceptionIfNoChanges() throws Exception {
MaterialRevisions modifications = new MaterialRevisions();
try {
new AutoBuild(goConfigService, pipelineService, "foo", new SystemEnvironment(), materialChecker).onModifications(modifications, false, null);
Assert.fail("Should throw Exception");
} catch (Exception e) {
}
}
use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.
the class AutoBuildCauseTest method shouldSetApproverToCruiseForTheProducedBuildCause.
@Test
public void shouldSetApproverToCruiseForTheProducedBuildCause() throws Exception {
SvnMaterial material = new SvnMaterial("http://foo.bar/baz", "user", "pass", false);
MaterialRevisions materialRevisions = new MaterialRevisions(new MaterialRevision(material, new Modification(new Date(), "1234", "MOCK_LABEL-12", null)));
when(goConfigService.upstreamDependencyGraphOf("foo", cruiseConfig)).thenReturn(new PipelineConfigDependencyGraph(null));
when(pipelineService.getRevisionsBasedOnDependencies(materialRevisions, cruiseConfig, new CaseInsensitiveString("foo"))).thenReturn(materialRevisions);
BuildCause buildCause = new AutoBuild(goConfigService, pipelineService, "foo", new SystemEnvironment(), materialChecker).onModifications(materialRevisions, false, null);
assertThat(buildCause.getApprover(), is(GoConstants.DEFAULT_APPROVED_BY));
}
use of com.thoughtworks.go.util.SystemEnvironment in project gocd by gocd.
the class BuildCauseProducerServiceTest method shouldHandleNoModificationExceptionThrownByAutoBuild.
@Test
public void shouldHandleNoModificationExceptionThrownByAutoBuild() {
String pipelineName = "pipeline";
ServerHealthStateOperationResult result = new ServerHealthStateOperationResult();
PipelineConfig config = PipelineConfigMother.pipelineConfig(pipelineName);
Material svnMaterial = MaterialsMother.defaultMaterials().get(0);
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("up"), new CaseInsensitiveString("s1"));
config.materialConfigs().clear();
config.addMaterialConfig(svnMaterial.config());
config.addMaterialConfig(dependencyMaterial.config());
when(pipelineService.getRevisionsBasedOnDependencies(Matchers.<MaterialRevisions>any(), Matchers.<BasicCruiseConfig>any(), Matchers.<CaseInsensitiveString>any())).thenThrow(new NoModificationsPresentForDependentMaterialException("P/1/S/1"));
when(pipelineScheduleQueue.mostRecentScheduled(pipelineName)).thenReturn(BuildCause.createNeverRun());
Modification modification = ModificationsMother.checkinWithComment("r", "c", new Date(), "f1");
when(materialRepository.findLatestModification(svnMaterial)).thenReturn(ModificationsMother.createSvnMaterialWithMultipleRevisions(1, modification));
when(materialRepository.findLatestModification(dependencyMaterial)).thenReturn(new MaterialRevisions(ModificationsMother.changedDependencyMaterialRevision("up", 1, "1", "s", 1, new Date())));
when(specificMaterialRevisionFactory.create(Matchers.<String>any(), Matchers.<Map<String, String>>any())).thenReturn(MaterialRevisions.EMPTY);
when(goConfigService.upstreamDependencyGraphOf(Matchers.<String>any(), Matchers.<BasicCruiseConfig>any())).thenReturn(new PipelineConfigDependencyGraph(config));
MaterialConfigs knownMaterialConfigs = new MaterialConfigs(svnMaterial.config(), dependencyMaterial.config());
Materials materials = new Materials(svnMaterial, dependencyMaterial);
when(materialConfigConverter.toMaterials(config.materialConfigs())).thenReturn(materials);
when(materialExpansionService.expandMaterialConfigsForScheduling(config.materialConfigs())).thenReturn(knownMaterialConfigs);
when(materialConfigConverter.toMaterials(knownMaterialConfigs)).thenReturn(materials);
AutoBuild autoBuild = new AutoBuild(goConfigService, pipelineService, pipelineName, new SystemEnvironment(), null);
ServerHealthState serverHealthState = buildCauseProducerService.newProduceBuildCause(config, autoBuild, result, 12345);
assertThat(serverHealthState.isSuccess(), is(true));
}
Aggregations