Search in sources :

Example 16 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class PluggableSCMMaterialUpdaterTest method shouldUpdateToNewMaterialInstanceWhenConfigHas_Changed.

@Test
public void shouldUpdateToNewMaterialInstanceWhenConfigHas_Changed() throws Exception {
    PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
    MaterialInstance materialInstance = material.createMaterialInstance();
    materialInstance.setId(1);
    material.getScmConfig().getConfiguration().add(ConfigurationPropertyMother.create("key2", false, "value2"));
    MaterialInstance newMaterialInstance = material.createMaterialInstance();
    newMaterialInstance.setId(1);
    File file = new File("random");
    Modifications modifications = new Modifications();
    when(materialRepository.find(anyLong())).thenReturn(materialInstance);
    materialUpdater.insertLatestOrNewModifications(material, materialInstance, file, modifications);
    verify(materialRepository).saveOrUpdate(newMaterialInstance);
    verify(scmMaterialUpdater).insertLatestOrNewModifications(material, materialInstance, file, modifications);
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) File(java.io.File) Test(org.junit.Test)

Example 17 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class MaterialServiceTest method shouldGetModificationSince_PluggableSCMMaterial.

@Test
public void shouldGetModificationSince_PluggableSCMMaterial() {
    PluggableSCMMaterial pluggableSCMMaterial = MaterialsMother.pluggableSCMMaterial();
    MaterialInstance materialInstance = pluggableSCMMaterial.createMaterialInstance();
    when(materialRepository.findMaterialInstance(any(Material.class))).thenReturn(materialInstance);
    MaterialPollResult materialPollResult = new MaterialPollResult(null, asList(new SCMRevision("new-revision-456", new Date(), "user", "comment", null, null)));
    when(scmExtension.latestModificationSince(any(String.class), any(SCMPropertyConfiguration.class), any(Map.class), any(String.class), any(SCMRevision.class))).thenReturn(materialPollResult);
    PluggableSCMMaterialRevision previouslyKnownRevision = new PluggableSCMMaterialRevision("revision-124", new Date());
    List<Modification> modifications = materialService.modificationsSince(pluggableSCMMaterial, new File("/tmp/flyweight"), previouslyKnownRevision, null);
    assertThat(modifications.get(0).getRevision(), is("new-revision-456"));
}
Also used : PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) P4Material(com.thoughtworks.go.config.materials.perforce.P4Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) TfsMaterial(com.thoughtworks.go.config.materials.tfs.TfsMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) PluggableSCMMaterialRevision(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision) Date(java.util.Date) SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) GitMaterialInstance(com.thoughtworks.go.domain.materials.git.GitMaterialInstance) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) Map(java.util.Map) File(java.io.File) Test(org.junit.Test)

Example 18 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class MaterialServiceTest method shouldGetLatestModification_PluggableSCMMaterial.

@Test
public void shouldGetLatestModification_PluggableSCMMaterial() {
    PluggableSCMMaterial pluggableSCMMaterial = MaterialsMother.pluggableSCMMaterial();
    MaterialInstance materialInstance = pluggableSCMMaterial.createMaterialInstance();
    when(materialRepository.findMaterialInstance(any(Material.class))).thenReturn(materialInstance);
    MaterialPollResult materialPollResult = new MaterialPollResult(null, new SCMRevision("blah-123", new Date(), "user", "comment", null, null));
    when(scmExtension.getLatestRevision(any(String.class), any(SCMPropertyConfiguration.class), any(Map.class), any(String.class))).thenReturn(materialPollResult);
    List<Modification> modifications = materialService.latestModification(pluggableSCMMaterial, new File("/tmp/flyweight"), null);
    assertThat(modifications.get(0).getRevision(), is("blah-123"));
}
Also used : PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) P4Material(com.thoughtworks.go.config.materials.perforce.P4Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) TfsMaterial(com.thoughtworks.go.config.materials.tfs.TfsMaterial) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) GitMaterialInstance(com.thoughtworks.go.domain.materials.git.GitMaterialInstance) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) Map(java.util.Map) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 19 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class MagicalMaterialAndMaterialConfigConversionTest method shouldBeSameObject_WhenConversionIsDoneFromMaterialToMaterialInstanceAndBack.

