use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class PackageRepositoryService method savePackageRepositoryToConfig.
public ConfigUpdateAjaxResponse savePackageRepositoryToConfig(PackageRepository packageRepository, final String md5, Username username) {
performPluginValidationsFor(packageRepository);
UpdateConfigFromUI updateCommand = getPackageRepositoryUpdateCommand(packageRepository, username);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
ConfigUpdateResponse configUpdateResponse = goConfigService.updateConfigFromUI(updateCommand, md5, username, result);
if (result.isSuccessful()) {
ConfigUpdateAjaxResponse response = ConfigUpdateAjaxResponse.success(packageRepository.getId(), result.httpCode(), configUpdateResponse.wasMerged() ? localizer.localize("CONFIG_MERGED") : localizer.localize("SAVED_CONFIGURATION_SUCCESSFULLY"));
return response;
} else {
List<String> globalErrors = globalErrors(configUpdateResponse.getCruiseConfig().getAllErrorsExceptFor(configUpdateResponse.getSubject()));
HashMap<String, List<String>> fieldErrors = fieldErrors(configUpdateResponse.getSubject(), "package_repository");
String message = result.message(localizer);
ConfigUpdateAjaxResponse response = ConfigUpdateAjaxResponse.failure(packageRepository.getId(), result.httpCode(), message, fieldErrors, globalErrors);
return response;
}
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class PatchEnvironmentCommandTest method setup.
@Before
public void setup() throws Exception {
initMocks(this);
pipelinesToAdd = new ArrayList<>();
pipelinesToRemove = new ArrayList<>();
agentsToAdd = new ArrayList<>();
agentsToRemove = new ArrayList<>();
envVarsToAdd = new ArrayList<>();
envVarsToRemove = new ArrayList<>();
result = new HttpLocalizedOperationResult();
currentUser = new Username(new CaseInsensitiveString("user"));
cruiseConfig = new GoConfigMother().defaultCruiseConfig();
environmentName = new CaseInsensitiveString("Dev");
environmentConfig = new BasicEnvironmentConfig(environmentName);
cruiseConfig.addEnvironment(environmentConfig);
pipelineConfig = new PipelineConfig();
String pipelineName = "pipeline-1";
pipelineConfig.setName(pipelineName);
cruiseConfig.addPipeline("First-Group", pipelineConfig);
agentConfig = new AgentConfig("uuid-1");
cruiseConfig.agents().add(agentConfig);
actionFailed = LocalizedMessage.string("ENV_UPDATE_FAILED", environmentConfig.name());
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class PatchEnvironmentCommandTest method shouldValidateInvalidAgentUUIDs.
@Test
public void shouldValidateInvalidAgentUUIDs() throws Exception {
String uuid = "invalid-agent-uuid";
agentsToAdd.add(uuid);
PatchEnvironmentCommand command = new PatchEnvironmentCommand(goConfigService, environmentConfig, pipelinesToAdd, pipelinesToRemove, agentsToAdd, agentsToRemove, envVarsToAdd, envVarsToRemove, currentUser, actionFailed, result);
assertFalse(cruiseConfig.getEnvironments().find(environmentName).hasAgent(uuid));
command.update(cruiseConfig);
assertFalse(command.isValid(cruiseConfig));
HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
expectedResult.unprocessableEntity(actionFailed.addParam("Environment 'Dev' has an invalid agent uuid 'invalid-agent-uuid'"));
assertThat(result, is(expectedResult));
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class PatchEnvironmentCommandTest method shouldNotAllowRemovingRemotePipeline.
@Test
public void shouldNotAllowRemovingRemotePipeline() throws Exception {
CaseInsensitiveString pipelineName = new CaseInsensitiveString("remote-pipeline-to-remove");
BasicEnvironmentConfig local = new BasicEnvironmentConfig(environmentName);
local.setOrigins(new FileConfigOrigin());
BasicEnvironmentConfig remote = new BasicEnvironmentConfig(environmentName);
remote.addPipeline(pipelineName);
ConfigRepoConfig configRepo = new ConfigRepoConfig(new GitMaterialConfig("foo/bar.git", "master"), "myPlugin");
remote.setOrigins(new RepoConfigOrigin(configRepo, "latest"));
MergeEnvironmentConfig mergedConfig = new MergeEnvironmentConfig(local, remote);
pipelinesToRemove.add(pipelineName.toString());
PatchEnvironmentCommand command = new PatchEnvironmentCommand(goConfigService, environmentConfig, pipelinesToAdd, pipelinesToRemove, agentsToAdd, agentsToRemove, envVarsToAdd, envVarsToRemove, currentUser, actionFailed, result);
assertFalse(cruiseConfig.getEnvironments().find(environmentName).containsPipeline(new CaseInsensitiveString(pipelineName.toString())));
command.update(cruiseConfig);
// preprocess
cruiseConfig.getEnvironments().replace(cruiseConfig.getEnvironments().find(environmentName), mergedConfig);
boolean isValid = command.isValid(cruiseConfig);
assertFalse(isValid);
HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
String message = "Pipeline 'remote-pipeline-to-remove' cannot be removed from environment 'Dev' as the association has been defined remotely in [foo/bar.git at latest]";
expectedResult.unprocessableEntity(actionFailed.addParam(message));
assertThat(result, is(expectedResult));
}
use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.
the class PatchEnvironmentCommandTest method shouldValidateInvalidPipelineNames.
@Test
public void shouldValidateInvalidPipelineNames() throws Exception {
String pipelineName = "invalid-pipeline-name";
pipelinesToAdd.add(pipelineName);
PatchEnvironmentCommand command = new PatchEnvironmentCommand(goConfigService, environmentConfig, pipelinesToAdd, pipelinesToRemove, agentsToAdd, agentsToRemove, envVarsToAdd, envVarsToRemove, currentUser, actionFailed, result);
assertFalse(cruiseConfig.getEnvironments().find(environmentName).hasAgent(pipelineName));
command.update(cruiseConfig);
assertFalse(cruiseConfig.getEnvironments().find(environmentName).hasAgent(pipelineName));
boolean isValid = command.isValid(cruiseConfig);
assertFalse(isValid);
HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
expectedResult.unprocessableEntity(actionFailed.addParam("Environment 'Dev' refers to an unknown pipeline 'invalid-pipeline-name'."));
assertThat(result, is(expectedResult));
}
Aggregations