use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.
the class GoConfigService method modifyEnvironments.
public void modifyEnvironments(List<AgentInstance> agents, List<TriStateSelection> selections) {
GoConfigDao.CompositeConfigCommand command = new GoConfigDao.CompositeConfigCommand();
for (AgentInstance agentInstance : agents) {
String uuid = agentInstance.getUuid();
if (hasAgent(uuid)) {
for (TriStateSelection selection : selections) {
command.addCommand(new ModifyEnvironmentCommand(uuid, selection.getValue(), selection.getAction()));
}
}
}
updateConfig(command);
}
use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.
the class AgentServiceIntegrationTest method shouldRespondToAgentEnvironmentModificationRequestWith406WhenErrors.
@Test
public void shouldRespondToAgentEnvironmentModificationRequestWith406WhenErrors() throws Exception {
createEnabledAgent(UUID);
HttpOperationResult operationResult = new HttpOperationResult();
agentService.modifyEnvironments(USERNAME, operationResult, Arrays.asList(UUID), Arrays.asList(new TriStateSelection("unknown_env", TriStateSelection.Action.add)));
assertThat(operationResult.httpCode(), is(406));
assertThat(operationResult.message(), containsString("Could not modify environments:"));
}
use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.
the class AgentServiceIntegrationTest method shouldNotAllowAddingResourcesWhenNotAdmin.
@Test
public void shouldNotAllowAddingResourcesWhenNotAdmin() throws IOException {
String agentId = "agent-id";
CONFIG_HELPER.enableSecurity();
HttpOperationResult operationResult = new HttpOperationResult();
CONFIG_HELPER.addAdmins("admin1");
agentService.modifyResources(new Username(new CaseInsensitiveString("not-admin")), operationResult, Arrays.asList(agentId), Arrays.asList(new TriStateSelection("dont-care", TriStateSelection.Action.add)));
assertThat(operationResult.httpCode(), is(401));
assertThat(operationResult.message(), is("Unauthorized to operate on agent"));
}
use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.
the class AgentServiceIntegrationTest method shouldNotChangeEnvironmentsOtherThanTheOneRemoveIsRequestedFor.
@Test
public void shouldNotChangeEnvironmentsOtherThanTheOneRemoveIsRequestedFor() throws Exception {
createEnvironment("uat", "prod");
createEnabledAgent(UUID);
addAgentToEnv("uat", UUID);
addAgentToEnv("prod", UUID);
HttpOperationResult operationResult = new HttpOperationResult();
agentService.modifyEnvironments(USERNAME, operationResult, Arrays.asList(UUID), Arrays.asList(new TriStateSelection("uat", TriStateSelection.Action.remove)));
assertThat(operationResult.httpCode(), is(200));
assertThat(operationResult.message(), is("Environment(s) modified on 1 agent(s)"));
assertThat(environmentConfigService.environmentsFor(UUID), not(containsSet("uat")));
assertThat(environmentConfigService.environmentsFor(UUID), containsSet("prod"));
}
use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.
the class AgentServiceIntegrationTest method shouldAddEnvironmentsToMultipleAgents.
@Test
public void shouldAddEnvironmentsToMultipleAgents() throws Exception {
createEnvironment("uat", "prod");
createEnabledAgent(UUID);
createEnabledAgent(UUID2);
HttpOperationResult operationResult = new HttpOperationResult();
agentService.modifyEnvironments(USERNAME, operationResult, Arrays.asList(UUID, UUID2), Arrays.asList(new TriStateSelection("uat", TriStateSelection.Action.add), new TriStateSelection("prod", TriStateSelection.Action.add)));
assertThat(operationResult.httpCode(), is(200));
assertThat(operationResult.message(), is("Environment(s) modified on 2 agent(s)"));
assertThat(environmentConfigService.environmentsFor(UUID), containsSet("uat", "prod"));
assertThat(environmentConfigService.environmentsFor(UUID2), containsSet("uat", "prod"));
}
Aggregations