use of com.thoughtworks.go.plugin.api.material.packagerepository.PackageRevision in project gocd by gocd.
the class JsonMessageHandler1_0Test method shouldBuildRequestBodyForLatestRevisionSinceRequest.
@Test
public void shouldBuildRequestBodyForLatestRevisionSinceRequest() throws Exception {
Date timestamp = new SimpleDateFormat(DATE_FORMAT).parse("2011-07-13T19:43:37.100Z");
Map data = new LinkedHashMap();
data.put("dataKeyOne", "data-value-one");
data.put("dataKeyTwo", "data-value-two");
PackageRevision previouslyKnownRevision = new PackageRevision("abc.rpm", timestamp, "someuser", "comment", null, data);
String requestBody = messageHandler.requestMessageForLatestRevisionSince(packageConfiguration, repositoryConfiguration, previouslyKnownRevision);
String expectedValue = "{\"repository-configuration\":{\"key-one\":{\"value\":\"value-one\"},\"key-two\":{\"value\":\"value-two\"}}," + "\"package-configuration\":{\"key-three\":{\"value\":\"value-three\"},\"key-four\":{\"value\":\"value-four\"}}," + "\"previous-revision\":{\"revision\":\"abc.rpm\",\"timestamp\":\"2011-07-13T19:43:37.100Z\",\"data\":{\"dataKeyOne\":\"data-value-one\",\"dataKeyTwo\":\"data-value-two\"}}}";
assertThat(requestBody, is(expectedValue));
}
use of com.thoughtworks.go.plugin.api.material.packagerepository.PackageRevision in project gocd by gocd.
the class PackageMaterialPoller method latestModification.
@Override
public List<Modification> latestModification(final PackageMaterial material, File baseDir, SubprocessExecutionContext execCtx) {
PackageConfiguration packageConfiguration = buildPackageConfigurations(material.getPackageDefinition());
RepositoryConfiguration repositoryConfiguration = buildRepositoryConfigurations(material.getPackageDefinition().getRepository());
PackageRevision packageRevision = packageRepositoryExtension.getLatestRevision(material.getPluginId(), packageConfiguration, repositoryConfiguration);
return getModifications(packageRevision);
}
use of com.thoughtworks.go.plugin.api.material.packagerepository.PackageRevision in project gocd by gocd.
the class JsonMessageHandler1_0 method toPackageRevision.
PackageRevision toPackageRevision(String responseBody) {
try {
Map map;
try {
map = parseResponseToMap(responseBody);
} catch (Exception e) {
throw new RuntimeException("Package revision should be returned as a map");
}
if (map == null || map.isEmpty()) {
return null;
}
String revision;
try {
revision = (String) map.get("revision");
} catch (Exception e) {
throw new RuntimeException("Package revision should be of type string");
}
String revisionComment;
try {
revisionComment = (String) map.get("revisionComment");
} catch (Exception e) {
throw new RuntimeException("Package revision comment should be of type string");
}
String user;
try {
user = (String) map.get("user");
} catch (Exception e) {
throw new RuntimeException("Package revision user should be of type string");
}
String trackbackUrl;
try {
trackbackUrl = (String) map.get("trackbackUrl");
} catch (Exception e) {
throw new RuntimeException("Package revision trackbackUrl should be of type string");
}
Date timestamp;
try {
String timestampString = (String) map.get("timestamp");
timestamp = new SimpleDateFormat(DATE_PATTERN).parse(timestampString);
} catch (Exception e) {
throw new RuntimeException("Package revision timestamp should be of type string with format yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
}
Map data = (Map) map.get("data");
PackageRevision packageRevision = new PackageRevision(revision, timestamp, user, revisionComment, trackbackUrl, data);
return packageRevision;
} catch (Exception e) {
throw new RuntimeException(format("Unable to de-serialize json response. %s", e.getMessage()));
}
}
use of com.thoughtworks.go.plugin.api.material.packagerepository.PackageRevision in project gocd by gocd.
the class MaterialServiceTest method shouldGetLatestModificationForPackageMaterial.
@Test
public void shouldGetLatestModificationForPackageMaterial() {
PackageMaterial material = new PackageMaterial();
PackageDefinition packageDefinition = create("id", "package", new Configuration(), PackageRepositoryMother.create("id", "name", "plugin-id", "plugin-version", new Configuration()));
material.setPackageDefinition(packageDefinition);
when(packageRepositoryExtension.getLatestRevision(eq("plugin-id"), any(PackageConfiguration.class), any(RepositoryConfiguration.class))).thenReturn(new PackageRevision("blah-123", new Date(), "user"));
List<Modification> modifications = materialService.latestModification(material, null, null);
assertThat(modifications.get(0).getRevision(), is("blah-123"));
}
use of com.thoughtworks.go.plugin.api.material.packagerepository.PackageRevision in project gocd by gocd.
the class MaterialServiceTest method shouldGetModificationSinceAGivenRevision.
@Test
public void shouldGetModificationSinceAGivenRevision() {
PackageMaterial material = new PackageMaterial();
PackageDefinition packageDefinition = create("id", "package", new Configuration(), PackageRepositoryMother.create("id", "name", "plugin-id", "plugin-version", new Configuration()));
material.setPackageDefinition(packageDefinition);
when(packageRepositoryExtension.latestModificationSince(eq("plugin-id"), any(PackageConfiguration.class), any(RepositoryConfiguration.class), any(PackageRevision.class))).thenReturn(new PackageRevision("new-revision-456", new Date(), "user"));
List<Modification> modifications = materialService.modificationsSince(material, null, new PackageMaterialRevision("revision-124", new Date()), null);
assertThat(modifications.get(0).getRevision(), is("new-revision-456"));
}
Aggregations