Search in sources :

Example 31 with GoConfigMother

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

the class ConfigMaterialUpdaterIntegrationTest method shouldNotMergeFromInvalidConfigRepository_AndShouldKeepLastValidPart.

@Test
public void shouldNotMergeFromInvalidConfigRepository_AndShouldKeepLastValidPart() throws Exception {
    String fileName = "pipe1.gocd.xml";
    GoConfigMother mother = new GoConfigMother();
    PipelineConfig pipelineConfig = mother.cruiseConfigWithOnePipelineGroup().getAllPipelineConfigs().get(0);
    configTestRepo.addPipelineToRepositoryAndPush(fileName, pipelineConfig);
    materialUpdateService.updateMaterial(material);
    // time for messages to pass through all services
    waitForMaterialNotInProgress();
    cachedGoConfig.forceReload();
    assertThat(goConfigService.hasPipelineNamed(pipelineConfig.name()), is(true));
    assertThat(goConfigService.pipelineConfigNamed(pipelineConfig.name()), is(pipelineConfig));
    configTestRepo.addCodeToRepositoryAndPush("badPipe.gocd.xml", "added bad config file", "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<cruise xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"cruise-config.xsd\" schemaVersion=\"38\">\n" + "<pipelines group=\"changed\">\n" + "  <pipeline name=\"badPipe\">\n" + "    <materials>\n" + "      <svn url=\"file:///tmp/foo\" />\n" + "      <svn url=\"file:///tmp/foo\" />\n" + "    </materials>\n" + "  </pipeline>\n" + "</pipelines>" + "</cruise>");
    materialUpdateService.updateMaterial(material);
    // time for messages to pass through all services
    waitForMaterialNotInProgress();
    cachedGoConfig.forceReload();
    // but we still have the old part
    assertThat(goConfigService.hasPipelineNamed(pipelineConfig.name()), is(true));
    assertThat(goConfigService.pipelineConfigNamed(pipelineConfig.name()), is(pipelineConfig));
    // and no trace of badPipe
    assertThat(goConfigService.hasPipelineNamed(new CaseInsensitiveString("badPipe")), is(false));
}
Also used : GoConfigMother(com.thoughtworks.go.helper.GoConfigMother)

Example 32 with GoConfigMother

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

the class ConfigMaterialUpdaterIntegrationTest method shouldMergePipelineFromValidConfigRepository.

@Test
public void shouldMergePipelineFromValidConfigRepository() throws Exception {
    String fileName = "pipe1.gocd.xml";
    GoConfigMother mother = new GoConfigMother();
    PipelineConfig pipelineConfig = mother.cruiseConfigWithOnePipelineGroup().getAllPipelineConfigs().get(0);
    configTestRepo.addPipelineToRepositoryAndPush(fileName, pipelineConfig);
    materialUpdateService.updateMaterial(material);
    Assert.assertThat(materialUpdateService.isInProgress(material), is(true));
    // time for messages to pass through all services
    waitForMaterialNotInProgress();
    cachedGoConfig.forceReload();
    assertThat(goConfigService.hasPipelineNamed(pipelineConfig.name()), is(true));
    assertThat(goConfigService.pipelineConfigNamed(pipelineConfig.name()), is(pipelineConfig));
}
Also used : GoConfigMother(com.thoughtworks.go.helper.GoConfigMother)

Example 33 with GoConfigMother

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

the class GoConfigServiceIntegrationTest method shouldInternallyGetGoConfigInvalidExceptionOnValidationErrorAndFailWithATopLevelConfigError.

@Test
public void shouldInternallyGetGoConfigInvalidExceptionOnValidationErrorAndFailWithATopLevelConfigError() throws Exception {
    String oldMd5 = goConfigService.getConfigForEditing().getMd5();
    CruiseConfig user1SeeingConfig = configHelper.load();
    // Setup a pipeline group in the config
    new GoConfigMother().addPipelineWithGroup(user1SeeingConfig, "defaultGroup", "user1_pipeline", "user1_stage", "user1_job");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    configHelper.getXml(user1SeeingConfig, os);
    GoConfigService.XmlPartialSaver saver = goConfigService.fileSaver(false);
    saver.saveXml(os.toString(), oldMd5);
    CruiseConfig configBeforePipelineGroupWasAddedAtBeginning = configHelper.load();
    String md5BeforeAddingGroupAtBeginning = configBeforePipelineGroupWasAddedAtBeginning.getMd5();
    // User 1 edits config XML and adds a pipeline group before the first group in config
    String configXMLWithGroupAddedAtBeginning = os.toString().replace("</pipelines>", "</pipelines><pipelines group=\"first_group\"/>");
    saver.saveXml(configXMLWithGroupAddedAtBeginning, md5BeforeAddingGroupAtBeginning);
    // User 2 adds another pipeline group, with the same name, through UI, but using the older MD5.
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ConfigUpdateResponse response = goConfigService.updateConfigFromUI(new UpdateConfigFromUI() {

        public void checkPermission(CruiseConfig cruiseConfig, LocalizedOperationResult result) {
        }

        public Validatable node(CruiseConfig cruiseConfig) {
            return cruiseConfig;
        }

        public Validatable updatedNode(CruiseConfig cruiseConfig) {
            return node(cruiseConfig);
        }

        public void update(Validatable config) {
            CruiseConfig cruiseConfig = (CruiseConfig) config;
            MaterialConfigs materials = new MaterialConfigs(MaterialConfigsMother.mockMaterialConfigs("file:///tmp/foo"));
            new GoConfigMother().addPipelineWithGroup(cruiseConfig, "first_group", "up_pipeline", materials, "down_stage", "down_job");
        }

        public Validatable subject(Validatable node) {
            return node;
        }

        public Validatable updatedSubject(Validatable updatedNode) {
            return subject(updatedNode);
        }
    }, md5BeforeAddingGroupAtBeginning, new Username(new CaseInsensitiveString("admin")), result);
    CruiseConfig config = response.getCruiseConfig();
    assertThat(config.getMd5(), is(md5BeforeAddingGroupAtBeginning));
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.httpCode(), is(SC_CONFLICT));
    assertThat(result.message(localizer), is("Save failed. Duplicate unique value [first_group] declared for identity constraint of element \"cruise\"."));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Matchers.containsString(org.hamcrest.Matchers.containsString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) LocalizedOperationResult(com.thoughtworks.go.server.service.result.LocalizedOperationResult) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ConfigUpdateResponse(com.thoughtworks.go.config.update.ConfigUpdateResponse) UpdateConfigFromUI(com.thoughtworks.go.config.update.UpdateConfigFromUI) Test(org.junit.Test)

