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