Search in sources :

Example 61 with Username

use of com.thoughtworks.go.server.domain.Username 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 62 with Username

use of com.thoughtworks.go.server.domain.Username 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 63 with Username

use of com.thoughtworks.go.server.domain.Username 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 64 with Username

use of com.thoughtworks.go.server.domain.Username 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 65 with Username

use of com.thoughtworks.go.server.domain.Username 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

Username (com.thoughtworks.go.server.domain.Username)391 Test (org.junit.Test)317 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)170 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)81 Before (org.junit.Before)42 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)36 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)33 Pipeline (com.thoughtworks.go.domain.Pipeline)30 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)27 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)21 StringContains.containsString (org.hamcrest.core.StringContains.containsString)20 Modification (com.thoughtworks.go.domain.materials.Modification)17 ArrayList (java.util.ArrayList)16 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)15 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)14 TimeProvider (com.thoughtworks.go.util.TimeProvider)13 UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)12 Date (java.util.Date)12 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)11 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)10