Search in sources :

Example 1 with ConfigUpdateResponse

use of com.thoughtworks.go.config.update.ConfigUpdateResponse in project gocd by gocd.

the class GoConfigServiceConfigSaveTest method shouldSaveTemplateWhenUserIsATemplateAdmin.

@Test
public void shouldSaveTemplateWhenUserIsATemplateAdmin() throws Exception {
    String adminUser = "admin1";
    String templateName = "template-name";
    CruiseConfig configForEdit = addTemplateWithTemplateAdminUser(adminUser, templateName);
    ConfigUpdateResponse response = goConfigService.updateConfigFromUI(new AddStageToTemplate(templateName, "stage2"), configForEdit.getMd5(), new Username(new CaseInsensitiveString(adminUser)), new HttpLocalizedOperationResult());
    CruiseConfig configAfterUpdate = response.configAfterUpdate();
    assertThat(configAfterUpdate.getTemplateByName(new CaseInsensitiveString(templateName)).size(), is(2));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) ConfigUpdateResponse(com.thoughtworks.go.config.update.ConfigUpdateResponse) Test(org.junit.Test)

Example 2 with ConfigUpdateResponse

use of com.thoughtworks.go.config.update.ConfigUpdateResponse in project gocd by gocd.

the class GoConfigServiceIntegrationTest method shouldRespondWithLatestUnmodifiedConfigInCaseOfUnexpectedFailures.

@Test
public void shouldRespondWithLatestUnmodifiedConfigInCaseOfUnexpectedFailures() {
    configHelper.addPipeline("pipeline", "stage");
    String md5 = goConfigService.getConfigForEditing().getMd5();
    UpdateConfigFromUI pipelineAndStageRename = new PipelineStageRenamingCommand() {

        @Override
        public void update(Validatable pipelineNode) {
            throw new RuntimeException("Oh no!");
        }
    };
    ConfigUpdateResponse response = goConfigService.updateConfigFromUI(pipelineAndStageRename, md5, Username.ANONYMOUS, new HttpLocalizedOperationResult());
    assertThat(goConfigService.getConfigForEditing().hasPipelineNamed(new CaseInsensitiveString("new-pipeline")), is(false));
    assertThat(goConfigService.getConfigForEditing().hasPipelineNamed(new CaseInsensitiveString("pipeline")), is(true));
    assertThat(((PipelineConfig) response.getNode()).name(), is(new CaseInsensitiveString("pipeline")));
    assertThat(((StageConfig) response.getSubject()).name(), is(new CaseInsensitiveString("stage")));
    assertThat(response.configAfterUpdate().hasStageConfigNamed(new CaseInsensitiveString("pipeline"), new CaseInsensitiveString("new-stage"), false), is(false));
    assertThat(response.configAfterUpdate().hasStageConfigNamed(new CaseInsensitiveString("pipeline"), new CaseInsensitiveString("stage"), false), is(true));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Matchers.containsString(org.hamcrest.Matchers.containsString) UpdateConfigFromUI(com.thoughtworks.go.config.update.UpdateConfigFromUI) ConfigUpdateResponse(com.thoughtworks.go.config.update.ConfigUpdateResponse) Test(org.junit.Test)

Example 3 with ConfigUpdateResponse

use of com.thoughtworks.go.config.update.ConfigUpdateResponse in project gocd by gocd.

the class GoConfigServiceIntegrationTest method shouldReturnAllErrorsAppliedOverEditedCopy.

@Test
public void shouldReturnAllErrorsAppliedOverEditedCopy() {
    configHelper.addPipeline("pipeline", "stage");
    configHelper.addParamToPipeline("pipeline", "mingle_url", "http://foo.bar");
    String md5 = goConfigService.getConfigForEditing().getMd5();
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ConfigUpdateResponse response = goConfigService.updateConfigFromUI(new UpdateConfigFromUI() {

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

        public Validatable node(CruiseConfig cruiseConfig) {
            return cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline"));
        }

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

        public void update(Validatable pipeline) {
            PipelineConfig pipelineConfig = (PipelineConfig) pipeline;
            pipelineConfig.setMingleConfig(new MingleConfig("#{mingle_url}", "go"));
        }

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

        public Validatable updatedSubject(Validatable updatedNode) {
            return subject(updatedNode);
        }
    }, md5, new Username(new CaseInsensitiveString("admin")), result);
    MingleConfig mingleConfig = ((PipelineConfig) response.getNode()).getMingleConfig();
    assertThat(mingleConfig.errors().on(MingleConfig.BASE_URL), is("Should be a URL starting with https://"));
    assertThat(mingleConfig.getBaseUrl(), is("#{mingle_url}"));
}
Also used : 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) Matchers.containsString(org.hamcrest.Matchers.containsString) ConfigUpdateResponse(com.thoughtworks.go.config.update.ConfigUpdateResponse) UpdateConfigFromUI(com.thoughtworks.go.config.update.UpdateConfigFromUI) Test(org.junit.Test)

Example 4 with ConfigUpdateResponse

use of com.thoughtworks.go.config.update.ConfigUpdateResponse in project gocd by gocd.

the class GoConfigServiceIntegrationTest method shouldNotUpdateConfigFromUI_whenUpdateMethodBombs.

@Test
public void shouldNotUpdateConfigFromUI_whenUpdateMethodBombs() {
    final PipelineConfig pipelineConfig = configHelper.addPipeline("pipeline", "stage");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    String md5 = goConfigService.getConfigForEditing().getMd5();
    ConfigUpdateResponse response = goConfigService.updateConfigFromUI(new AddStageToPipelineCommand("secondStage") {

        public void update(Validatable node) {
            super.update(node);
            throw new RuntimeException("oops, foo bared!");
        }
    }, md5, Username.ANONYMOUS, result);
    PipelineConfig config = goConfigService.getConfigForEditing().pipelineConfigByName(new CaseInsensitiveString("pipeline"));
    assertThat(config.size(), is(1));
    assertThat(config.get(0).name(), is(new CaseInsensitiveString("stage")));
    assertThat(response.getCruiseConfig(), is(goConfigService.getConfigForEditing()));
    assertThat(response.getNode(), is(pipelineConfig));
    assertFailedResult(result, "Save failed. oops, foo bared!");
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Matchers.containsString(org.hamcrest.Matchers.containsString) ConfigUpdateResponse(com.thoughtworks.go.config.update.ConfigUpdateResponse) Test(org.junit.Test)

Example 5 with ConfigUpdateResponse

use of com.thoughtworks.go.config.update.ConfigUpdateResponse 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 \"uniquePipelines\" 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)

Aggregations

ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)19 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)19 Test (org.junit.Test)18 UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)12 Username (com.thoughtworks.go.server.domain.Username)10 Matchers.containsString (org.hamcrest.Matchers.containsString)10 LocalizedOperationResult (com.thoughtworks.go.server.service.result.LocalizedOperationResult)5 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)2 ConfigUpdateAjaxResponse (com.thoughtworks.go.config.update.ConfigUpdateAjaxResponse)2 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Cloner (com.rits.cloning.Cloner)1 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Date (java.util.Date)1