Search in sources :

Example 1 with PluggableSCMMaterialRevision

use of com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision 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 2 with PluggableSCMMaterialRevision

use of com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision 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)

Example 3 with PluggableSCMMaterialRevision

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

the class PluggableSCMMaterialPollerTest method shouldGetModificationsSinceAGivenRevisionAlongWithAdditionalDataFromTheSCMRevision.

@Test
void shouldGetModificationsSinceAGivenRevisionAlongWithAdditionalDataFromTheSCMRevision() {
    String previousRevision = "rev-122";
    Date timestamp = new Date();
    Map<String, String> dataInPreviousRevision = new HashMap<>();
    dataInPreviousRevision.put("1", "one");
    PluggableSCMMaterialRevision knownRevision = new PluggableSCMMaterialRevision(previousRevision, timestamp, dataInPreviousRevision);
    ArgumentCaptor<SCMRevision> knownSCMRevision = ArgumentCaptor.forClass(SCMRevision.class);
    Map<String, String> data = new HashMap<>();
    String dataKey = "2";
    String dataValue = "two";
    data.put(dataKey, dataValue);
    SCMRevision latestRevision = new SCMRevision("rev-123", timestamp, "user", "comment-123", data, 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(knownSCMRevision.getValue().getRevision()).isEqualTo(previousRevision);
    assertThat(knownSCMRevision.getValue().getTimestamp()).isEqualTo(timestamp);
    assertThat(knownSCMRevision.getValue().getData()).isNotNull();
    assertThat(knownSCMRevision.getValue().getData().size()).isEqualTo(dataInPreviousRevision.size());
    assertThat(knownSCMRevision.getValue().getData().get("1")).isEqualTo(dataInPreviousRevision.get("1"));
    HashMap<String, String> expected = new HashMap<>();
    expected.put(dataKey, dataValue);
    Modification firstModification = modifications.get(0);
    assertThat(firstModification.getRevision()).isEqualTo("rev-123");
    assertThat(firstModification.getModifiedTime()).isEqualTo(timestamp);
    assertThat(firstModification.getUserName()).isEqualTo("user");
    assertThat(firstModification.getComment()).isEqualTo("comment-123");
    assertThat(firstModification.getAdditionalData()).isEqualTo(JsonHelper.toJsonString(expected));
    assertThat(firstModification.getModifiedFiles().isEmpty()).isTrue();
    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)

Example 4 with PluggableSCMMaterialRevision

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

the class ModificationsTest method shouldGetLatestModificationsForPluggableSCMMaterial.

@Test
public void shouldGetLatestModificationsForPluggableSCMMaterial() {
    String revisionString = "123";
    Date timestamp = new Date();
    HashMap<String, String> data = new HashMap<>();
    data.put("1", "one");
    data.put("2", "two");
    Modification modification = new Modification(null, null, null, timestamp, revisionString, JsonHelper.toJsonString(data));
    Modifications modifications = new Modifications(modification);
    Revision revision = modifications.latestRevision(new PluggableSCMMaterial());
    assertThat(revision instanceof PluggableSCMMaterialRevision, is(true));
    PluggableSCMMaterialRevision pluggableSCMMaterialRevision = (PluggableSCMMaterialRevision) revision;
    assertThat(pluggableSCMMaterialRevision.getRevision(), is(revisionString));
    assertThat(pluggableSCMMaterialRevision.getTimestamp(), is(timestamp));
    assertThat(pluggableSCMMaterialRevision.getData().size(), is(data.size()));
    assertThat(pluggableSCMMaterialRevision.getData().get("1"), is(data.get("1")));
    assertThat(pluggableSCMMaterialRevision.getData().get("2"), is(data.get("2")));
}
Also used : PluggableSCMMaterialRevision(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision) PackageMaterialRevision(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision) StringRevision(com.thoughtworks.go.domain.materials.mercurial.StringRevision) HashMap(java.util.HashMap) PluggableSCMMaterialRevision(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 5 with PluggableSCMMaterialRevision

use of com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision 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)

Aggregations

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