use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class ChangesetServiceIntegrationTest method shouldReturnModsOfItsOwnAndAllUpstreamPipelinesForTheGivenCounter.
@Test
public void shouldReturnModsOfItsOwnAndAllUpstreamPipelinesForTheGivenCounter() {
SvnMaterial svn = MaterialsMother.svnMaterial("http://svn");
PipelineConfig grandFatherPipeline = configHelper.addPipeline("granpa", "stage", svn.config(), "job");
DependencyMaterial parentDependencyMaterial = MaterialsMother.dependencyMaterial("granpa", "stage");
PipelineConfig upstreamPipeline = configHelper.addPipeline("upstream", "stage", git.config(), "job");
upstreamPipeline.addMaterialConfig(parentDependencyMaterial.config());
DependencyMaterial dependencyMaterial = MaterialsMother.dependencyMaterial("upstream", "stage");
pipelineConfigWithTwoMaterials.addMaterialConfig(dependencyMaterial.config());
pipelineConfigWithTwoMaterials.removeMaterialConfig(git.config());
Username username = new Username(new CaseInsensitiveString("user1"));
//Schedule grandfather
List<MaterialRevision> revisionsForGrandfather1 = new ArrayList<>();
addRevisionWith2Mods(revisionsForGrandfather1, svn);
Pipeline grandFatherOne = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), grandFatherPipeline, revisionsForGrandfather1);
//Schedule upstream
List<MaterialRevision> revisionsForUpstream1 = new ArrayList<>();
addRevisionWith2Mods(revisionsForUpstream1, git);
dbHelper.addDependencyRevisionModification(revisionsForUpstream1, parentDependencyMaterial, grandFatherOne);
Pipeline upstreamOne = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), upstreamPipeline, revisionsForUpstream1);
//Schedule downstream
List<MaterialRevision> revisionsForPipeline1 = new ArrayList<>();
addRevisionWith2Mods(revisionsForPipeline1, hg);
dbHelper.addDependencyRevisionModification(revisionsForPipeline1, dependencyMaterial, upstreamOne);
Pipeline pipelineOne = dbHelper.checkinRevisionsToBuild(new ManualBuild(username), pipelineConfigWithTwoMaterials, revisionsForPipeline1);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
List<MaterialRevision> actual = changesetService.revisionsBetween(CaseInsensitiveString.str(pipelineConfigWithTwoMaterials.name()), pipelineOne.getCounter(), pipelineOne.getCounter(), username, result, true, false);
List<MaterialRevision> expectedRevisions = groupByMaterial(revisionsForGrandfather1, revisionsForUpstream1, revisionsForPipeline1);
assertMaterialRevisions(expectedRevisions, actual);
assertThat(result.isSuccessful(), is(true));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class MaterialCheckerTest method shouldUseLatestPipelineInstanceForDependentPipelineGivenThePreviousRevision.
@Test
public void shouldUseLatestPipelineInstanceForDependentPipelineGivenThePreviousRevision() throws Exception {
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
Stage passedStage = StageMother.passedStageInstance("stage-name", "job-name", "pipeline-name");
MaterialRevisions materialRevisions = new MaterialRevisions();
Modification previous = new Modification("Unknown", "Unknown", null, passedStage.completedDate(), "pipeline-name/1/stage-name/0");
MaterialRevision previousRevision = revisions(dependencyMaterial, previous).getMaterialRevision(0);
when(materialRepository.findModificationsSince(dependencyMaterial, previousRevision)).thenReturn(Arrays.asList(new Modification(new Date(), "pipeline-name/2/stage-name/0", "MOCK_LABEL-12", null)));
MaterialRevisions revisionsSince = materialChecker.findRevisionsSince(materialRevisions, new Materials(dependencyMaterial), new MaterialRevisions(previousRevision), new MaterialRevisions());
assertThat(revisionsSince.getMaterialRevision(0).getRevision().getRevision(), is("pipeline-name/2/stage-name/0"));
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class DependencyMaterialUpdateNotifierTest method shouldUpdateMaterialOnStageChange.
@Test
public void shouldUpdateMaterialOnStageChange() {
Stage stage = StageMother.passedStageInstance("Stage1", "plan", "Pipeline1");
DependencyMaterial dependencyMaterial = MaterialsMother.dependencyMaterial(stage.getIdentifier().getPipelineName(), stage.getName());
Set<DependencyMaterialConfig> schedulableMaterialConfigs = new HashSet<>(Arrays.asList((DependencyMaterialConfig) dependencyMaterial.config()));
when(goConfigService.getSchedulableDependencyMaterials()).thenReturn(schedulableMaterialConfigs);
when(materialConfigConverter.toMaterial(dependencyMaterial.config())).thenReturn(dependencyMaterial);
notifier = new DependencyMaterialUpdateNotifier(goConfigService, materialConfigConverter, materialUpdateService, serverHealthService);
notifier.initialize();
notifier.stageStatusChanged(stage);
verify(materialUpdateService, times(2)).updateMaterial(dependencyMaterial);
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class DependencyMaterialUpdateNotifierTest method shouldNotUpdateMaterialUnlessStageResultIsPassedOnStageChange.
@Test
public void shouldNotUpdateMaterialUnlessStageResultIsPassedOnStageChange() {
Stage stage = StageMother.scheduledStage("Pipeline1", 1, "Stage1", 1, "buildName");
DependencyMaterial dependencyMaterial = MaterialsMother.dependencyMaterial(stage.getIdentifier().getPipelineName(), stage.getName());
Set<DependencyMaterialConfig> schedulableMaterialConfigs = new HashSet<>(Arrays.asList((DependencyMaterialConfig) dependencyMaterial.config()));
when(goConfigService.getSchedulableDependencyMaterials()).thenReturn(schedulableMaterialConfigs);
when(materialConfigConverter.toMaterial(dependencyMaterial.config())).thenReturn(dependencyMaterial);
notifier = new DependencyMaterialUpdateNotifier(goConfigService, materialConfigConverter, materialUpdateService, serverHealthService);
notifier.initialize();
notifier.stageStatusChanged(stage);
//updated only during initialization
verify(materialUpdateService, times(1)).updateMaterial(dependencyMaterial);
}
use of com.thoughtworks.go.config.materials.dependency.DependencyMaterial in project gocd by gocd.
the class DependencyMaterialUpdateNotifierTest method shouldRetryUpdatingMaterialsIfPreviouslyUpdatesFailed_OnMaterialUpdate.
@Test
public void shouldRetryUpdatingMaterialsIfPreviouslyUpdatesFailed_OnMaterialUpdate() {
Stage stage = StageMother.passedStageInstance("Stage1", "plan", "Pipeline1");
DependencyMaterial dependencyMaterial = MaterialsMother.dependencyMaterial(stage.getIdentifier().getPipelineName(), stage.getName());
Set<DependencyMaterialConfig> schedulableMaterialConfigs = new HashSet<>(Arrays.asList((DependencyMaterialConfig) dependencyMaterial.config()));
when(goConfigService.getSchedulableDependencyMaterials()).thenReturn(schedulableMaterialConfigs);
when(materialConfigConverter.toMaterial(dependencyMaterial.config())).thenReturn(dependencyMaterial);
when(materialUpdateService.updateMaterial(dependencyMaterial)).thenThrow(new RuntimeException("some error")).thenReturn(true);
notifier = new DependencyMaterialUpdateNotifier(goConfigService, materialConfigConverter, materialUpdateService, serverHealthService);
notifier.initialize();
notifier.onMaterialUpdate(dependencyMaterial);
verify(materialUpdateService, atMost(2)).updateMaterial(dependencyMaterial);
}
Aggregations