Search in sources :

Example 31 with Modifications

use of com.thoughtworks.go.domain.materials.Modifications in project gocd by gocd.

the class ChangesetServiceIntegrationTest method testShouldGroupMaterialsBasedOnFingerprint.

@Test
public void testShouldGroupMaterialsBasedOnFingerprint() {
    SvnMaterial first = new SvnMaterial("url", "user1", "password", false);
    Modification mod1 = new Modification("user1", "comment", "email", new Date(), "revision");
    mod1.setMaterialInstance(new SvnMaterialInstance("url", "user1", "flyweight1", false));
    Modification mod2 = new Modification("user1", "comment", "email", new Date(), "revision");
    mod2.setMaterialInstance(new SvnMaterialInstance("url", "user1", "flyweight1", false));
    Map<Material, Modifications> map = changesetService.groupModsByMaterial(Arrays.asList(mod1, mod2));
    assertThat(map.size(), is(1));
    assertThat(map.get(first), is(new Modifications(mod1, mod2)));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) Modification(com.thoughtworks.go.domain.materials.Modification) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) SvnMaterialInstance(com.thoughtworks.go.domain.materials.svn.SvnMaterialInstance) Test(org.junit.Test)

Example 32 with Modifications

use of com.thoughtworks.go.domain.materials.Modifications in project gocd by gocd.

the class PackageMaterialUpdaterIntegrationTest method shouldUpdateMaterialInstanceWhenPluginIsUpgraded.

@Test
public void shouldUpdateMaterialInstanceWhenPluginIsUpgraded() throws Exception {
    final PackageMaterial material = MaterialsMother.packageMaterial();
    final MaterialInstance materialInstance = material.createMaterialInstance();
    materialRepository.saveOrUpdate(materialInstance);
    addMetadata(material, "fieldX", false);
    material.getPackageDefinition().getConfiguration().addNewConfiguration("fieldX", true);
    final List<Modification> modifications = ModificationsMother.multipleModificationList();
    doNothing().when(scmMaterialUpdater).insertLatestOrNewModifications(material, materialInstance, new File(""), new Modifications(modifications));
    transactionTemplate.execute(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus transactionStatus) {
            packageMaterialUpdater.insertLatestOrNewModifications(material, materialInstance, new File(""), new Modifications(modifications));
            return null;
        }
    });
    MaterialInstance actualInstance = materialRepository.findMaterialInstance(material);
    assertThat(actualInstance.getConfiguration(), is(material.createMaterialInstance().getConfiguration()));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) Modification(com.thoughtworks.go.domain.materials.Modification) TransactionCallback(org.springframework.transaction.support.TransactionCallback) PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) TransactionStatus(org.springframework.transaction.TransactionStatus) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) File(java.io.File) Test(org.junit.Test)

Example 33 with Modifications

use of com.thoughtworks.go.domain.materials.Modifications in project gocd by gocd.

the class PluggableSCMMaterialUpdaterIntegrationTest method shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModification.

@Test
public void shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModification() throws Exception {
    final PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
    final MaterialInstance materialInstance = material.createMaterialInstance();
    materialRepository.saveOrUpdate(materialInstance);
    Map<String, String> data = new HashMap<>();
    data.put("k1", "v1");
    when(scmExtension.getLatestRevision(any(String.class), any(SCMPropertyConfiguration.class), any(Map.class), any(String.class))).thenReturn(new MaterialPollResult(data, new SCMRevision()));
    mockSCMExtensionInPoller();
    scmMaterialUpdater = new ScmMaterialUpdater(materialRepository, materialChecker, subprocessExecutionContext, materialService);
    pluggableSCMMaterialUpdater = new PluggableSCMMaterialUpdater(materialRepository, scmMaterialUpdater, transactionTemplate);
    transactionTemplate.execute(new TransactionCallback() {

        @Override
        public Object doInTransaction(TransactionStatus transactionStatus) {
            pluggableSCMMaterialUpdater.insertLatestOrNewModifications(material, materialInstance, new File(""), new Modifications());
            return null;
        }
    });
    MaterialInstance actualInstance = materialRepository.findMaterialInstance(material);
    assertThat(actualInstance.getAdditionalDataMap(), is(data));
}
Also used : PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) HashMap(java.util.HashMap) MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) TransactionStatus(org.springframework.transaction.TransactionStatus) Modifications(com.thoughtworks.go.domain.materials.Modifications) TransactionCallback(org.springframework.transaction.support.TransactionCallback) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) Test(org.junit.Test)

Example 34 with Modifications

use of com.thoughtworks.go.domain.materials.Modifications in project gocd by gocd.

the class ValueStreamMapServiceTest method shouldPopulateAllSCMMaterialRevisionsThatCausedPipelineRun_WhenFaninIsNotObeyed.

