Search in sources :

Example 11 with MaterialPollResult

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

the class JsonMessageHandler1_0Test method shouldBuildSCMRevisionFromLatestRevisionResponse.

@Test
public void shouldBuildSCMRevisionFromLatestRevisionResponse() throws Exception {
    String revisionJSON = "{\"revision\":\"r1\",\"timestamp\":\"2011-07-14T19:43:37.100Z\",\"user\":\"some-user\",\"revisionComment\":\"comment\",\"data\":{\"dataKeyTwo\":\"data-value-two\",\"dataKeyOne\":\"data-value-one\"}," + "\"modifiedFiles\":[{\"fileName\":\"f1\",\"action\":\"added\"},{\"fileName\":\"f2\",\"action\":\"modified\"},{\"fileName\":\"f3\",\"action\":\"deleted\"}]}";
    String responseBody = "{\"revision\": " + revisionJSON + "}";
    MaterialPollResult pollResult = messageHandler.responseMessageForLatestRevision(responseBody);
    assertThat(pollResult.getMaterialData(), is(nullValue()));
    assertSCMRevision(pollResult.getLatestRevision(), "r1", "some-user", "2011-07-14T19:43:37.100Z", "comment", asList(new ModifiedFile("f1", ModifiedAction.added), new ModifiedFile("f2", ModifiedAction.modified), new ModifiedFile("f3", ModifiedAction.deleted)));
}
Also used : MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) ModifiedFile(com.thoughtworks.go.plugin.access.scm.revision.ModifiedFile) Test(org.junit.jupiter.api.Test)

Example 12 with MaterialPollResult

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

the class JsonMessageHandler1_0Test method shouldBuildSCMDataFromLatestRevisionsSinceResponse.

@Test
public void shouldBuildSCMDataFromLatestRevisionsSinceResponse() throws Exception {
    String responseBodyWithSCMData = "{\"revisions\":[],\"scm-data\":{\"key-one\":\"value-one\"}}";
    MaterialPollResult pollResult = messageHandler.responseMessageForLatestRevisionsSince(responseBodyWithSCMData);
    Map<String, String> scmData = new HashMap<>();
    scmData.put("key-one", "value-one");
    assertThat(pollResult.getMaterialData(), is(scmData));
    assertThat(pollResult.getRevisions().isEmpty(), is(true));
}
Also used : MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) Test(org.junit.jupiter.api.Test)

Example 13 with MaterialPollResult

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

the class PluggableSCMMaterialPoller method latestModification.

@Override
public List<Modification> latestModification(final PluggableSCMMaterial material, File baseDir, SubprocessExecutionContext execCtx) {
    SCMPropertyConfiguration scmPropertyConfiguration = buildSCMPropertyConfigurations(material.getScmConfig());
    final MaterialInstance materialInstance = materialRepository.findMaterialInstance(material);
    MaterialPollResult pollResult = scmExtension.getLatestRevision(material.getPluginId(), scmPropertyConfiguration, materialInstance.getAdditionalDataMap(), baseDir.getAbsolutePath());
    final Map<String, String> materialData = pollResult.getMaterialData();
    if (materialInstance.requiresUpdate(materialData)) {
        updateAdditionalData(materialInstance.getId(), materialData);
    }
    SCMRevision scmRevision = pollResult.getLatestRevision();
    return scmRevision == null ? new Modifications() : new Modifications(getModification(scmRevision));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance)

Example 14 with MaterialPollResult

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

the class PluggableSCMMaterialPollerTest method shouldGetLatestModificationAlongWithAdditionalDataFromTheSCMRevision.

@Test
void shouldGetLatestModificationAlongWithAdditionalDataFromTheSCMRevision() {
    Date timestamp = new Date();
    Map<String, String> data = new HashMap<>();
    String dataKey = "revision_data";
    String dataValue = "revision_value";
    data.put(dataKey, dataValue);
    List<ModifiedFile> modifiedFiles = new ArrayList<>(asList(new ModifiedFile("f1", ModifiedAction.added), new ModifiedFile("f2", ModifiedAction.modified), new ModifiedFile("f3", ModifiedAction.deleted)));
    SCMRevision scmRevision = new SCMRevision("revision-123", timestamp, "user", "comment", data, modifiedFiles);
    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");
    assertThat(modifications.get(0).getAdditionalData()).isEqualTo(JsonHelper.toJsonString(data));
    assertThat(modifications.get(0).getModifiedFiles().size()).isEqualTo(3);
    com.thoughtworks.go.domain.materials.ModifiedFile f1 = new com.thoughtworks.go.domain.materials.ModifiedFile("f1", null, com.thoughtworks.go.domain.materials.ModifiedAction.added);
    com.thoughtworks.go.domain.materials.ModifiedFile f2 = new com.thoughtworks.go.domain.materials.ModifiedFile("f2", null, com.thoughtworks.go.domain.materials.ModifiedAction.modified);
    com.thoughtworks.go.domain.materials.ModifiedFile f3 = new com.thoughtworks.go.domain.materials.ModifiedFile("f3", null, com.thoughtworks.go.domain.materials.ModifiedAction.deleted);
    assertThat(new HashSet(modifications.get(0).getModifiedFiles())).isEqualTo(new HashSet(asList(f1, f2, f3)));
    assertConfiguration(scmConfiguration.getValue(), material.getScmConfig().getConfiguration());
    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) ModifiedFile(com.thoughtworks.go.plugin.access.scm.revision.ModifiedFile) 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 15 with MaterialPollResult

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

the class PluggableSCMMaterialPollerTest method shouldReturnEmptyModificationWhenSCMRevisionIsNull_latestModification.

@Test
void shouldReturnEmptyModificationWhenSCMRevisionIsNull_latestModification() {
    when(scmExtension.getLatestRevision(eq(material.getPluginId()), scmConfiguration.capture(), materialData.capture(), eq(flyweightFolderPath))).thenReturn(new MaterialPollResult());
    List<Modification> modifications = poller.latestModification(material, new File(flyweightFolderPath), 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) 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