use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class AgentServiceIntegrationTest method shouldNOTDeleteAnyAgentIfAtLeastOneOfTheRequestedAgentIsNotDisabled.
@Test
public void shouldNOTDeleteAnyAgentIfAtLeastOneOfTheRequestedAgentIsNotDisabled() throws Exception {
AgentConfig disabledAgent = createDisabledAndIdleAgent(UUID);
AgentConfig enabledAgent = createEnabledAgent(UUID2);
goConfigDao.load();
assertThat(agentService.agents().size(), is(2));
HttpOperationResult operationResult = new HttpOperationResult();
agentService.deleteAgents(USERNAME, operationResult, Arrays.asList(disabledAgent.getUuid(), enabledAgent.getUuid()));
assertThat(operationResult.httpCode(), is(406));
assertThat(operationResult.message(), is("Failed to delete 2 agent(s), as agent(s) might not be disabled or are still building."));
assertThat(agentService.agents().size(), is(2));
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class AgentServiceIntegrationTest method shouldDeleteAgentsGivenListOfUUIDs.
@Test
public void shouldDeleteAgentsGivenListOfUUIDs() throws Exception {
AgentConfig disabledAgent1 = createDisabledAndIdleAgent(UUID);
AgentConfig disabledAgent2 = createDisabledAndIdleAgent(UUID2);
goConfigDao.load();
assertThat(agentService.agents().size(), is(2));
HttpOperationResult operationResult = new HttpOperationResult();
agentService.deleteAgents(USERNAME, operationResult, Arrays.asList(disabledAgent1.getUuid(), disabledAgent2.getUuid()));
assertThat(operationResult.httpCode(), is(200));
assertThat(operationResult.message(), is("Deleted 2 agent(s)."));
assertThat(agentService.agents().size(), is(0));
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult 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.server.service.result.HttpOperationResult in project gocd by gocd.
the class AgentServiceIntegrationTest method disable.
private void disable(AgentConfig agentConfig) {
AgentIdentifier agentIdentifier = agentConfig.getAgentIdentifier();
String cookie = agentService.assignCookie(agentIdentifier);
AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), cookie, false);
agentRuntimeInfo.busy(new AgentBuildingInfo("path", "buildLocator"));
agentService.updateRuntimeInfo(agentRuntimeInfo);
agentService.disableAgents(USERNAME, new HttpOperationResult(), Arrays.asList(agentConfig.getUuid()));
assertThat(isDisabled(agentConfig), is(true));
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class AgentServiceIntegrationTest method shouldDenyApprovedAgent.
@Test
public void shouldDenyApprovedAgent() throws Exception {
CONFIG_HELPER.addAgent(new AgentConfig(UUID, "agentName", "127.0.0.9"));
CruiseConfig cruiseConfig = goConfigDao.load();
assertThat(cruiseConfig.agents().get(0).isDisabled(), is(false));
agentService.initialize();
HttpOperationResult operationResult = new HttpOperationResult();
agentService.disableAgents(USERNAME, operationResult, Arrays.asList(UUID));
CruiseConfig newCruiseConfig = goConfigDao.load();
assertThat(newCruiseConfig.agents().get(0).isDisabled(), is(true));
assertAgentDisablingSucceeded(operationResult, UUID);
}
Aggregations