Search in sources :

Example 16 with PackageMaterial

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));
}
Also used : PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) Test(org.junit.Test)

Example 17 with PackageMaterial

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;
}
Also used : PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) SCM(com.thoughtworks.go.domain.scm.SCM) Timestamp(java.sql.Timestamp)

Example 18 with PackageMaterial

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);
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Materials(com.thoughtworks.go.config.materials.Materials) Stage(com.thoughtworks.go.domain.Stage) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 19 with PackageMaterial

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);
}
Also used : PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) File(java.io.File) Test(org.junit.Test)

Example 20 with PackageMaterial

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"));
}
Also used : PackageMaterialRevision(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision) SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) Configuration(com.thoughtworks.go.domain.config.Configuration) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration) PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRevision(com.thoughtworks.go.plugin.api.material.packagerepository.PackageRevision) PackageConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) Date(java.util.Date) Test(org.junit.Test)

Aggregations

PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)23 Test (org.junit.Test)18 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)6 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)5 File (java.io.File)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)4 Configuration (com.thoughtworks.go.domain.config.Configuration)4 Modification (com.thoughtworks.go.domain.materials.Modification)4 PackageRevision (com.thoughtworks.go.plugin.api.material.packagerepository.PackageRevision)4 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)3 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)3 Modifications (com.thoughtworks.go.domain.materials.Modifications)3 Date (java.util.Date)3 Materials (com.thoughtworks.go.config.materials.Materials)2 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)2 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)2 PackageMaterialRevision (com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision)2 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)2 SCM (com.thoughtworks.go.domain.scm.SCM)2