use of com.thoughtworks.go.plugin.access.scm.revision.SCMRevision in project gocd by gocd.
the class PluggableSCMMaterialPollerTest method shouldTalkToPlugInToGetLatestModifications.
@Test
public 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(), is("revision-123"));
assertThat(modifications.get(0).getModifiedTime(), is(timestamp));
assertThat(modifications.get(0).getUserName(), is("user"));
assertThat(modifications.get(0).getComment(), is("comment"));
assertConfiguration(scmConfiguration.getValue(), "k1", "v1");
assertConfiguration(scmConfiguration.getValue(), "k2", "v2");
assertThat(materialData.getValue().size(), is(1));
assertThat(materialData.getValue().get("mk-1"), is("mv-1"));
}
use of com.thoughtworks.go.plugin.access.scm.revision.SCMRevision in project gocd by gocd.
the class JsonMessageHandler1_0 method toSCMRevisions.
List<SCMRevision> toSCMRevisions(Map map) {
try {
List<SCMRevision> scmRevisions = new ArrayList<>();
if (map == null || map.get("revisions") == null) {
return scmRevisions;
}
List revisionMaps = null;
try {
revisionMaps = (List) map.get("revisions");
} catch (Exception e) {
throw new RuntimeException("'revisions' should be of type list of map");
}
if (revisionMaps != null && !revisionMaps.isEmpty()) {
for (Object revision : revisionMaps) {
if (!(revision instanceof Map)) {
throw new RuntimeException("SCM revision should be of type map");
}
}
for (Object revisionObj : revisionMaps) {
Map revisionMap = (Map) revisionObj;
SCMRevision scmRevision = getScmRevisionFromMap(revisionMap);
scmRevisions.add(scmRevision);
}
}
return scmRevisions;
} catch (Exception e) {
throw new RuntimeException(format("Unable to de-serialize json response. %s", e.getMessage()));
}
}
use of com.thoughtworks.go.plugin.access.scm.revision.SCMRevision in project gocd by gocd.
the class PluggableSCMMaterialUpdaterIntegrationTest method shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModification.
@Test
public void shouldUpdateMaterialInstanceWhenAdditionalDataIsUpdatedDuringLatestModification() throws Exception {
final PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial();
final MaterialInstance materialInstance = material.createMaterialInstance();
materialRepository.saveOrUpdate(materialInstance);
Map<String, String> data = new HashMap<>();
data.put("k1", "v1");
when(scmExtension.getLatestRevision(any(String.class), any(SCMPropertyConfiguration.class), any(Map.class), any(String.class))).thenReturn(new MaterialPollResult(data, 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());
return null;
}
});
MaterialInstance actualInstance = materialRepository.findMaterialInstance(material);
assertThat(actualInstance.getAdditionalDataMap(), is(data));
}
use of com.thoughtworks.go.plugin.access.scm.revision.SCMRevision in project gocd by gocd.
the class SCMRevisionTest method shouldThrowExceptionIfDataKeyContainsCharactersOtherThanAlphaNumericAndUnderScoreCharacters.
@Test
public void shouldThrowExceptionIfDataKeyContainsCharactersOtherThanAlphaNumericAndUnderScoreCharacters() throws Exception {
SCMRevision scmRevision = new SCMRevision("rev123", new Date(), "loser", null, null, null);
try {
scmRevision.addData("HEL-LO-WORLD", "value");
fail("should have thrown exception");
} catch (InvalidSCMRevisionDataException e) {
assertThat(e.getMessage(), is("Key 'HEL-LO-WORLD' is invalid. Key names should consists of only alphanumeric characters and/or underscores."));
}
}
use of com.thoughtworks.go.plugin.access.scm.revision.SCMRevision in project gocd by gocd.
the class SCMExtensionTest method shouldTalkToPluginToCheckout.
@Test
public void shouldTalkToPluginToCheckout() throws Exception {
String destination = "destination";
SCMRevision revision = new SCMRevision();
when(jsonMessageHandler.requestMessageForCheckout(scmPropertyConfiguration, destination, revision)).thenReturn(requestBody);
Result deserializedResponse = new Result();
when(jsonMessageHandler.responseMessageForCheckout(responseBody)).thenReturn(deserializedResponse);
Result response = scmExtension.checkout(PLUGIN_ID, scmPropertyConfiguration, destination, revision);
assertRequest(requestArgumentCaptor.getValue(), SCMExtension.EXTENSION_NAME, "1.0", SCMExtension.REQUEST_CHECKOUT, requestBody);
verify(jsonMessageHandler).requestMessageForCheckout(scmPropertyConfiguration, destination, revision);
verify(jsonMessageHandler).responseMessageForCheckout(responseBody);
assertSame(response, deserializedResponse);
}
Aggregations