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));
}
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));
}
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."));
}
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));
}
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));
}
Aggregations