use of com.thoughtworks.go.config.materials.Materials in project gocd by gocd.
the class MaterialCheckerTest method shouldSkipFindingRevisionsSinceForMaterialsThatWereAlreadyChecked.
@Test
public void shouldSkipFindingRevisionsSinceForMaterialsThatWereAlreadyChecked() throws Exception {
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("pipeline-name"), new CaseInsensitiveString("stage-name"));
SvnMaterial svnMaterial = new SvnMaterial("svnUrl", null, null, false);
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");
MaterialRevision previousSvnRevision = new MaterialRevision(svnMaterial, mod(1L));
Modification svnModification = new Modification("user", "commend", "em@il", new Date(), "2");
Mockito.when(materialRepository.findModificationsSince(svnMaterial, previousSvnRevision)).thenReturn(modifications(svnModification));
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, svnMaterial), new MaterialRevisions(previousDependantRevision, previousSvnRevision), latestRevisions);
assertThat(revisionsSince, is(new MaterialRevisions(new MaterialRevision(dependencyMaterial, dependencyModification), new MaterialRevision(svnMaterial, svnModification))));
Mockito.verify(materialRepository, never()).findLatestModification(dependencyMaterial);
Mockito.verify(materialRepository).findModificationsSince(svnMaterial, previousSvnRevision);
}
use of com.thoughtworks.go.config.materials.Materials in project gocd by gocd.
the class MaterialCheckerTest method shouldUseFlyweightWorkingFolderForLatestModificationCheck.
@Test
public void shouldUseFlyweightWorkingFolderForLatestModificationCheck() throws Exception {
Modification modification = new Modification();
Mockito.when(materialRepository.findLatestModification(mockMaterial)).thenReturn(revisions(mockMaterial, modification));
materialChecker.findLatestRevisions(new MaterialRevisions(), new Materials(mockMaterial));
Mockito.verify(materialRepository).findLatestModification(mockMaterial);
}
use of com.thoughtworks.go.config.materials.Materials 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.config.materials.Materials in project gocd by gocd.
the class MaterialExpansionServiceTest method shouldExpandSvnMaterialWithExternalsIntoMultipleSvnMaterialsWhenExpandingForHistory.
@Test
public void shouldExpandSvnMaterialWithExternalsIntoMultipleSvnMaterialsWhenExpandingForHistory() {
SvnMaterial svn = svnMaterial(svnRepo.projectRepositoryUrl(), "mainRepo", "user1", "pass1", true, "*.doc");
SvnMaterial expectedExternalSvnMaterial = new SvnMaterial(svnRepo.externalRepositoryUrl(), "user1", "pass1", true, "mainRepo/" + svnRepo.externalMaterial().getFolder());
expectedExternalSvnMaterial.setFilter(FilterMother.filterFor("*.doc"));
when(materialConfigConverter.toMaterials(new MaterialConfigs(svn.config(), expectedExternalSvnMaterial.config()))).thenReturn(new Materials(svn, expectedExternalSvnMaterial));
Materials materials = new Materials();
materialExpansionService.expandForScheduling(svn, materials);
assertThat(materials.size(), is(2));
assertThat(materials.get(0), is(svn));
assertThat(((SvnMaterial) materials.get(1)).getUrl(), endsWith("end2end/"));
}
use of com.thoughtworks.go.config.materials.Materials in project gocd by gocd.
the class BuildCauseProducerServiceTest method shouldBeAbleToPassInSpecificRevisionForMaterialsAndScheduleABuild.
@Test
public void shouldBeAbleToPassInSpecificRevisionForMaterialsAndScheduleABuild() throws Exception {
DependencyMaterial dependencyMaterial = new DependencyMaterial(new CaseInsensitiveString("upstream-pipeline"), new CaseInsensitiveString("stage"));
SvnMaterial svnMaterial = new SvnMaterial("url", null, null, false);
pipelineConfig.addMaterialConfig(dependencyMaterial.config());
pipelineConfig.addMaterialConfig(svnMaterial.config());
List<Modification> svnModifications = ModificationsMother.multipleModificationList();
MaterialConfigs knownMaterialConfigs = new MaterialConfigs(pipelineConfig.materialConfigs());
MaterialRevision specificMaterialRevision = new MaterialRevision(dependencyMaterial, new Modification(new Date(), "upstream-pipeline/2/stage/1", "MOCK_LABEL-12", null));
when(specificMaterialRevisionFactory.create(eq("pipeline"), eq(Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/2/stage/1")))).thenReturn(new MaterialRevisions(specificMaterialRevision));
when(pipelineScheduleQueue.mostRecentScheduled("pipeline")).thenReturn(BuildCause.createNeverRun());
when(materialRepository.findLatestModification(svnMaterial)).thenReturn(new MaterialRevisions(new MaterialRevision(svnMaterial, svnModifications)));
when(materialConfigConverter.toMaterials(pipelineConfig.materialConfigs())).thenReturn(new Materials(dependencyMaterial, svnMaterial));
when(materialExpansionService.expandMaterialConfigsForScheduling(pipelineConfig.materialConfigs())).thenReturn(knownMaterialConfigs);
when(materialConfigConverter.toMaterials(knownMaterialConfigs)).thenReturn(new Materials(dependencyMaterial, svnMaterial));
ManualBuild buildType = new ManualBuild(Username.ANONYMOUS);
final HashMap<String, String> stringStringHashMap = new HashMap<>();
buildCauseProducerService.newProduceBuildCause(pipelineConfig, buildType, new ScheduleOptions(Collections.singletonMap(dependencyMaterial.getPipelineUniqueFingerprint(), "upstream-pipeline/2/stage/1"), stringStringHashMap, new HashMap<>()), new ServerHealthStateOperationResult(), 12345);
verify(pipelineScheduleQueue).schedule(eq("pipeline"), argThat(containsRevisions(new MaterialRevision(svnMaterial, svnModifications), specificMaterialRevision)));
}
Aggregations