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