Search in sources :

Example 1 with PackageMaterialProperty

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

the class JsonMessageHandler1_0 method toPackageMaterialProperty.

private PackageMaterialProperty toPackageMaterialProperty(String key, Map configuration) {
    List<String> errors = new ArrayList<>();
    String defaultValue = null;
    try {
        defaultValue = (String) configuration.get("default-value");
    } catch (Exception e) {
        errors.add(format("'default-value' property for key '%s' should be of type string", key));
    }
    Boolean partOfIdentity = null;
    try {
        partOfIdentity = (Boolean) configuration.get("part-of-identity");
    } catch (Exception e) {
        errors.add(format("'part-of-identity' property for key '%s' should be of type boolean", key));
    }
    Boolean isSecure = null;
    try {
        isSecure = (Boolean) configuration.get("secure");
    } catch (Exception e) {
        errors.add(format("'secure' property for key '%s' should be of type boolean", key));
    }
    Boolean required = null;
    try {
        required = (Boolean) configuration.get("required");
    } catch (Exception e) {
        errors.add(format("'required' property for key '%s' should be of type boolean", key));
    }
    String displayName = null;
    try {
        displayName = (String) configuration.get("display-name");
    } catch (Exception e) {
        errors.add(format("'display-name' property for key '%s' should be of type string", key));
    }
    Integer displayOrder = null;
    try {
        displayOrder = configuration.get("display-order") == null ? null : Integer.parseInt((String) configuration.get("display-order"));
    } catch (Exception e) {
        errors.add(format("'display-order' property for key '%s' should be of type integer", key));
    }
    if (!errors.isEmpty()) {
        throw new RuntimeException(StringUtils.join(errors, ", "));
    }
    PackageMaterialProperty packageMaterialProperty = new PackageMaterialProperty(key);
    if (!isEmpty(defaultValue)) {
        packageMaterialProperty.withDefault(defaultValue);
    }
    if (partOfIdentity != null) {
        packageMaterialProperty.with(Property.PART_OF_IDENTITY, partOfIdentity);
    }
    if (isSecure != null) {
        packageMaterialProperty.with(Property.SECURE, isSecure);
    }
    if (required != null) {
        packageMaterialProperty.with(Property.REQUIRED, required);
    }
    if (!isEmpty(displayName)) {
        packageMaterialProperty.with(Property.DISPLAY_NAME, displayName);
    }
    if (displayOrder != null) {
        packageMaterialProperty.with(Property.DISPLAY_ORDER, displayOrder);
    }
    return packageMaterialProperty;
}
Also used : PackageMaterialProperty(com.thoughtworks.go.plugin.api.material.packagerepository.PackageMaterialProperty)

Example 2 with PackageMaterialProperty

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

the class PackageRepositoriesTest method shouldFailValidationIfMaterialWithDuplicateFingerprintIsFound.

@Test
public void shouldFailValidationIfMaterialWithDuplicateFingerprintIsFound() {
    com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration packageConfiguration = new com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration();
    packageConfiguration.add(new PackageMaterialProperty("k1"));
    packageConfiguration.add(new PackageMaterialProperty("k2").with(PART_OF_IDENTITY, false));
    PackageMetadataStore.getInstance().addMetadataFor("plugin", new PackageConfigurations(packageConfiguration));
    String expectedErrorMessage = "Cannot save package or repo, found duplicate packages. [Repo Name: 'repo-repo1', Package Name: 'pkg1'], [Repo Name: 'repo-repo1', Package Name: 'pkg3'], [Repo Name: 'repo-repo1', Package Name: 'pkg5']";
    PackageRepository repository = PackageRepositoryMother.create("repo1");
    PackageDefinition definition1 = PackageDefinitionMother.create("1", "pkg1", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1"))), repository);
    PackageDefinition definition2 = PackageDefinitionMother.create("2", "pkg2", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v2"))), repository);
    PackageDefinition definition3 = PackageDefinitionMother.create("3", "pkg3", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1"))), repository);
    PackageDefinition definition4 = PackageDefinitionMother.create("4", "pkg4", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("V1"))), repository);
    PackageDefinition definition5 = PackageDefinitionMother.create("5", "pkg5", new Configuration(new ConfigurationProperty(new ConfigurationKey("k1"), new ConfigurationValue("v1")), new ConfigurationProperty(new ConfigurationKey("k2"), new ConfigurationValue("v2"))), repository);
    repository.setPackages(new Packages(definition1, definition2, definition3, definition4, definition5));
    PackageRepositories packageRepositories = new PackageRepositories(repository);
    packageRepositories.validate(null);
    assertThat(definition1.errors().getAllOn(PackageDefinition.ID), is(asList(expectedErrorMessage)));
    assertThat(definition3.errors().getAllOn(PackageDefinition.ID), is(asList(expectedErrorMessage)));
    assertThat(definition3.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER).equals(definition1.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER)), is(true));
    assertThat(definition5.errors().getAllOn(PackageDefinition.ID), is(asList(expectedErrorMessage)));
    assertThat(definition5.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER).equals(definition1.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER)), is(true));
    assertThat(definition2.errors().getAllOn(PackageDefinition.ID), is(nullValue()));
    assertThat(definition2.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER).equals(definition1.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER)), is(false));
    assertThat(definition4.errors().getAllOn(PackageDefinition.ID), is(nullValue()));
    assertThat(definition4.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER).equals(definition1.getFingerprint(AbstractMaterialConfig.FINGERPRINT_DELIMITER)), is(false));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) Configuration(com.thoughtworks.go.domain.config.Configuration) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) PackageMaterialProperty(com.thoughtworks.go.plugin.api.material.packagerepository.PackageMaterialProperty) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 3 with PackageMaterialProperty

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

