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