Search in sources :

Example 31 with ConfigSaveValidationContext

use of com.thoughtworks.go.config.ConfigSaveValidationContext in project gocd by gocd.

the class PluggableSCMMaterialConfigTest method shouldAddErrorIfMaterialDoesNotHaveASCMId.

@Test
public void shouldAddErrorIfMaterialDoesNotHaveASCMId() {
    pluggableSCMMaterialConfig.setScmId(null);
    pluggableSCMMaterialConfig.validateConcreteMaterial(new ConfigSaveValidationContext(null, null));
    assertThat(pluggableSCMMaterialConfig.errors().getAll().size(), is(1));
    assertThat(pluggableSCMMaterialConfig.errors().on(PluggableSCMMaterialConfig.SCM_ID), is("Please select a SCM"));
}
Also used : PipelineConfigSaveValidationContext(com.thoughtworks.go.config.PipelineConfigSaveValidationContext) ConfigSaveValidationContext(com.thoughtworks.go.config.ConfigSaveValidationContext) Test(org.junit.jupiter.api.Test)

Example 32 with ConfigSaveValidationContext

use of com.thoughtworks.go.config.ConfigSaveValidationContext in project gocd by gocd.

the class PluggableSCMMaterialConfigTest method shouldAddErrorIDestinationIsNotValid.

@Test
public void shouldAddErrorIDestinationIsNotValid() throws Exception {
    ConfigSaveValidationContext configSaveValidationContext = mock(ConfigSaveValidationContext.class);
    SCM scmConfig = mock(SCM.class);
    when(configSaveValidationContext.findScmById(anyString())).thenReturn(scmConfig);
    when(scmConfig.doesPluginExist()).thenReturn(true);
    PluggableSCMMaterialConfig pluggableSCMMaterialConfig = new PluggableSCMMaterialConfig(null, scmConfig, "/usr/home", null, false);
    pluggableSCMMaterialConfig.setScmId("scm-id");
    pluggableSCMMaterialConfig.validateConcreteMaterial(configSaveValidationContext);
    assertThat(pluggableSCMMaterialConfig.errors().getAll().size(), is(1));
    assertThat(pluggableSCMMaterialConfig.errors().on(PluggableSCMMaterialConfig.FOLDER), is("Dest folder '/usr/home' is not valid. It must be a sub-directory of the working folder."));
    pluggableSCMMaterialConfig = new PluggableSCMMaterialConfig(null, scmConfig, "./../crap", null, false);
    pluggableSCMMaterialConfig.setScmId("scm-id");
    pluggableSCMMaterialConfig.validateConcreteMaterial(configSaveValidationContext);
    assertThat(pluggableSCMMaterialConfig.errors().getAll().size(), is(2));
    assertThat(pluggableSCMMaterialConfig.errors().on(PluggableSCMMaterialConfig.FOLDER), is("Invalid directory name './../crap'. It should be a valid relative path."));
}
Also used : PipelineConfigSaveValidationContext(com.thoughtworks.go.config.PipelineConfigSaveValidationContext) ConfigSaveValidationContext(com.thoughtworks.go.config.ConfigSaveValidationContext) SCM(com.thoughtworks.go.domain.scm.SCM) Test(org.junit.jupiter.api.Test)

Example 33 with ConfigSaveValidationContext

use of com.thoughtworks.go.config.ConfigSaveValidationContext in project gocd by gocd.

the class ElasticProfileTest method shouldNotAddAnyErrorsForAValidClusterProfileReference.

@Test
public void shouldNotAddAnyErrorsForAValidClusterProfileReference() {
    ElasticProfile profile = new ElasticProfile("docker.unit-test", "prod-cluster");
    BasicCruiseConfig config = new BasicCruiseConfig();
    config.getElasticConfig().setClusterProfiles(new ClusterProfiles(new ClusterProfile("prod-cluster", "cd.go.elastic-agent.docker")));
    profile.validate(new ConfigSaveValidationContext(config));
    assertThat(profile.errors().size(), is(0));
}
Also used : ConfigSaveValidationContext(com.thoughtworks.go.config.ConfigSaveValidationContext) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) Test(org.junit.jupiter.api.Test)

Example 34 with ConfigSaveValidationContext

use of com.thoughtworks.go.config.ConfigSaveValidationContext in project gocd by gocd.

the class PackageRepositoryTest method shouldValidateIfNameIsMissing.

@Test
void shouldValidateIfNameIsMissing() {
    PackageRepository packageRepository = new PackageRepository();
    packageRepository.validate(new ConfigSaveValidationContext(new BasicCruiseConfig(), null));
    assertThat(packageRepository.errors().getAllOn("name")).isEqualTo(asList("Please provide name"));
}
Also used : ConfigSaveValidationContext(com.thoughtworks.go.config.ConfigSaveValidationContext) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) Test(org.junit.jupiter.api.Test)

Example 35 with ConfigSaveValidationContext

use of com.thoughtworks.go.config.ConfigSaveValidationContext in project gocd by gocd.

the class PackageRepositoryTest method shouldValidateName.

@Test
void shouldValidateName() throws Exception {
    PackageRepository packageRepository = new PackageRepository();
    packageRepository.setName("some name");
    packageRepository.validate(new ConfigSaveValidationContext(null));
    assertThat(packageRepository.errors().isEmpty()).isFalse();
    assertThat(packageRepository.errors().getAllOn(PackageRepository.NAME).get(0)).isEqualTo("Invalid PackageRepository name 'some name'. This must be alphanumeric and can contain underscores, hyphens and periods (however, it cannot start with a period). The maximum allowed length is 255 characters.");
}
Also used : ConfigSaveValidationContext(com.thoughtworks.go.config.ConfigSaveValidationContext) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigSaveValidationContext (com.thoughtworks.go.config.ConfigSaveValidationContext)38 Test (org.junit.Test)18 Test (org.junit.jupiter.api.Test)10 GoCipher (com.thoughtworks.go.security.GoCipher)9 UrlArgument (com.thoughtworks.go.util.command.UrlArgument)7 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)5 PipelineConfigSaveValidationContext (com.thoughtworks.go.config.PipelineConfigSaveValidationContext)3 ConfigErrors (com.thoughtworks.go.domain.ConfigErrors)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)2 MingleConfig (com.thoughtworks.go.config.MingleConfig)2 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)2 AgentConfig (com.thoughtworks.go.config.AgentConfig)1 Agents (com.thoughtworks.go.config.Agents)1 ElasticProfiles (com.thoughtworks.go.config.elastic.ElasticProfiles)1 SCM (com.thoughtworks.go.domain.scm.SCM)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1