Search in sources :

Example 11 with ConfigUpdateResponse

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

the class GoConfigServiceIntegrationTest method shouldUpdateConfigFromUI.

@Test
public void shouldUpdateConfigFromUI() {
    configHelper.addPipeline("pipeline", "stage");
    String md5 = goConfigService.getConfigForEditing().getMd5();
    ConfigUpdateResponse response = goConfigService.updateConfigFromUI(new AddStageToPipelineCommand("secondStage"), md5, Username.ANONYMOUS, new HttpLocalizedOperationResult());
    PipelineConfig config = goConfigService.getConfigForEditing().pipelineConfigByName(new CaseInsensitiveString("pipeline"));
    assertThat(config.size(), is(2));
    assertThat(config.get(0).name(), is(new CaseInsensitiveString("stage")));
    assertThat(config.get(1).name(), is(new CaseInsensitiveString("secondStage")));
    assertThat(response.configAfterUpdate().hasStageConfigNamed(new CaseInsensitiveString("pipeline"), new CaseInsensitiveString("secondStage"), true), is(true));
}
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 12 with ConfigUpdateResponse

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

the class GoConfigServiceIntegrationTest method shouldRespondWithNewConfigWhenSavedSuccessfully.

@Test
public void shouldRespondWithNewConfigWhenSavedSuccessfully() {
    configHelper.addPipeline("pipeline", "stage");
    String md5 = goConfigService.getConfigForEditing().getMd5();
    UpdateConfigFromUI pipelineAndStageRename = new PipelineStageRenamingCommand();
    ConfigUpdateResponse response = goConfigService.updateConfigFromUI(pipelineAndStageRename, md5, Username.ANONYMOUS, new HttpLocalizedOperationResult());
    PipelineConfig pipeline = goConfigService.getConfigForEditing().pipelineConfigByName(new CaseInsensitiveString("new-pipeline"));
    StageConfig stage = pipeline.getStage(new CaseInsensitiveString("new-stage"));
    assertThat(pipeline, not(nullValue()));
    assertThat(stage, not(nullValue()));
    assertThat(((PipelineConfig) response.getNode()).name(), is(new CaseInsensitiveString("new-pipeline")));
    assertThat(((StageConfig) response.getSubject()).name(), is(new CaseInsensitiveString("new-stage")));
    assertThat(response.configAfterUpdate().hasStageConfigNamed(new CaseInsensitiveString("new-pipeline"), new CaseInsensitiveString("new-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 13 with ConfigUpdateResponse

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

the class GoConfigServiceIntegrationTest method shouldNotUpdateConfigFromUIWhentheUserDoesNotHavePermissions.

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

        public void checkPermission(CruiseConfig cruiseConfig, LocalizedOperationResult result) {
            result.unauthorized(LocalizedMessage.string("UNAUTHORIZED_TO_EDIT_GROUP", "groupName"), null);
            configObtainedInCheckPermissions[0] = cruiseConfig;
        }
    }, md5, Username.ANONYMOUS, result);
    assertThat(configObtainedInCheckPermissions[0], is(goConfigService.getCurrentConfig()));
    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));
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.httpCode(), is(401));
    assertThat(result.message(localizer), is("Unauthorized to edit 'groupName' group."));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) 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) Test(org.junit.Test)

Example 14 with ConfigUpdateResponse

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

the class GoConfigServiceIntegrationTest method shouldReturnAResponseWithTheValidatedCruiseConfig.

@Test
public void shouldReturnAResponseWithTheValidatedCruiseConfig() {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    configHelper.addPipeline("pipeline", "stage");
    String md5 = goConfigService.getConfigForEditing().getMd5();
    ConfigUpdateResponse response = goConfigService.updateConfigFromUI(new AddStageToPipelineCommand("stage"), md5, Username.ANONYMOUS, result);
    CruiseConfig invalidConfig = response.getCruiseConfig();
    //Make sure that the config returned is the duplicate on.
    assertThat(invalidConfig.pipelineConfigByName(new CaseInsensitiveString("pipeline")).size(), is(2));
    PipelineConfig config = (PipelineConfig) response.getNode();
    assertThat(config.size(), is(2));
    assertStageError(config.get(1), "You have defined multiple stages called 'stage'. Stage names are case-insensitive and must be unique.", StageConfig.NAME);
    assertFailedResult(result, "Save failed, see errors below");
    assertThat(response.configAfterUpdate().hasStageConfigNamed(new CaseInsensitiveString("pipeline"), new CaseInsensitiveString("secondStage"), true), is(false));
}
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 15 with ConfigUpdateResponse

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

the class GoConfigServiceIntegrationTest method shouldRespondWithModifiedConfigWhenSaveFailsBecauseOfValidationErrors.

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

        {
            newPipelineName = "pipeline!@foo - bar";
        }
    };
    ConfigUpdateResponse response = goConfigService.updateConfigFromUI(pipelineAndStageRename, md5, Username.ANONYMOUS, new HttpLocalizedOperationResult());
    assertThat(goConfigService.getConfigForEditing().hasPipelineNamed(new CaseInsensitiveString("pipeline!@foo - bar")), is(false));
    assertThat(goConfigService.getConfigForEditing().hasPipelineNamed(new CaseInsensitiveString("pipeline")), is(true));
    assertThat(((PipelineConfig) response.getNode()).name(), is(new CaseInsensitiveString("pipeline!@foo - bar")));
    assertThat(((StageConfig) response.getSubject()).name(), is(new CaseInsensitiveString("new-stage")));
    assertThat(response.configAfterUpdate().hasStageConfigNamed(new CaseInsensitiveString("pipeline!@foo - bar"), new CaseInsensitiveString("new-stage"), false), is(false));
}
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)

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