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");
}
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)));
}
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);
}
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);
}
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());
}
Aggregations