Search in sources :

Example 6 with PackageConfiguration

use of com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration in project gocd by gocd.

the class JsonMessageHandler1_0Test method setUp.

@Before
public void setUp() throws Exception {
    messageHandler = new JsonMessageHandler1_0();
    repositoryConfiguration = new RepositoryConfiguration();
    repositoryConfiguration.add(new PackageMaterialProperty("key-one", "value-one"));
    repositoryConfiguration.add(new PackageMaterialProperty("key-two", "value-two"));
    packageConfiguration = new PackageConfiguration();
    packageConfiguration.add(new PackageMaterialProperty("key-three", "value-three"));
    packageConfiguration.add(new PackageMaterialProperty("key-four", "value-four"));
}
Also used : PackageMaterialProperty(com.thoughtworks.go.plugin.api.material.packagerepository.PackageMaterialProperty) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) PackageConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration) Before(org.junit.Before)

Example 7 with PackageConfiguration

use of com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration in project gocd by gocd.

the class JsonMessageHandler1_0 method responseMessageForPackageConfiguration.

@Override
public PackageConfiguration responseMessageForPackageConfiguration(String responseBody) {
    try {
        PackageConfiguration packageConfiguration = new PackageConfiguration();
        Map<String, Map> configurations;
        try {
            configurations = parseResponseToMap(responseBody);
        } catch (Exception e) {
            throw new RuntimeException("Package configuration should be returned as a map");
        }
        if (configurations == null || configurations.isEmpty()) {
            throw new RuntimeException("Empty response body");
        }
        for (String key : configurations.keySet()) {
            if (isEmpty(key)) {
                throw new RuntimeException("Package configuration key cannot be empty");
            }
            if (!(configurations.get(key) instanceof Map)) {
                throw new RuntimeException(format("Package configuration properties for key '%s' should be represented as a Map", key));
            }
            packageConfiguration.add(toPackageMaterialProperty(key, configurations.get(key)));
        }
        return packageConfiguration;
    } catch (RuntimeException e) {
        throw new RuntimeException(format("Unable to de-serialize json response. %s", e.getMessage()));
    }
}
Also used : PackageConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration)

Aggregations

PackageConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration)7 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)4 PackageRevision (com.thoughtworks.go.plugin.api.material.packagerepository.PackageRevision)2 Test (org.junit.Test)2 PackageMaterialRevision (com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision)1 PackageMaterialProperty (com.thoughtworks.go.plugin.api.material.packagerepository.PackageMaterialProperty)1 Before (org.junit.Before)1