Search in sources :

Example 11 with GoConfigInvalidException

use of com.thoughtworks.go.config.exceptions.GoConfigInvalidException in project gocd by gocd.

the class SCMConfigXmlWriterTest method shouldNotAllowSCMWithInvalidName.

@Test
public void shouldNotAllowSCMWithInvalidName() throws Exception {
    Configuration configuration = new Configuration(getConfigurationProperty("url", false, "http://go"));
    CruiseConfig configToSave = new BasicCruiseConfig();
    SCM scm = createSCM("id", "name with space", "plugin-id", "1.0", configuration);
    configToSave.setSCMs(new SCMs(scm));
    try {
        xmlWriter.write(configToSave, output, false);
        fail("should not have allowed two SCMs with same id");
    } catch (GoConfigInvalidException e) {
        assertThat(e.getMessage(), is("Invalid SCM name 'name with space'. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters."));
    }
}
Also used : SCMs(com.thoughtworks.go.domain.scm.SCMs) SCM(com.thoughtworks.go.domain.scm.SCM) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) Test(org.junit.Test)

Example 12 with GoConfigInvalidException

use of com.thoughtworks.go.config.exceptions.GoConfigInvalidException in project gocd by gocd.

the class SCMConfigXmlWriterTest method shouldNotAllowMultipleSCMsWithSameName.

@Test
public void shouldNotAllowMultipleSCMsWithSameName() throws Exception {
    Configuration scmConfiguration = new Configuration(getConfigurationProperty("url", false, "http://go"));
    CruiseConfig configToSave = new BasicCruiseConfig();
    SCM scm1 = createSCM("id1", "scm-name-1", "plugin-id", "1.0", scmConfiguration);
    SCM scm2 = createSCM("id2", "scm-name-2", "plugin-id", "1.0", scmConfiguration);
    configToSave.setSCMs(new SCMs(scm1, scm2));
    try {
        xmlWriter.write(configToSave, output, false);
        fail("should not have allowed two SCMs with same id");
    } catch (GoConfigInvalidException e) {
        assertThat(e.getMessage(), is("Cannot save SCM, found duplicate SCMs. scm-name-1, scm-name-2"));
    }
}
Also used : SCMs(com.thoughtworks.go.domain.scm.SCMs) SCM(com.thoughtworks.go.domain.scm.SCM) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) Test(org.junit.Test)

Example 13 with GoConfigInvalidException

use of com.thoughtworks.go.config.exceptions.GoConfigInvalidException 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 14 with GoConfigInvalidException

use of com.thoughtworks.go.config.exceptions.GoConfigInvalidException in project gocd by gocd.

the class AgentConfigService method updateAgent.

public AgentConfig updateAgent(UpdateConfigCommand command, String uuid, HttpOperationResult result, Username currentUser) {
    AgentConfigsUpdateValidator validator = new AgentConfigsUpdateValidator(asList(uuid));
    try {
        updateAgents(command, validator, currentUser);
        result.ok(String.format("Updated agent with uuid %s.", uuid));
    } catch (Exception e) {
        if (e instanceof GoConfigInvalidException) {
            result.unprocessibleEntity("Updating agent failed:", e.getMessage(), HealthStateType.general(HealthStateScope.GLOBAL));
            GoConfigInvalidException goConfigInvalidException = (GoConfigInvalidException) e;
            return goConfigInvalidException.getCruiseConfig().agents().getAgentByUuid(uuid);
        } else {
            result.internalServerError("Updating agent failed: " + e.getMessage(), HealthStateType.general(HealthStateScope.GLOBAL));
            return null;
        }
    }
    return goConfigService.agents().getAgentByUuid(uuid);
}
Also used : AgentConfigsUpdateValidator(com.thoughtworks.go.validation.AgentConfigsUpdateValidator) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException)

Example 15 with GoConfigInvalidException

use of com.thoughtworks.go.config.exceptions.GoConfigInvalidException in project gocd by gocd.

the class MagicalGoConfigXmlWriter method write.

public void write(CruiseConfig configForEdit, OutputStream output, boolean skipPreprocessingAndValidation) throws Exception {
    LOGGER.debug("[Serializing Config] Starting to write. Validation skipped? " + skipPreprocessingAndValidation);
    MagicalGoConfigXmlLoader loader = new MagicalGoConfigXmlLoader(configCache, registry);
    if (!configForEdit.getOrigin().isLocal()) {
        throw new GoConfigInvalidException(configForEdit, "Attempted to save merged configuration with patials");
    }
    if (!skipPreprocessingAndValidation) {
        loader.preprocessAndValidate(configForEdit);
        LOGGER.debug("[Serializing Config] Done with cruise config validators.");
    }
    Document document = createEmptyCruiseConfigDocument();
    write(configForEdit, document.getRootElement(), configCache, registry);
    LOGGER.debug("[Serializing Config] XSD and DOM validation.");
    verifyXsdValid(document);
    MagicalGoConfigXmlLoader.validateDom(document.getRootElement(), registry);
    LOGGER.info("[Serializing Config] Generating config partial.");
    XmlUtils.writeXml(document, output);
    LOGGER.debug("[Serializing Config] Finished writing config partial.");
}
Also used : XmlUtils.buildXmlDocument(com.thoughtworks.go.util.XmlUtils.buildXmlDocument) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException)

Aggregations

GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)17 Test (org.junit.Test)13 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)4 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)4 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)4 Packages (com.thoughtworks.go.domain.packagerepository.Packages)4 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)3 FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)3 ConfigErrors (com.thoughtworks.go.domain.ConfigErrors)3 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)2 SCM (com.thoughtworks.go.domain.scm.SCM)2 SCMs (com.thoughtworks.go.domain.scm.SCMs)2 IOException (java.io.IOException)2 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 AgentConfig (com.thoughtworks.go.config.AgentConfig)1 GoConfigDao (com.thoughtworks.go.config.GoConfigDao)1 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)1 ConfigMergeException (com.thoughtworks.go.config.exceptions.ConfigMergeException)1 GoConfigInvalidMergeException (com.thoughtworks.go.config.exceptions.GoConfigInvalidMergeException)1 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)1