Search in sources :

Example 51 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class ConfigRepoConfigTest method validate_shouldNotAllowDisabledAutoUpdate.

@Test
public void validate_shouldNotAllowDisabledAutoUpdate() {
    CruiseConfig cruiseConfig = new BasicCruiseConfig();
    GoConfigMother mother = new GoConfigMother();
    SvnMaterialConfig svn = new SvnMaterialConfig("url", false);
    svn.setAutoUpdate(false);
    ConfigRepoConfig configRepoConfig = new ConfigRepoConfig(svn, "plug");
    cruiseConfig.setConfigRepos(new ConfigReposConfig(configRepoConfig));
    configRepoConfig.validate(null);
    assertThat(configRepoConfig.errors().isEmpty(), is(false));
    assertThat(configRepoConfig.errors().on(ConfigRepoConfig.AUTO_UPDATE), is("Configuration repository material url must have autoUpdate enabled"));
}
Also used : SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.Test)

Example 52 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class ConfigRepoConfigTest method validate_shouldNotAllowPipelineWithSameRepositoryAndDisabledAutoUpdate.

@Test
public void validate_shouldNotAllowPipelineWithSameRepositoryAndDisabledAutoUpdate() {
    CruiseConfig cruiseConfig = new BasicCruiseConfig();
    GoConfigMother mother = new GoConfigMother();
    MaterialConfigs materialConfigs = new MaterialConfigs();
    SvnMaterialConfig svn = new SvnMaterialConfig("url", false);
    svn.setAutoUpdate(false);
    materialConfigs.add(svn);
    ConfigRepoConfig configRepoConfig = new ConfigRepoConfig(svn, "plug");
    cruiseConfig.setConfigRepos(new ConfigReposConfig(configRepoConfig));
    PipelineConfig pipeline1 = mother.addPipeline(cruiseConfig, "badpipe", "build", materialConfigs, "build");
    configRepoConfig.validate(ConfigSaveValidationContext.forChain(cruiseConfig, new BasicPipelineConfigs(), pipeline1));
    assertThat(svn.errors().isEmpty(), is(false));
    assertThat(svn.errors().on(ScmMaterialConfig.AUTO_UPDATE), is("Material of type Subversion (url) is specified as a configuration repository and pipeline material with disabled autoUpdate. All copies of this material must have autoUpdate enabled or configuration repository must be removed"));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.Test)

Example 53 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class GoConfigServiceTest method shouldReturnInvalidWhenPipelineGroupPartialHasInvalidAttributeValue.

@Test
public void shouldReturnInvalidWhenPipelineGroupPartialHasInvalidAttributeValue() throws Exception {
    String groupName = "group_name";
    String md5 = "md5";
    cruiseConfig = new BasicCruiseConfig();
    expectLoad(cruiseConfig);
    new GoConfigMother().addPipelineWithGroup(cruiseConfig, groupName, "pipeline_name", "stage_name", "job_name");
    expectLoadForEditing(cruiseConfig);
    when(goConfigDao.md5OfConfigFile()).thenReturn(md5);
    String pipelineGroupContent = groupXmlWithInvalidAttributeValue(groupName);
    GoConfigValidity validity = goConfigService.groupSaver(groupName).saveXml(pipelineGroupContent, "md5");
    assertThat(validity.isValid(), Matchers.is(false));
    assertThat(validity.errorMessage(), containsString("Name is invalid. \"pipeline@$^\""));
    verify(goConfigDao, never()).updateConfig(any(UpdateConfigCommand.class));
}
Also used : StringContains.containsString(org.hamcrest.core.StringContains.containsString) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.Test)

Example 54 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class GoConfigServiceTest method shouldRegisterBaseUrlChangeListener.

@Test
public void shouldRegisterBaseUrlChangeListener() throws Exception {
    CruiseConfig cruiseConfig = new GoConfigMother().cruiseConfigWithOnePipelineGroup();
    stub(goConfigDao.load()).toReturn(cruiseConfig);
    goConfigService.initialize();
    verify(goConfigDao).registerListener(any(BaseUrlChangeListener.class));
}
Also used : BaseUrlChangeListener(com.thoughtworks.go.listener.BaseUrlChangeListener) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.Test)

Example 55 with GoConfigMother

use of com.thoughtworks.go.helper.GoConfigMother in project gocd by gocd.

the class PipelineConfigsServiceTest method shouldReturnXmlForGivenGroup_onGetXml.

@Test
public void shouldReturnXmlForGivenGroup_onGetXml() {
    CruiseConfig cruiseConfig = new BasicCruiseConfig();
    String groupName = "group_name";
    new GoConfigMother().addPipelineWithGroup(cruiseConfig, groupName, "pipeline_name", "stage_name", "job_name");
    when(goConfigService.getConfigForEditing()).thenReturn(cruiseConfig);
    when(securityService.isUserAdminOfGroup(validUser.getUsername(), groupName)).thenReturn(true);
    String actualXml = service.getXml(groupName, validUser, result);
    String expectedXml = "<pipelines group=\"group_name\">\n  <pipeline name=\"pipeline_name\">\n    <materials>\n      <svn url=\"file:///tmp/foo\" />\n    </materials>\n    <stage name=\"stage_name\">\n      <jobs>\n        <job name=\"job_name\" />\n      </jobs>\n    </stage>\n  </pipeline>\n</pipelines>";
    assertThat(actualXml, is(expectedXml));
    assertThat(result.isSuccessful(), is(true));
    verify(goConfigService, times(1)).getConfigForEditing();
}
Also used : GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Test(org.junit.Test)

Aggregations

GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)55 Test (org.junit.Test)34 Before (org.junit.Before)19 Username (com.thoughtworks.go.server.domain.Username)18 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)15 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)15 GoConfigValidity (com.thoughtworks.go.config.validation.GoConfigValidity)11 StringContains.containsString (org.hamcrest.core.StringContains.containsString)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)6 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)5 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)4 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)4 File (java.io.File)4 BasicEnvironmentConfig (com.thoughtworks.go.config.BasicEnvironmentConfig)3 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)3 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)3 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)3 SCM (com.thoughtworks.go.domain.scm.SCM)3