use of com.thoughtworks.go.util.XsdValidationException in project gocd by gocd.
the class SCMConfigXmlLoaderTest method shouldThrowXsdValidationWhenSCMNamesAreDuplicate.
@Test
public void shouldThrowXsdValidationWhenSCMNamesAreDuplicate() throws Exception {
String xml = "<cruise schemaVersion='" + GoConstants.CONFIG_SCHEMA_VERSION + "'><scms>\n" + format(VALID_SCM_WITH_ID_NAME, "1", "scm-name") + format(VALID_SCM_WITH_ID_NAME, "2", "scm-name") + " </scms></cruise>";
try {
xmlLoader.loadConfigHolder(xml);
fail("should have thrown XsdValidationException");
} catch (XsdValidationException e) {
assertThat(e.getMessage(), anyOf(is("Duplicate unique value [scm-name] declared for identity constraint of element \"scms\"."), is("Duplicate unique value [scm-name] declared for identity constraint \"uniqueSCMName\" of element \"scms\".")));
}
}
use of com.thoughtworks.go.util.XsdValidationException in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldFailValidationIfPackageTypeMaterialForPipelineHasARefToNonExistantPackage.
@Test
public void shouldFailValidationIfPackageTypeMaterialForPipelineHasARefToNonExistantPackage() throws Exception {
String packageId = "does-not-exist";
PackageMaterialConfig packageMaterialConfig = new PackageMaterialConfig(packageId);
PackageRepository repository = com.thoughtworks.go.domain.packagerepository.PackageRepositoryMother.create("repo-id", "repo-name", "pluginid", "version", new Configuration(com.thoughtworks.go.domain.packagerepository.ConfigurationPropertyMother.create("k1", false, "v1")));
packageMaterialConfig.setPackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinitionMother.create("does-not-exist", "package-name", new Configuration(com.thoughtworks.go.domain.packagerepository.ConfigurationPropertyMother.create("k2", false, "v2")), repository));
JobConfig jobConfig = new JobConfig("ls");
jobConfig.addTask(new AntTask());
cruiseConfig.addPipeline("default", com.thoughtworks.go.helper.PipelineConfigMother.pipelineConfig("test", new MaterialConfigs(packageMaterialConfig), new JobConfigs(jobConfig)));
try {
xmlWriter.write(cruiseConfig, output, false);
fail("should not allow this");
} catch (XsdValidationException exception) {
assertThat(exception.getMessage(), is("Key 'packageIdReferredByMaterial' with value 'does-not-exist' not found for identity constraint of element 'cruise'."));
}
}
use of com.thoughtworks.go.util.XsdValidationException in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldValidateLeadingAndTrailingSpacesOnExecCommandInReasonableTime.
@Test
@Timeout(1)
public void shouldValidateLeadingAndTrailingSpacesOnExecCommandInReasonableTime() throws Exception {
// See https://github.com/gocd/gocd/issues/3551
// This is only reproducible on longish strings, so don't try shortening the exec task length...
String longPath = StringUtils.repeat("f", 100);
CruiseConfig config = GoConfigMother.configWithPipelines("pipeline1");
config.initializeServer();
config.findJob("pipeline1", "stage", "job").addTask(new ExecTask(longPath + " ", "arg1", (String) null));
output = new ByteArrayOutputStream();
try {
xmlWriter.write(config, output, false);
fail("expected to blow up");
} catch (XsdValidationException e) {
assertThat(e.getMessage(), containsString("should conform to the pattern - \\S(.*\\S)?"));
}
}
Aggregations