Search in sources :

Example 6 with TriStateSelection

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

Example 7 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldRemoveResourcesFromMultipleAgents.

@Test
public void shouldRemoveResourcesFromMultipleAgents() {
    createEnabledAgent(UUID);
    createEnabledAgent(UUID2);
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.modifyResources(USERNAME, operationResult, Arrays.asList(UUID, UUID2), Arrays.asList(new TriStateSelection("resource-1", TriStateSelection.Action.add), new TriStateSelection("resource-2", TriStateSelection.Action.add)));
    agentService.modifyResources(USERNAME, operationResult, Arrays.asList(UUID, UUID2), Arrays.asList(new TriStateSelection("resource-1", TriStateSelection.Action.remove)));
    assertThat(operationResult.httpCode(), is(200));
    assertThat(operationResult.message(), is("Resource(s) modified on 2 agent(s)"));
    assertThat(agentService.findAgentAndRefreshStatus(UUID).agentConfig().getResources(), hasItem(new Resource("resource-2")));
    assertThat(agentService.findAgentAndRefreshStatus(UUID).agentConfig().getResources(), not(hasItem(new Resource("resource-1"))));
    assertThat(agentService.findAgentAndRefreshStatus(UUID2).agentConfig().getResources(), hasItem(new Resource("resource-2")));
    assertThat(agentService.findAgentAndRefreshStatus(UUID2).agentConfig().getResources(), not(hasItem(new Resource("resource-1"))));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 8 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class AgentServiceIntegrationTest method testShouldNotUpdateHostnameOrResourcesOrEnvironmentsIfNoneAreSpecified.

@Test
public void testShouldNotUpdateHostnameOrResourcesOrEnvironmentsIfNoneAreSpecified() throws Exception {
    createEnvironment("a", "b");
    AgentConfig agent = createDisabledAndIdleAgent(UUID);
    String originalHostname = agent.getHostname();
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.modifyEnvironments(USERNAME, operationResult, Arrays.asList(UUID), Arrays.asList(new TriStateSelection("a", TriStateSelection.Action.add), new TriStateSelection("b", TriStateSelection.Action.add)));
    goConfigDao.load();
    agentConfigService.updateAgentResources(agent.getUuid(), new Resources("linux,java"));
    assertThat(agentService.agents().size(), is(1));
    operationResult = new HttpOperationResult();
    agentService.updateAgentAttributes(USERNAME, operationResult, UUID, null, null, null, TriState.UNSET);
    assertThat(operationResult.httpCode(), is(200));
    assertThat(operationResult.message(), is("Updated agent with uuid uuid."));
    assertThat(agentService.agents().size(), is(1));
    assertThat(getFirstAgent().getHostname(), is(originalHostname));
    assertThat(getFirstAgent().getResources().resourceNames(), is(new Resources("linux,java").resourceNames()));
    assertEquals(getEnvironments(getFirstAgent().getUuid()), new HashSet<>(Arrays.asList("a", "b")));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 9 with TriStateSelection

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

Example 10 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldNotAllowUpdatingEnvironmentsWhenNotAdmin.

@Test
public void shouldNotAllowUpdatingEnvironmentsWhenNotAdmin() throws IOException {
    String agentId = "agent-id";
    HttpOperationResult operationResult = new HttpOperationResult();
    CONFIG_HELPER.addSecurityWithPasswordFile();
    CONFIG_HELPER.addAdmins("admin1");
    agentService.modifyEnvironments(new Username(new CaseInsensitiveString("not-admin")), operationResult, Arrays.asList(UUID), Arrays.asList(new TriStateSelection("uat", TriStateSelection.Action.remove)));
    assertThat(operationResult.httpCode(), is(401));
    assertThat(operationResult.message(), is("Unauthorized to operate on agent"));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Username(com.thoughtworks.go.server.domain.Username) 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