Search in sources :

Example 81 with HttpLocalizedOperationResult

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;
    }
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ArrayList(java.util.ArrayList) List(java.util.List)

Example 82 with HttpLocalizedOperationResult

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());
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Before(org.junit.Before)

Example 83 with HttpLocalizedOperationResult

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.Test)

Example 84 with HttpLocalizedOperationResult

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) FileConfigOrigin(com.thoughtworks.go.config.remote.FileConfigOrigin) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) Test(org.junit.Test)

Example 85 with HttpLocalizedOperationResult

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.Test)

Aggregations

HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)437 Test (org.junit.Test)394 Username (com.thoughtworks.go.server.domain.Username)168 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)41 ArrayList (java.util.ArrayList)27 Before (org.junit.Before)26 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)24 Pipeline (com.thoughtworks.go.domain.Pipeline)24 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)20 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)20 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)19 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)18 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)17 AgentInstance (com.thoughtworks.go.domain.AgentInstance)17 UserSearchModel (com.thoughtworks.go.presentation.UserSearchModel)17 GoCipher (com.thoughtworks.go.security.GoCipher)16 Matchers.containsString (org.hamcrest.Matchers.containsString)16 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)15 TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)14 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)14