@Test
public void shouldPopulateAllSCMMaterialRevisionsThatCausedPipelineRun_WhenFaninIsNotObeyed() {
    /*
        * git---> p1 --->p2
        *  |             ^
        *  +-------------+
        * **/
    GitMaterial git = new GitMaterial("git");
    MaterialConfig gitConfig = git.config();
    Modification modification1 = checkinWithComment("rev1", "comment1", new Date());
    Modification modification2 = checkinWithComment("rev2", "comment2", new Date());
    Modification modification3 = checkinWithComment("rev3", "comment3", new Date());
    BuildCause p1buildCause = createBuildCauseForRevisions(new ArrayList<>(), asList(git), new Modifications(modification1, modification2));
    BuildCause p2buildCause = createBuildCauseForRevisions(asList(dependencyMaterial("p1", 1)), asList(git), new Modifications(modification3));
    when(pipelineService.buildCauseFor("p2", 1)).thenReturn(p2buildCause);
    when(pipelineService.buildCauseFor("p1", 1)).thenReturn(p1buildCause);
    PipelineConfig p1Config = PipelineConfigMother.pipelineConfig("p1", new MaterialConfigs(gitConfig));
    PipelineConfig p2Config = PipelineConfigMother.pipelineConfig("p2", new MaterialConfigs(gitConfig));
    CruiseConfig cruiseConfig = new BasicCruiseConfig(new BasicPipelineConfigs(p1Config, p2Config));
    when(pipelineService.findPipelineByCounterOrLabel("p2", "1")).thenReturn(new Pipeline("p2", "LABEL-P2", p2buildCause));
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    ValueStreamMapPresentationModel graph = valueStreamMapService.getValueStreamMap("p2", 1, user, result);
    VSMTestHelper.assertNodeHasRevisions(graph, "p1", new PipelineRevision("p1", 1, "LABEL-p1-1"));
    VSMTestHelper.assertNodeHasRevisions(graph, "p2", new PipelineRevision("p2", 1, "LABEL-P2"));
    VSMTestHelper.assertSCMNodeHasMaterialRevisions(graph, git.getFingerprint(), new MaterialRevision(git, false, modification1, modification2), new MaterialRevision(git, false, modification3));
    verify(runStagesPopulator).apply(any(ValueStreamMap.class));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Modifications(com.thoughtworks.go.domain.materials.Modifications) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) ValueStreamMapPresentationModel(com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel) Test(org.junit.Test)

Example 35 with Modifications

use of com.thoughtworks.go.domain.materials.Modifications in project gocd by gocd.

the class ValueStreamMapServiceTest method shouldPopulateAllMaterialRevisionsThatCausedPipelineRun.

@Test
public void shouldPopulateAllMaterialRevisionsThatCausedPipelineRun() {
    /*
        * git---> p1 --->p2
        *  |             ^
        *  +-------------+
        * **/
    GitMaterial git = new GitMaterial("git");
    MaterialConfig gitConfig = git.config();
    BuildCause p2buildCause = createBuildCauseForRevisions(asList(dependencyMaterial("p1", 1)), asList(git), ModificationsMother.multipleModificationList(0));
    BuildCause p1buildCause = createBuildCause(new ArrayList<>(), asList(git));
    Modifications gitModifications = p1buildCause.getMaterialRevisions().getMaterialRevision(0).getModifications();
    when(pipelineService.buildCauseFor("p2", 1)).thenReturn(p2buildCause);
    when(pipelineService.buildCauseFor("p1", 1)).thenReturn(p1buildCause);
    PipelineConfig p1Config = PipelineConfigMother.pipelineConfig("p1", new MaterialConfigs(gitConfig));
    PipelineConfig p2Config = PipelineConfigMother.pipelineConfig("p2", new MaterialConfigs(gitConfig));
    CruiseConfig cruiseConfig = new BasicCruiseConfig(new BasicPipelineConfigs(p1Config, p2Config));
    when(pipelineService.findPipelineByCounterOrLabel("p2", "1")).thenReturn(new Pipeline("p2", "LABEL-P2", p2buildCause));
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    ValueStreamMapPresentationModel graph = valueStreamMapService.getValueStreamMap("p2", 1, user, result);
    VSMTestHelper.assertNodeHasRevisions(graph, "p1", new PipelineRevision("p1", 1, "LABEL-p1-1"));
    VSMTestHelper.assertNodeHasRevisions(graph, "p2", new PipelineRevision("p2", 1, "LABEL-P2"));
    VSMTestHelper.assertSCMNodeHasMaterialRevisions(graph, git.getFingerprint(), new MaterialRevision(git, false, gitModifications));
    verify(runStagesPopulator).apply(any(ValueStreamMap.class));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Modifications(com.thoughtworks.go.domain.materials.Modifications) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) DependencyMaterialConfig(com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig) ValueStreamMapPresentationModel(com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel) Test(org.junit.Test)

Aggregations

Modifications (com.thoughtworks.go.domain.materials.Modifications)35 Test (org.junit.Test)29 Modification (com.thoughtworks.go.domain.materials.Modification)21 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)15 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)12 Date (java.util.Date)12 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)10 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)10 MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)9 File (java.io.File)8 HashMap (java.util.HashMap)6 LinkedHashMap (java.util.LinkedHashMap)6 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)5 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)5 PackageMaterialRevision (com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision)5 PluggableSCMMaterialRevision (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision)5 SCM (com.thoughtworks.go.domain.scm.SCM)5 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)4 TransactionStatus (org.springframework.transaction.TransactionStatus)4 TransactionCallback (org.springframework.transaction.support.TransactionCallback)4