@Theory
public void shouldBeSameObject_WhenConversionIsDoneFromMaterialToMaterialInstanceAndBack(MaterialConfig materialConfig) throws Exception {
    Material material = materialConfigConverter.toMaterial(materialConfig);
    MaterialInstance materialInstance = material.createMaterialInstance();
    Material materialConvertedBackFromInstance = materialInstance.toOldMaterial(materialConfig.getName().toString(), materialConfig.getFolder(), "pass");
    assertTrue(message("Material <-> MaterialInstance conversion failed.", material, materialConvertedBackFromInstance), reflectionEquals(material, materialConvertedBackFromInstance, fieldsWhichShouldBeIgnoredWhenSavedInDbAndGotBack.get(materialConfig.getClass())));
    assertThat(materialInstance.getFingerprint(), is(material.getFingerprint()));
    assertThat(materialConvertedBackFromInstance.getFingerprint(), is(materialInstance.getFingerprint()));
    assertPasswordIsCorrect(material);
    assertPasswordIsCorrect(materialConvertedBackFromInstance);
}
Also used : Material(com.thoughtworks.go.domain.materials.Material) PasswordAwareMaterial(com.thoughtworks.go.config.materials.PasswordAwareMaterial) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) Theory(org.junit.experimental.theories.Theory)

Example 20 with MaterialInstance

use of com.thoughtworks.go.domain.MaterialInstance in project gocd by gocd.

the class ValueStreamMapService method getValueStreamMap.

public ValueStreamMapPresentationModel getValueStreamMap(String materialFingerprint, String revision, Username username, LocalizedOperationResult result) {
    try {
        MaterialConfig materialConfig = null;
        boolean hasViewPermissionForMaterial = false;
        List<PipelineConfig> downstreamPipelines = new ArrayList<>();
        for (PipelineConfigs pipelineGroup : goConfigService.groups()) {
            boolean hasViewPermissionForGroup = securityService.hasViewPermissionForGroup(CaseInsensitiveString.str(username.getUsername()), pipelineGroup.getGroup());
            for (PipelineConfig pipelineConfig : pipelineGroup) {
                for (MaterialConfig currentMaterialConfig : pipelineConfig.materialConfigs()) {
                    if (currentMaterialConfig.getFingerprint().equals(materialFingerprint)) {
                        materialConfig = currentMaterialConfig;
                        if (hasViewPermissionForGroup) {
                            hasViewPermissionForMaterial = true;
                        }
                        downstreamPipelines.add(pipelineConfig);
                    }
                }
            }
        }
        if (materialConfig == null) {
            result.notFound(LocalizedMessage.string("MATERIAL_CONFIG_WITH_FINGERPRINT_NOT_FOUND", materialFingerprint), HealthStateType.general(HealthStateScope.GLOBAL));
            return null;
        }
        if (!hasViewPermissionForMaterial) {
            result.unauthorized(LocalizedMessage.cannotViewMaterial(materialFingerprint), HealthStateType.general(HealthStateScope.forMaterialConfig(materialConfig)));
            return null;
        }
        MaterialInstance materialInstance = materialRepository.findMaterialInstance(materialConfig);
        if (materialInstance == null) {
            result.notFound(LocalizedMessage.string("MATERIAL_INSTANCE_WITH_FINGERPRINT_NOT_FOUND", materialFingerprint), HealthStateType.general(HealthStateScope.forMaterialConfig(materialConfig)));
            return null;
        }
        Material material = new MaterialConfigConverter().toMaterial(materialConfig);
        Modification modification = materialRepository.findModificationWithRevision(material, revision);
        if (modification == null) {
            result.notFound(LocalizedMessage.string("MATERIAL_MODIFICATION_NOT_FOUND", materialFingerprint, revision), HealthStateType.general(HealthStateScope.forMaterialConfig(materialConfig)));
            return null;
        }
        ValueStreamMap valueStreamMap = buildValueStreamMap(material, materialInstance, modification, downstreamPipelines, username);
        if (valueStreamMap == null) {
            return null;
        }
        return valueStreamMap.presentationModel();
    } catch (Exception e) {
        result.internalServerError(LocalizedMessage.string("VSM_INTERNAL_SERVER_ERROR_FOR_MATERIAL", materialFingerprint, revision));
        LOGGER.error("[Value Stream Map] Material {} with revision {} could not be rendered.", materialFingerprint, revision, e);
        return null;
    }
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) ArrayList(java.util.ArrayList) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance)

Aggregations

MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)39 Test (org.junit.Test)28 File (java.io.File)13 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)10 Modification (com.thoughtworks.go.domain.materials.Modification)9 Modifications (com.thoughtworks.go.domain.materials.Modifications)9 PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)7 MaterialPollResult (com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult)7 SCMRevision (com.thoughtworks.go.plugin.access.scm.revision.SCMRevision)7 TransactionStatus (org.springframework.transaction.TransactionStatus)7 SCMPropertyConfiguration (com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration)6 Date (java.util.Date)6 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)5 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)5 TfsMaterial (com.thoughtworks.go.config.materials.tfs.TfsMaterial)5 TransactionCallback (org.springframework.transaction.support.TransactionCallback)5 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)4 Material (com.thoughtworks.go.domain.materials.Material)4 HashMap (java.util.HashMap)4