Search in sources :

Example 1 with MaterialPollResult

use of com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult in project gocd by gocd.

the class PluggableSCMMaterialUpdaterIntegrationTest method shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModificationsSince.

@Test
public void shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModificationsSince() throws Exception {
    final PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
    final MaterialInstance materialInstance = material.createMaterialInstance();
    Map<String, String> oldData = new HashMap<>();
    oldData.put("k1", "v1");
    materialInstance.setAdditionalData(new GsonBuilder().create().toJson(oldData));
    materialRepository.saveOrUpdate(materialInstance);
    Map<String, String> newData = new HashMap<>(oldData);
    newData.put("k2", "v2");
    when(scmExtension.latestModificationSince(any(String.class), any(SCMPropertyConfiguration.class), any(Map.class), any(String.class), any(SCMRevision.class))).thenReturn(new MaterialPollResult(newData, 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(new Modification()));
            return null;
        }
    });
    MaterialInstance actualInstance = materialRepository.findMaterialInstance(material);
    assertThat(actualInstance.getAdditionalDataMap(), is(newData));
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) HashMap(java.util.HashMap) GsonBuilder(com.google.gson.GsonBuilder) 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.jupiter.api.Test)

Example 2 with MaterialPollResult

use of com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult in project gocd by gocd.

the class PluggableSCMMaterialPoller method modificationsSince.

@Override
public List<Modification> modificationsSince(final PluggableSCMMaterial material, File baseDir, final Revision revision, SubprocessExecutionContext execCtx) {
    SCMPropertyConfiguration scmPropertyConfiguration = buildSCMPropertyConfigurations(material.getScmConfig());
    MaterialInstance materialInstance = materialRepository.findMaterialInstance(material);
    PluggableSCMMaterialRevision pluggableSCMMaterialRevision = (PluggableSCMMaterialRevision) revision;
    SCMRevision previouslyKnownRevision = new SCMRevision(pluggableSCMMaterialRevision.getRevision(), pluggableSCMMaterialRevision.getTimestamp(), null, null, pluggableSCMMaterialRevision.getData(), null);
    MaterialPollResult pollResult = scmExtension.latestModificationSince(material.getPluginId(), scmPropertyConfiguration, materialInstance.getAdditionalDataMap(), baseDir.getAbsolutePath(), previouslyKnownRevision);
    final Map<String, String> materialData = pollResult.getMaterialData();
    if (materialInstance.requiresUpdate(materialData)) {
        updateAdditionalData(materialInstance.getId(), materialData);
    }
    List<SCMRevision> scmRevisions = pollResult.getRevisions();
    return getModifications(scmRevisions);
}
Also used : MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) PluggableSCMMaterialRevision(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance)

Example 3 with MaterialPollResult

use of com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult in project gocd by gocd.

the class PluggableSCMMaterialPollerTest method shouldTalkToPlugInToGetLatestModifications.

