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