Search in sources :

Example 11 with PackageRevision

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));
}
Also used : PackageRevision(com.thoughtworks.go.plugin.api.material.packagerepository.PackageRevision) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.jupiter.api.Test)

Example 12 with PackageRevision

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);
}
Also used : 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 13 with 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()));
    }
}
Also used : PackageRevision(com.thoughtworks.go.plugin.api.material.packagerepository.PackageRevision) SimpleDateFormat(java.text.SimpleDateFormat)

Example 14 with PackageRevision

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"));
}
Also used : SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) Configuration(com.thoughtworks.go.domain.config.Configuration) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration) PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) 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) Date(java.util.Date) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with PackageRevision

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"));
}
Also used : PackageMaterialRevision(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision) SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) Configuration(com.thoughtworks.go.domain.config.Configuration) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration) PackageMaterial(com.thoughtworks.go.config.materials.PackageMaterial) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) 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) Date(java.util.Date) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

PackageRevision (com.thoughtworks.go.plugin.api.material.packagerepository.PackageRevision)17 Test (org.junit.jupiter.api.Test)14 Date (java.util.Date)9 Modification (com.thoughtworks.go.domain.materials.Modification)7 PackageMaterialRevision (com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision)6 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)6 PackageMaterial (com.thoughtworks.go.config.materials.PackageMaterial)4 PackageConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration)4 SimpleDateFormat (java.text.SimpleDateFormat)3 Configuration (com.thoughtworks.go.domain.config.Configuration)2 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)2 SCMPropertyConfiguration (com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration)2 HashMap (java.util.HashMap)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1