use of com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision in project gocd by gocd.
the class PackageMaterialPoller method modificationsSince.
@Override
public List<Modification> modificationsSince(final PackageMaterial material, File baseDir, final Revision revision, SubprocessExecutionContext execCtx) {
PackageMaterialRevision packageMaterialRevision = (PackageMaterialRevision) revision;
PackageRevision previouslyKnownRevision = new PackageRevision(packageMaterialRevision.getRevision(), packageMaterialRevision.getTimestamp(), null, packageMaterialRevision.getData());
PackageConfiguration packageConfiguration = buildPackageConfigurations(material.getPackageDefinition());
RepositoryConfiguration repositoryConfiguration = buildRepositoryConfigurations(material.getPackageDefinition().getRepository());
PackageRevision packageRevision = packageRepositoryExtension.latestModificationSince(material.getPluginId(), packageConfiguration, repositoryConfiguration, previouslyKnownRevision);
return getModifications(packageRevision);
}
use of com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision in project gocd by gocd.
the class PackageMaterialPollerTest method shouldTalkToPlugInToGetModificationsSinceAGivenRevision.
@Test
void shouldTalkToPlugInToGetModificationsSinceAGivenRevision() {
Date timestamp = new Date();
PackageMaterialRevision knownRevision = new PackageMaterialRevision("rev-122", timestamp);
ArgumentCaptor<PackageRevision> knownPackageRevision = ArgumentCaptor.forClass(PackageRevision.class);
PackageRevision latestRevision = new PackageRevision("rev-123", timestamp, "user");
when(packageRepositoryExtension.latestModificationSince(eq(material.getPluginId()), packageConfiguration.capture(), repositoryConfiguration.capture(), knownPackageRevision.capture())).thenReturn(latestRevision);
List<Modification> modifications = poller.modificationsSince(material, null, 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()).isNotNull();
assertConfiguration(packageConfiguration.getValue(), "name", "go-agent");
assertConfiguration(repositoryConfiguration.getValue(), "url", "http://some-url");
assertThat(knownPackageRevision.getValue().getRevision()).isEqualTo("rev-122");
assertThat(knownPackageRevision.getValue().getTimestamp()).isEqualTo(timestamp);
}
use of com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision in project gocd by gocd.
the class PackageMaterialPollerTest method shouldPopulatePackageModificationComment_WithTrackbackUrl_ForModificationsSince.
@Test
void shouldPopulatePackageModificationComment_WithTrackbackUrl_ForModificationsSince() throws Exception {
PackageRevision packageRevision = new PackageRevision(null, null, null, "some comment", "http://google.com");
PackageMaterialRevision previousRevision = new PackageMaterialRevision("rev", new Date());
PackageMaterial packageMaterial = MaterialsMother.packageMaterial();
when(packageRepositoryExtension.latestModificationSince(eq(packageMaterial.getPluginId()), any(com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration.class), any(RepositoryConfiguration.class), any(PackageRevision.class))).thenReturn(packageRevision);
List<Modification> modifications = poller.modificationsSince(packageMaterial, null, previousRevision, null);
JsonFluentAssert.assertThatJson(modifications.get(0).getComment()).isEqualTo("{\"COMMENT\":\"some comment\",\"TRACKBACK_URL\":\"http://google.com\",\"TYPE\":\"PACKAGE_MATERIAL\"}");
}
use of com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision in project gocd by gocd.
the class PackageMaterialPollerTest method shouldGetModificationsSinceAGivenRevisionAlongWithAdditionalDataFromThePackageRevision.
@Test
void shouldGetModificationsSinceAGivenRevisionAlongWithAdditionalDataFromThePackageRevision() {
String previousRevision = "rev-122";
Date timestamp = new Date();
HashMap<String, String> dataInPreviousRevision = new HashMap<>();
dataInPreviousRevision.put("1", "one");
PackageMaterialRevision knownRevision = new PackageMaterialRevision(previousRevision, timestamp, dataInPreviousRevision);
ArgumentCaptor<PackageRevision> knownPackageRevision = ArgumentCaptor.forClass(PackageRevision.class);
PackageRevision latestRevision = new PackageRevision("rev-123", timestamp, "user");
String dataKey = "2";
String dataValue = "two";
latestRevision.addData(dataKey, dataValue);
when(packageRepositoryExtension.latestModificationSince(eq(material.getPluginId()), packageConfiguration.capture(), repositoryConfiguration.capture(), knownPackageRevision.capture())).thenReturn(latestRevision);
List<Modification> modifications = poller.modificationsSince(material, null, knownRevision, null);
assertThat(knownPackageRevision.getValue().getRevision()).isEqualTo(previousRevision);
assertThat(knownPackageRevision.getValue().getTimestamp()).isEqualTo(timestamp);
assertThat(knownPackageRevision.getValue().getData()).isNotNull();
assertThat(knownPackageRevision.getValue().getData().size()).isEqualTo(dataInPreviousRevision.size());
assertThat(knownPackageRevision.getValue().getData().get("1")).isEqualTo(dataInPreviousRevision.get("1"));
HashMap<String, String> expected = new HashMap<>();
expected.put(dataKey, dataValue);
String expectedDataString = JsonHelper.toJsonString(expected);
Modification firstModification = modifications.get(0);
assertThat(firstModification.getRevision()).isEqualTo("rev-123");
assertThat(firstModification.getModifiedTime()).isEqualTo(timestamp);
assertThat(firstModification.getUserName()).isEqualTo("user");
assertThat(firstModification.getComment()).isNotNull();
assertThat(firstModification.getAdditionalData()).isEqualTo(expectedDataString);
}
use of com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision in project gocd by gocd.
the class PackageMaterialPollerTest method shouldReturnEmptyModificationWhenPackageRevisionIsNullForLatestModificationSince.
@Test
void shouldReturnEmptyModificationWhenPackageRevisionIsNullForLatestModificationSince() {
PackageMaterialRevision knownRevision = new PackageMaterialRevision("rev-122", new Date());
ArgumentCaptor<PackageRevision> knownPackageRevision = ArgumentCaptor.forClass(PackageRevision.class);
when(packageRepositoryExtension.latestModificationSince(eq(material.getPluginId()), packageConfiguration.capture(), repositoryConfiguration.capture(), knownPackageRevision.capture())).thenReturn(null);
List<Modification> modifications = poller.modificationsSince(material, null, knownRevision, null);
assertThat(modifications).isNotNull();
assertThat(modifications.isEmpty()).isTrue();
}
Aggregations