@Test
void shouldTalkToPlugInToGetLatestModifications() {
    Date timestamp = new Date();
    SCMRevision scmRevision = new SCMRevision("revision-123", timestamp, "user", "comment", null, null);
    MaterialPollResult materialPollResult = new MaterialPollResult(null, scmRevision);
    when(scmExtension.getLatestRevision(eq(material.getPluginId()), scmConfiguration.capture(), materialData.capture(), eq(flyweightFolderPath))).thenReturn(materialPollResult);
    List<Modification> modifications = poller.latestModification(material, new File(flyweightFolderPath), null);
    assertThat(modifications.get(0).getRevision()).isEqualTo("revision-123");
    assertThat(modifications.get(0).getModifiedTime()).isEqualTo(timestamp);
    assertThat(modifications.get(0).getUserName()).isEqualTo("user");
    assertThat(modifications.get(0).getComment()).isEqualTo("comment");
    assertConfiguration(scmConfiguration.getValue(), "k1", "v1");
    assertConfiguration(scmConfiguration.getValue(), "k2", "v2");
    assertThat(materialData.getValue().size()).isEqualTo(1);
    assertThat(materialData.getValue().get("mk-1")).isEqualTo("mv-1");
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) ModifiedFile(com.thoughtworks.go.plugin.access.scm.revision.ModifiedFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 4 with MaterialPollResult

use of com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult in project gocd by gocd.

the class PluggableSCMMaterialPollerTest method shouldReturnEmptyModificationWhenSCMRevisionIsNullFor_latestModificationSince.

@Test
void shouldReturnEmptyModificationWhenSCMRevisionIsNullFor_latestModificationSince() {
    PluggableSCMMaterialRevision knownRevision = new PluggableSCMMaterialRevision("rev-122", new Date());
    ArgumentCaptor<SCMRevision> knownSCMRevision = ArgumentCaptor.forClass(SCMRevision.class);
    when(scmExtension.latestModificationSince(eq(material.getPluginId()), scmConfiguration.capture(), materialData.capture(), eq(flyweightFolderPath), knownSCMRevision.capture())).thenReturn(new MaterialPollResult());
    List<Modification> modifications = poller.modificationsSince(material, new File(flyweightFolderPath), knownRevision, null);
    assertThat(modifications).isNotNull();
    assertThat(modifications.isEmpty()).isTrue();
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) PluggableSCMMaterialRevision(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) ModifiedFile(com.thoughtworks.go.plugin.access.scm.revision.ModifiedFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 5 with MaterialPollResult

use of com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult in project gocd by gocd.

the class PluggableSCMMaterialPollerTest method shouldTalkToPlugInToGetModificationsSinceAGivenRevision.

@Test
void shouldTalkToPlugInToGetModificationsSinceAGivenRevision() {
    Date timestamp = new Date();
    PluggableSCMMaterialRevision knownRevision = new PluggableSCMMaterialRevision("rev-122", timestamp);
    ArgumentCaptor<SCMRevision> knownSCMRevision = ArgumentCaptor.forClass(SCMRevision.class);
    SCMRevision latestRevision = new SCMRevision("rev-123", timestamp, "user", null, null, null);
    MaterialPollResult materialPollResult = new MaterialPollResult(null, asList(latestRevision));
    when(scmExtension.latestModificationSince(eq(material.getPluginId()), scmConfiguration.capture(), materialData.capture(), eq(flyweightFolderPath), knownSCMRevision.capture())).thenReturn(materialPollResult);
    List<Modification> modifications = poller.modificationsSince(material, new File(flyweightFolderPath), knownRevision, null);
    assertThat(modifications.get(0).getRevision()).isEqualTo("rev-123");
    assertThat(modifications.get(0).getModifiedTime()).isEqualTo(timestamp);
    assertThat(modifications.get(0).getUserName()).isEqualTo("user");
    assertThat(modifications.get(0).getComment()).isNull();
    assertConfiguration(scmConfiguration.getValue(), "k1", "v1");
    assertConfiguration(scmConfiguration.getValue(), "k2", "v2");
    assertThat(knownSCMRevision.getValue().getRevision()).isEqualTo("rev-122");
    assertThat(knownSCMRevision.getValue().getTimestamp()).isEqualTo(timestamp);
    assertThat(materialData.getValue().size()).isEqualTo(1);
    assertThat(materialData.getValue().get("mk-1")).isEqualTo("mv-1");
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) PluggableSCMMaterialRevision(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) ModifiedFile(com.thoughtworks.go.plugin.access.scm.revision.ModifiedFile) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

MaterialPollResult (com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult)19 Test (org.junit.jupiter.api.Test)17 SCMRevision (com.thoughtworks.go.plugin.access.scm.revision.SCMRevision)13 File (java.io.File)10 ModifiedFile (com.thoughtworks.go.plugin.access.scm.revision.ModifiedFile)8 Modification (com.thoughtworks.go.domain.materials.Modification)7 MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)6 PluggableSCMMaterialRevision (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision)5 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)4 SCMPropertyConfiguration (com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration)4 Map (java.util.Map)4 Modifications (com.thoughtworks.go.domain.materials.Modifications)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)2 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)2 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)2 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)2 P4Material (com.thoughtworks.go.config.materials.perforce.P4Material)2 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)2 TfsMaterial (com.thoughtworks.go.config.materials.tfs.TfsMaterial)2