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 AgentConfigService method modifyResources.
public void modifyResources(AgentInstance[] agentInstances, List<TriStateSelection> selections, Username currentUser) {
GoConfigDao.CompositeConfigCommand command = new GoConfigDao.CompositeConfigCommand();
ArrayList<String> uuids = new ArrayList<>();
for (AgentInstance agentInstance : agentInstances) {
String uuid = agentInstance.getUuid();
uuids.add(uuid);
if (goConfigService.hasAgent(uuid)) {
for (TriStateSelection selection : selections) {
command.addCommand(new ModifyResourcesCommand(uuid, new Resource(selection.getValue()), selection.getAction()));
}
}
}
AgentConfigsUpdateValidator validator = new AgentConfigsUpdateValidator(uuids);
updateAgents(command, validator, currentUser);
}
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 UserServiceIntegrationTest method getRoleSelection.
@Test
public void getRoleSelection() throws Exception {
configFileHelper.addRole(new RoleConfig(new CaseInsensitiveString("dev")));
configFileHelper.addRole(new RoleConfig(new CaseInsensitiveString("boy")));
configFileHelper.addRole(new RoleConfig(new CaseInsensitiveString("girl")));
configFileHelper.addRole(new RoleConfig(new CaseInsensitiveString("none")));
addUser(new User("yogi"));
addUser(new User("shilpa"));
addUser(new User("pavan"));
userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("yogi", "shilpa"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.nochange), Arrays.asList(new TriStateSelection("dev", TriStateSelection.Action.add)), new HttpLocalizedOperationResult());
userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("shilpa"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.nochange), Arrays.asList(new TriStateSelection("girl", TriStateSelection.Action.add)), new HttpLocalizedOperationResult());
userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("yogi"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.nochange), Arrays.asList(new TriStateSelection("boy", TriStateSelection.Action.add)), new HttpLocalizedOperationResult());
userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("pavan"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.nochange), Arrays.asList(new TriStateSelection("none", TriStateSelection.Action.add)), new HttpLocalizedOperationResult());
List<TriStateSelection> selections = userService.getAdminAndRoleSelections(Arrays.asList("yogi", "shilpa")).getRoleSelections();
assertThat(selections.size(), is(4));
assertRoleSelection(selections.get(0), "boy", TriStateSelection.Action.nochange);
assertRoleSelection(selections.get(1), "dev", TriStateSelection.Action.add);
assertRoleSelection(selections.get(2), "girl", TriStateSelection.Action.nochange);
assertRoleSelection(selections.get(3), "none", TriStateSelection.Action.remove);
}
use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.
the class UserServiceIntegrationTest method modifyRoles_shouldCreateRoleAndAddUserIfRoleDoesntExist.
@Test
public void modifyRoles_shouldCreateRoleAndAddUserIfRoleDoesntExist() throws Exception {
addUser(new User("user-1"));
userService.modifyRolesAndUserAdminPrivileges(Arrays.asList("user-1"), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.nochange), Arrays.asList(new TriStateSelection("dev", TriStateSelection.Action.add)), new HttpLocalizedOperationResult());
CruiseConfig cruiseConfig = goConfigDao.load();
assertThat(cruiseConfig.server().security().getRoles().findByName(new CaseInsensitiveString("dev")).hasMember(new CaseInsensitiveString("user-1")), is(true));
}
Aggregations