the class MagicalGoConfigXmlLoaderTest method shouldFailValidationIfPackageDefinitionWithDuplicateFingerprintExists.

@Test
public void shouldFailValidationIfPackageDefinitionWithDuplicateFingerprintExists() throws Exception {
    com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration packageConfiguration = new com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration();
    packageConfiguration.add(new PackageMaterialProperty("PKG-KEY1"));
    RepositoryConfiguration repositoryConfiguration = new RepositoryConfiguration();
    repositoryConfiguration.add(new PackageMaterialProperty("REPO-KEY1"));
    repositoryConfiguration.add(new PackageMaterialProperty("REPO-KEY2").with(REQUIRED, false).with(PART_OF_IDENTITY, false));
    repositoryConfiguration.add(new PackageMaterialProperty("REPO-KEY3").with(REQUIRED, false).with(PART_OF_IDENTITY, false).with(SECURE, true));
    PackageMetadataStore.getInstance().addMetadataFor("plugin-1", new PackageConfigurations(packageConfiguration));
    RepositoryMetadataStore.getInstance().addMetadataFor("plugin-1", new PackageConfigurations(repositoryConfiguration));
    String xml = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + "<repositories>\n" + "    <repository id='repo-id-1' name='name-1'>\n" + "		<pluginConfiguration id='plugin-1' version='1.0'/>\n" + "      <configuration>\n" + "        <property>\n" + "          <key>REPO-KEY1</key>\n" + "          <value>repo-key1</value>\n" + "        </property>\n" + "        <property>\n" + "          <key>REPO-KEY2</key>\n" + "          <value>repo-key2</value>\n" + "        </property>\n" + "        <property>\n" + "          <key>REPO-KEY3</key>\n" + "          <value>repo-key3</value>\n" + "        </property>\n" + "      </configuration>\n" + "      <packages>\n" + "        <package id='package-id-1' name='name-1'>\n" + "          <configuration>\n" + "            <property>\n" + "              <key>PKG-KEY1</key>\n" + "              <value>pkg-key1</value>\n" + "            </property>\n" + "          </configuration>\n" + "        </package>\n" + "      </packages>\n" + "    </repository>\n" + "    <repository id='repo-id-2' name='name-2'>\n" + "		<pluginConfiguration id='plugin-1' version='1.0'/>\n" + "      <configuration>\n" + "        <property>\n" + "          <key>REPO-KEY1</key>\n" + "          <value>repo-key1</value>\n" + "        </property>\n" + "        <property>\n" + "          <key>REPO-KEY2</key>\n" + "          <value>another-repo-key2</value>\n" + "        </property>\n" + "        <property>\n" + "          <key>REPO-KEY3</key>\n" + "          <value>another-repo-key3</value>\n" + "        </property>\n" + "      </configuration>\n" + "      <packages>\n" + "        <package id='package-id-2' name='name-2'>\n" + "          <configuration>\n" + "            <property>\n" + "              <key>PKG-KEY1</key>\n" + "              <value>pkg-key1</value>\n" + "            </property>\n" + "          </configuration>\n" + "        </package>\n" + "      </packages>\n" + "    </repository>\n" + "  </repositories>" + "</cruise>";
    try {
        xmlLoader.loadConfigHolder(xml);
        fail("should have thrown duplicate fingerprint exception");
    } catch (GoConfigInvalidException e) {
        assertThat(e.getMessage(), is("Cannot save package or repo, found duplicate packages. [Repo Name: 'name-1', Package Name: 'name-1'], [Repo Name: 'name-2', Package Name: 'name-2']"));
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) PackageMaterialProperty(com.thoughtworks.go.plugin.api.material.packagerepository.PackageMaterialProperty) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Example 4 with PackageMaterialProperty

use of com.thoughtworks.go.plugin.api.material.packagerepository.PackageMaterialProperty 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 5 with PackageMaterialProperty

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

the class PackageRepositoryExtensionTest method setUp.

@Before
public void setUp() throws Exception {
    initMocks(this);
    extension = new PackageRepositoryExtension(pluginManager);
    pluginSettingsConfiguration = new PluginSettingsConfiguration();
    repositoryConfiguration = new RepositoryConfiguration();
    repositoryConfiguration.add(new PackageMaterialProperty("key-one", "value-one"));
    repositoryConfiguration.add(new PackageMaterialProperty("key-two", "value-two"));
    packageConfiguration = new com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration();
    packageConfiguration.add(new PackageMaterialProperty("key-three", "value-three"));
    packageConfiguration.add(new PackageMaterialProperty("key-four", "value-four"));
    requestArgumentCaptor = ArgumentCaptor.forClass(GoPluginApiRequest.class);
    when(pluginManager.resolveExtensionVersion(PLUGIN_ID, asList("1.0"))).thenReturn("1.0");
}
Also used : GoPluginApiRequest(com.thoughtworks.go.plugin.api.request.GoPluginApiRequest) PackageMaterialProperty(com.thoughtworks.go.plugin.api.material.packagerepository.PackageMaterialProperty) PluginSettingsConfiguration(com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) Before(org.junit.Before)

Aggregations

PackageMaterialProperty (com.thoughtworks.go.plugin.api.material.packagerepository.PackageMaterialProperty)7 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)5 Test (org.junit.Test)3 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)2 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)2 Before (org.junit.Before)2 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)1 Configuration (com.thoughtworks.go.domain.config.Configuration)1 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)1 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)1 PluginSettingsConfiguration (com.thoughtworks.go.plugin.access.common.settings.PluginSettingsConfiguration)1 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)1 PackageConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration)1 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1