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."));
}
}
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"));
}
}
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']"));
}
}
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);
}
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.");
}
Aggregations