use of com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult in project gocd by gocd.
the class PluggableSCMMaterialUpdaterIntegrationTest method shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModificationsSince.
@Test
public void shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModificationsSince() throws Exception {
final PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
final MaterialInstance materialInstance = material.createMaterialInstance();
Map<String, String> oldData = new HashMap<>();
oldData.put("k1", "v1");
materialInstance.setAdditionalData(new GsonBuilder().create().toJson(oldData));
materialRepository.saveOrUpdate(materialInstance);
Map<String, String> newData = new HashMap<>(oldData);
newData.put("k2", "v2");
when(scmExtension.latestModificationSince(any(String.class), any(SCMPropertyConfiguration.class), any(Map.class), any(String.class), any(SCMRevision.class))).thenReturn(new MaterialPollResult(newData, new SCMRevision()));
mockSCMExtensionInPoller();
scmMaterialUpdater = new ScmMaterialUpdater(materialRepository, materialChecker, subprocessExecutionContext, materialService);
pluggableSCMMaterialUpdater = new PluggableSCMMaterialUpdater(materialRepository, scmMaterialUpdater, transactionTemplate);
transactionTemplate.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus transactionStatus) {
pluggableSCMMaterialUpdater.insertLatestOrNewModifications(material, materialInstance, new File(""), new Modifications(new Modification()));
return null;
}
});
MaterialInstance actualInstance = materialRepository.findMaterialInstance(material);
assertThat(actualInstance.getAdditionalDataMap(), is(newData));
}
use of com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult 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);
}
use of com.thoughtworks.go.plugin.access.scm.material.MaterialPollResult in project gocd by gocd.
the class PluggableSCMMaterialPollerTest method shouldTalkToPlugInToGetLatestModifications.
@Test
void shouldTalkToPlugInToGetLatestModifications() {
Date timestamp = new Date();
SCMRevision scmRevision = new SCMRevision("revision-123", timestamp, "user", "comment", null, null);
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");
assertConfiguration(scmConfiguration.getValue(), "k1", "v1");
assertConfiguration(scmConfiguration.getValue(), "k2", "v2");
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 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.plugin.access.scm.material.MaterialPollResult 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");
}
Aggregations