Search in sources :

Example 6 with MaterialPollResult

use of com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult 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 7 with MaterialPollResult

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

the class JsonMessageHandler1_0Test method shouldBuildSCMRevisionsFromLatestRevisionsSinceResponse.

@Test
public void shouldBuildSCMRevisionsFromLatestRevisionsSinceResponse() throws Exception {
    String r1 = "{\"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 r2 = "{\"revision\":\"r2\",\"timestamp\":\"2011-07-14T19:43:37.101Z\",\"user\":\"new-user\",\"revisionComment\":\"comment\",\"data\":{\"dataKeyTwo\":\"data-value-two\",\"dataKeyOne\":\"data-value-one\"}," + "\"modifiedFiles\":[{\"fileName\":\"f1\",\"action\":\"added\"}]}";
    String responseBody = "{\"revisions\":[" + r1 + "," + r2 + "]}";
    MaterialPollResult pollResult = messageHandler.responseMessageForLatestRevisionsSince(responseBody);
    assertThat(pollResult.getMaterialData(), is(nullValue()));
    List<SCMRevision> scmRevisions = pollResult.getRevisions();
    assertThat(scmRevisions.size(), is(2));
    assertSCMRevision(scmRevisions.get(0), "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)));
    assertSCMRevision(scmRevisions.get(1), "r2", "new-user", "2011-07-14T19:43:37.101Z", "comment", asList(new ModifiedFile("f1", ModifiedAction.added)));
}
Also used : 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) Test(org.junit.jupiter.api.Test)

Example 8 with MaterialPollResult

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

the class SCMExtensionTest method shouldTalkToPluginToGetLatestModification.

@Test
public void shouldTalkToPluginToGetLatestModification() throws Exception {
    String flyweight = "flyweight";
    when(jsonMessageHandler.requestMessageForLatestRevision(scmPropertyConfiguration, materialData, flyweight)).thenReturn(requestBody);
    MaterialPollResult deserializedResponse = new MaterialPollResult();
    when(jsonMessageHandler.responseMessageForLatestRevision(responseBody)).thenReturn(deserializedResponse);
    MaterialPollResult response = scmExtension.getLatestRevision(PLUGIN_ID, scmPropertyConfiguration, materialData, flyweight);
    assertRequest(requestArgumentCaptor.getValue(), SCM_EXTENSION, "1.0", SCMExtension.REQUEST_LATEST_REVISION, requestBody);
    verify(jsonMessageHandler).requestMessageForLatestRevision(scmPropertyConfiguration, materialData, flyweight);
    verify(jsonMessageHandler).responseMessageForLatestRevision(responseBody);
    assertSame(response, deserializedResponse);
}
Also used : MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) Test(org.junit.jupiter.api.Test)

Example 9 with MaterialPollResult

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

the class SCMExtensionTest method shouldTalkToPluginToGetLatestModificationSinceLastRevision.

@Test
public void shouldTalkToPluginToGetLatestModificationSinceLastRevision() throws Exception {
    String flyweight = "flyweight";
    SCMRevision previouslyKnownRevision = new SCMRevision();
    when(jsonMessageHandler.requestMessageForLatestRevisionsSince(scmPropertyConfiguration, materialData, flyweight, previouslyKnownRevision)).thenReturn(requestBody);
    MaterialPollResult deserializedResponse = new MaterialPollResult();
    when(jsonMessageHandler.responseMessageForLatestRevisionsSince(responseBody)).thenReturn(deserializedResponse);
    MaterialPollResult response = scmExtension.latestModificationSince(PLUGIN_ID, scmPropertyConfiguration, materialData, flyweight, previouslyKnownRevision);
    assertRequest(requestArgumentCaptor.getValue(), SCM_EXTENSION, "1.0", SCMExtension.REQUEST_LATEST_REVISIONS_SINCE, requestBody);
    verify(jsonMessageHandler).requestMessageForLatestRevisionsSince(scmPropertyConfiguration, materialData, flyweight, previouslyKnownRevision);
    verify(jsonMessageHandler).responseMessageForLatestRevisionsSince(responseBody);
    assertSame(response, deserializedResponse);
}
Also used : MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) SCMRevision(com.thoughtworks.go.plugin.access.scm.revision.SCMRevision) Test(org.junit.jupiter.api.Test)

Example 10 with MaterialPollResult

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

the class JsonMessageHandler1_0Test method shouldBuildNullSCMRevisionFromLatestRevisionsSinceWhenEmptyResponse.

@Test
public void shouldBuildNullSCMRevisionFromLatestRevisionsSinceWhenEmptyResponse() throws Exception {
    MaterialPollResult pollResult = messageHandler.responseMessageForLatestRevisionsSince("");
    assertThat(pollResult.getRevisions(), nullValue());
    assertThat(pollResult.getMaterialData(), nullValue());
    pollResult = messageHandler.responseMessageForLatestRevisionsSince(null);
    assertThat(pollResult.getRevisions(), nullValue());
    assertThat(pollResult.getMaterialData(), nullValue());
}
Also used : MaterialPollResult(com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult) 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