Search in sources :

Example 11 with XsdValidationException

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\".")));
    }
}
Also used : XsdValidationException(com.thoughtworks.go.util.XsdValidationException) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.jupiter.api.Test)

Example 12 with XsdValidationException

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'."));
    }
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) XsdValidationException(com.thoughtworks.go.util.XsdValidationException) PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Example 13 with XsdValidationException

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)?"));
    }
}
Also used : XsdValidationException(com.thoughtworks.go.util.XsdValidationException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Aggregations

XsdValidationException (com.thoughtworks.go.util.XsdValidationException)13 Test (org.junit.jupiter.api.Test)13 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)7 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)5 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)4 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)4 Packages (com.thoughtworks.go.domain.packagerepository.Packages)4 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Timeout (org.junit.jupiter.api.Timeout)1