use of com.thoughtworks.go.config.materials.PackageMaterial in project gocd by gocd.
the class PackageMaterialInstanceTest method shouldSetFingerprintWhenConvertingMaterialInstanceToMaterial.
@Test
public void shouldSetFingerprintWhenConvertingMaterialInstanceToMaterial() {
String fingerprint = "fingerprint";
PackageMaterial material = MaterialsMother.packageMaterial();
PackageMaterialInstance materialInstance = new PackageMaterialInstance(JsonHelper.toJsonString(material), "flyweight");
ReflectionUtil.setField(materialInstance, "fingerprint", fingerprint);
materialInstance.setId(1L);
PackageMaterial constructedMaterial = (PackageMaterial) materialInstance.toOldMaterial(null, null, null);
assertThat(constructedMaterial.getFingerprint(), Is.is(fingerprint));
}
use of com.thoughtworks.go.config.materials.PackageMaterial in project gocd by gocd.
the class JsonMessageHandler2_0_Test method createPipeline.
private Pipeline createPipeline() throws Exception {
Pipeline pipeline = PipelineMother.pipelineWithAllTypesOfMaterials("pipeline-name", "stage-name", "job-name", "1");
List<MaterialRevision> materialRevisions = pipeline.getMaterialRevisions().getRevisions();
PackageDefinition packageDefinition = ((PackageMaterial) materialRevisions.get(6).getMaterial()).getPackageDefinition();
packageDefinition.getRepository().getConfiguration().get(1).handleSecureValueConfiguration(true);
packageDefinition.getConfiguration().addNewConfigurationWithValue("k4", "package-v2", false);
packageDefinition.getConfiguration().get(1).handleSecureValueConfiguration(true);
SCM scm = ((PluggableSCMMaterial) materialRevisions.get(7).getMaterial()).getScmConfig();
scm.getConfiguration().get(1).handleSecureValueConfiguration(true);
Stage stage = pipeline.getFirstStage();
stage.setId(1L);
stage.setPipelineId(1L);
stage.setCreatedTime(new Timestamp(getFixedDate().getTime()));
stage.setLastTransitionedTime(new Timestamp(getFixedDate().getTime()));
JobInstance job = stage.getJobInstances().get(0);
job.setScheduledDate(getFixedDate());
job.getTransition(JobState.Assigned).setStateChangeTime(getFixedDate());
job.getTransition(JobState.Completed).setStateChangeTime(getFixedDate());
return pipeline;
}
use of com.thoughtworks.go.config.materials.PackageMaterial 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.PackageMaterial in project gocd by gocd.
the class PackageMaterialUpdaterTest method shouldDelegateToSCMUpdaterToAddNewMaterial.
@Test
public void shouldDelegateToSCMUpdaterToAddNewMaterial() throws Exception {
PackageMaterial material = MaterialsMother.packageMaterial();
File file = new File("random");
materialUpdater.addNewMaterialWithModifications(material, file);
verify(scmMaterialUpdater).addNewMaterialWithModifications(material, file);
}
use of com.thoughtworks.go.config.materials.PackageMaterial in project gocd by gocd.
the class MaterialServiceTest method shouldGetModificationSinceAGivenRevision.
@Test
public void shouldGetModificationSinceAGivenRevision() {
PackageMaterial material = new PackageMaterial();
PackageDefinition packageDefinition = create("id", "package", new Configuration(), PackageRepositoryMother.create("id", "name", "plugin-id", "plugin-version", new Configuration()));
material.setPackageDefinition(packageDefinition);
when(packageRepositoryExtension.latestModificationSince(eq("plugin-id"), any(PackageConfiguration.class), any(RepositoryConfiguration.class), any(PackageRevision.class))).thenReturn(new PackageRevision("new-revision-456", new Date(), "user"));
List<Modification> modifications = materialService.modificationsSince(material, null, new PackageMaterialRevision("revision-124", new Date()), null);
assertThat(modifications.get(0).getRevision(), is("new-revision-456"));
}
Aggregations