Search in sources :

Example 11 with TriStateSelection

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:"));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 12 with TriStateSelection

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);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) ArrayList(java.util.ArrayList) AgentConfigsUpdateValidator(com.thoughtworks.go.validation.AgentConfigsUpdateValidator) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection)

Example 13 with TriStateSelection

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);
}
Also used : TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection)

Example 14 with TriStateSelection

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);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 15 with TriStateSelection

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Aggregations

TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)30 Test (org.junit.Test)24 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)13 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)12 Username (com.thoughtworks.go.server.domain.Username)5 GoConfigFileHelper (com.thoughtworks.go.util.GoConfigFileHelper)2 Before (org.junit.Before)2 UpdateConfigCommand (com.thoughtworks.go.config.UpdateConfigCommand)1 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)1 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)1 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)1 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)1 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)1 GoCipher (com.thoughtworks.go.security.GoCipher)1 AgentConfigsUpdateValidator (com.thoughtworks.go.validation.AgentConfigsUpdateValidator)1 ArrayList (java.util.ArrayList)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 ExpectedException (org.junit.rules.ExpectedException)1