use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class AgentServiceIntegrationTest method shouldAllowEnableOfPendingAgent.
@Test
public void shouldAllowEnableOfPendingAgent() {
String agentName = "agentName";
String agentId = DatabaseAccessHelper.AGENT_UUID;
AgentConfig agentConfig = new AgentConfig(agentId, agentName, "50.40.30.9");
AgentRuntimeInfo agentRuntimeInfo = new AgentRuntimeInfo(agentConfig.getAgentIdentifier(), AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false);
agentRuntimeInfo.busy(new AgentBuildingInfo("path", "buildLocator"));
agentService.requestRegistration(new Username("bob"), agentRuntimeInfo);
HttpOperationResult operationResult = new HttpOperationResult();
agentService.enableAgents(USERNAME, operationResult, Arrays.asList(agentId));
assertThat(operationResult.httpCode(), is(200));
assertThat(operationResult.message(), is("Enabled 1 agent(s)"));
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class AgentServiceIntegrationTest method shouldNOTDeleteDisabledAgentThatIsBuildingGivenUUID.
@Test
public void shouldNOTDeleteDisabledAgentThatIsBuildingGivenUUID() throws Exception {
AgentConfig disabledButBuildingAgent = createDisabledAgent(UUID);
goConfigDao.load();
assertThat(agentService.agents().size(), is(1));
HttpOperationResult operationResult = new HttpOperationResult();
agentService.deleteAgents(USERNAME, operationResult, Arrays.asList(disabledButBuildingAgent.getUuid()));
assertThat(operationResult.httpCode(), is(406));
assertThat(operationResult.message(), is("Failed to delete 1 agent(s), as agent(s) might not be disabled or are still building."));
assertThat(agentService.agents().size(), is(1));
assertTrue(agentService.agents().hasAgent(UUID));
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.
the class AgentServiceIntegrationTest method shouldDeleteOnlyDisabledAgentGivenUUID.
@Test
public void shouldDeleteOnlyDisabledAgentGivenUUID() throws Exception {
AgentConfig disabledAgent = createDisabledAndIdleAgent(UUID);
AgentConfig enabledAgent = createEnabledAgent(UUID2);
goConfigDao.load();
assertThat(agentService.agents().size(), is(2));
HttpOperationResult disabledAgentOperationResult = new HttpOperationResult();
HttpOperationResult enabledAgentOperationResult = new HttpOperationResult();
agentService.deleteAgents(USERNAME, disabledAgentOperationResult, Arrays.asList(disabledAgent.getUuid()));
agentService.deleteAgents(USERNAME, enabledAgentOperationResult, Arrays.asList(enabledAgent.getUuid()));
assertThat(disabledAgentOperationResult.httpCode(), is(200));
assertThat(disabledAgentOperationResult.message(), is("Deleted 1 agent(s)."));
assertThat(enabledAgentOperationResult.httpCode(), is(406));
assertThat(enabledAgentOperationResult.message(), is("Failed to delete 1 agent(s), as agent(s) might not be disabled or are still building."));
assertThat(agentService.agents().size(), is(1));
assertTrue(agentService.agents().hasAgent(UUID2));
}
use of com.thoughtworks.go.server.service.result.HttpOperationResult 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.server.service.result.HttpOperationResult in project gocd by gocd.
the class AgentServiceIntegrationTest method shouldReturn401WhenAUnauthorizedUserTriesToDeleteAgents.
@Test
public void shouldReturn401WhenAUnauthorizedUserTriesToDeleteAgents() throws IOException {
CONFIG_HELPER.enableSecurity();
HttpOperationResult operationResult = new HttpOperationResult();
CONFIG_HELPER.addAdmins("admin1");
agentService.deleteAgents(new Username(new CaseInsensitiveString("not-admin")), operationResult, Arrays.asList(UUID));
assertThat(operationResult.httpCode(), is(401));
assertThat(operationResult.message(), is("Unauthorized to operate on agent"));
}
Aggregations