Example 34 with GoConfigMother

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

the class GoConfigServiceIntegrationTest method shouldThrowUpOnConfigSaveValidationError_ViaNormalFlow.

@Test
public void shouldThrowUpOnConfigSaveValidationError_ViaNormalFlow() throws Exception {
    // User 1 loads page
    CruiseConfig user1SeeingConfig = goConfigDao.loadForEditing();
    String user1SeeingMd5 = user1SeeingConfig.getMd5();
    // User 1 edits old config
    new GoConfigMother().addPipelineWithGroup(user1SeeingConfig, "defaultGroup", "user1_pipeline", "user1_stage", "user1_job");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    configHelper.getXml(user1SeeingConfig, os);
    // Introduce validation error on xml
    String xml = os.toString();
    xml = xml.replace("user1_pipeline", "user1 pipeline");
    // User 1 saves edited config
    GoConfigService.XmlPartialSaver saver = goConfigService.fileSaver(false);
    GoConfigValidity validity = saver.saveXml(xml, user1SeeingMd5);
    assertThat(validity.isValid(), is(false));
    assertThat(validity.isType(GoConfigValidity.VT_CONFLICT), is(true));
    assertThat(validity.errorMessage(), containsString("Name is invalid. \"user1 pipeline\""));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.Test)

Example 35 with GoConfigMother

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

the class GoConfigServiceIntegrationTest method shouldThrowUpOnConfigSavePostValidationError_ViaMergeFlow.

@Test
public void shouldThrowUpOnConfigSavePostValidationError_ViaMergeFlow() throws Exception {
    // User 1 adds a pipeline
    configHelper.addPipelineWithGroup("defaultGroup", "up_pipeline", "up_stage", "up_job");
    configHelper.addPipelineWithGroup("anotherGroup", "random_pipeline", "random_stage", "random_job");
    CruiseConfig user1SeeingConfig = configHelper.load();
    String user1SeeingMd5 = user1SeeingConfig.getMd5();
    // User 2 edits config
    configHelper.removePipeline("up_pipeline");
    // User 1 edits old config
    MaterialConfigs materialConfigs = new MaterialConfigs();
    materialConfigs.add(MaterialConfigsMother.dependencyMaterialConfig("up_pipeline", "up_stage"));
    new GoConfigMother().addPipelineWithGroup(user1SeeingConfig, "anotherGroup", "down_pipeline", materialConfigs, "down_stage", "down_job");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    configHelper.getXml(user1SeeingConfig, os);
    // User 1 saves edited config
    String xml = os.toString();
    GoConfigService.XmlPartialSaver saver = goConfigService.fileSaver(false);
    GoConfigValidity validity = saver.saveXml(xml, user1SeeingMd5);
    assertThat(validity.isValid(), is(false));
    assertThat(validity.toString(), validity.isType(GoConfigValidity.VT_MERGE_POST_VALIDATION_ERROR), is(true));
    assertThat(validity.errorMessage(), is("Pipeline \"up_pipeline\" does not exist. It is used from pipeline \"down_pipeline\"."));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Matchers.containsString(org.hamcrest.Matchers.containsString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.Test)

Aggregations

GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)80 Test (org.junit.Test)48 Username (com.thoughtworks.go.server.domain.Username)33 Before (org.junit.Before)25 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)18 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)17 GoConfigValidity (com.thoughtworks.go.config.validation.GoConfigValidity)11 StringContains.containsString (org.hamcrest.core.StringContains.containsString)8 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 File (java.io.File)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 BasicEnvironmentConfig (com.thoughtworks.go.config.BasicEnvironmentConfig)3 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)3 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)3 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)3 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)3