Search in sources :

Example 1 with PackageMaterialRevision

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);
}
Also used : PackageMaterialRevision(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision) PackageRevision(com.thoughtworks.go.plugin.api.material.packagerepository.PackageRevision) PackageConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)

Example 2 with PackageMaterialRevision

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);
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) PackageMaterialRevision(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision) PackageRevision(com.thoughtworks.go.plugin.api.material.packagerepository.PackageRevision) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 3 with PackageMaterialRevision

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\"}");
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) PackageMaterialRevision(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision) PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) PackageRevision(com.thoughtworks.go.plugin.api.material.packagerepository.PackageRevision) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 4 with PackageMaterialRevision

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);
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) PackageMaterialRevision(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision) HashMap(java.util.HashMap) PackageRevision(com.thoughtworks.go.plugin.api.material.packagerepository.PackageRevision) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 5 with PackageMaterialRevision

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();
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) PackageMaterialRevision(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision) PackageRevision(com.thoughtworks.go.plugin.api.material.packagerepository.PackageRevision) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

PackageMaterialRevision (com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision)8 Date (java.util.Date)7 Test (org.junit.jupiter.api.Test)7 PackageRevision (com.thoughtworks.go.plugin.api.material.packagerepository.PackageRevision)6 Modification (com.thoughtworks.go.domain.materials.Modification)4 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)3 PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)2 PackageConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration)2 HashMap (java.util.HashMap)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 Configuration (com.thoughtworks.go.domain.config.Configuration)1 StringRevision (com.thoughtworks.go.domain.materials.mercurial.StringRevision)1 PluggableSCMMaterialRevision (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision)1 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)1 SCMPropertyConfiguration (com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration)1 LinkedHashMap (java.util.LinkedHashMap)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1