Search in sources :

Example 56 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class ElasticProfileServiceTest method shouldAddPluginNotFoundErrorOnConfigForANonExistentPluginIdWhileCreating.

@Test
public void shouldAddPluginNotFoundErrorOnConfigForANonExistentPluginIdWhileCreating() throws Exception {
    ElasticProfile elasticProfile = new ElasticProfile("some-id", "non-existent-plugin", create("key", false, "value"));
    Username username = new Username("username");
    when(elasticAgentExtension.validate(elasticProfile.getPluginId(), elasticProfile.getConfigurationAsMap(true))).thenThrow(new PluginNotFoundException("some error"));
    elasticProfileService.create(username, elasticProfile, new HttpLocalizedOperationResult());
    assertThat(elasticProfile.errors().isEmpty(), Matchers.is(false));
    assertThat(elasticProfile.errors().on("pluginId"), Matchers.is("Plugin with id `non-existent-plugin` is not found."));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PluginNotFoundException(com.thoughtworks.go.plugin.access.PluginNotFoundException) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) Test(org.junit.Test)

Example 57 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class ElasticProfileServiceTest method shouldUpdateExistingElasticProfileInConfig.

@Test
public void shouldUpdateExistingElasticProfileInConfig() {
    ElasticProfile elasticProfile = new ElasticProfile("ldap", "cd.go.ldap");
    Username username = new Username("username");
    elasticProfileService.update(username, "md5", elasticProfile, new HttpLocalizedOperationResult());
    verify(goConfigService).updateConfig(any(ElasticAgentProfileUpdateCommand.class), eq(username));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ElasticAgentProfileUpdateCommand(com.thoughtworks.go.config.update.ElasticAgentProfileUpdateCommand) Test(org.junit.Test)

Example 58 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class EnvironmentConfigServiceTest method shouldReturnResultWithMessageThatConfigWasMerged_WhenMergingEnvironmentChanges_NewUpdateEnvironmentMethod.

@Test
public void shouldReturnResultWithMessageThatConfigWasMerged_WhenMergingEnvironmentChanges_NewUpdateEnvironmentMethod() {
    String environmentName = "env_name";
    EnvironmentConfig environmentConfig = new BasicEnvironmentConfig(new CaseInsensitiveString(environmentName));
    Username user = new Username(new CaseInsensitiveString("user"));
    when(securityService.isUserAdmin(user)).thenReturn(true);
    when(mockGoConfigService.updateConfig(any(UpdateConfigCommand.class))).thenReturn(ConfigSaveState.MERGED);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    String md5 = "md5";
    environmentConfigService.updateEnvironment(environmentConfig.name().toString(), environmentConfig, user, md5, result);
    assertTrue(result.isSuccessful());
    assertThat(result.toString(), containsString("UPDATE_ENVIRONMENT_SUCCESS"));
    assertThat(result.toString(), containsString(environmentName));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) MergeEnvironmentConfig(com.thoughtworks.go.config.merge.MergeEnvironmentConfig) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 59 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class EnvironmentConfigServiceTest method shouldCreateANewEnvironment.

@Test
public void shouldCreateANewEnvironment() {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    List<String> selectedAgents = new ArrayList<>();
    Username user = new Username(new CaseInsensitiveString("user"));
    when(securityService.isUserAdmin(user)).thenReturn(true);
    String environmentName = "foo-environment";
    when(mockGoConfigService.hasEnvironmentNamed(new CaseInsensitiveString(environmentName))).thenReturn(false);
    environmentConfigService.createEnvironment(env(environmentName, new ArrayList<>(), new ArrayList<>(), selectedAgents), user, result);
    assertThat(result.isSuccessful(), is(true));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 60 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class EnvironmentConfigServiceTest method shouldCreateANewEnvironmentWithEnvironmentVariables.

@Test
public void shouldCreateANewEnvironmentWithEnvironmentVariables() {
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    List<String> selectedAgents = new ArrayList<>();
    Username user = new Username(new CaseInsensitiveString("user"));
    when(securityService.isUserAdmin(user)).thenReturn(true);
    String environmentName = "foo-environment";
    when(mockGoConfigService.hasEnvironmentNamed(new CaseInsensitiveString(environmentName))).thenReturn(false);
    List<Map<String, String>> environmentVariables = new ArrayList<>();
    environmentVariables.addAll(Arrays.asList(envVar("SHELL", "/bin/zsh"), envVar("HOME", "/home/cruise")));
    environmentConfigService.createEnvironment(env(environmentName, new ArrayList<>(), environmentVariables, selectedAgents), user, result);
    assertThat(result.isSuccessful(), is(true));
    BasicEnvironmentConfig expectedConfig = new BasicEnvironmentConfig(new CaseInsensitiveString(environmentName));
    expectedConfig.addEnvironmentVariable("SHELL", "/bin/zsh");
    expectedConfig.addEnvironmentVariable("HOME", "/home/cruise");
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) Matchers.containsString(org.hamcrest.Matchers.containsString) 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