Search in sources :

Example 6 with HttpOperationResult

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

Example 7 with HttpOperationResult

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

Example 8 with HttpOperationResult

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

Example 9 with HttpOperationResult

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

Example 10 with HttpOperationResult

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

Aggregations

HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)146 Test (org.junit.jupiter.api.Test)64 Test (org.junit.Test)53 Username (com.thoughtworks.go.server.domain.Username)34 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)23 TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)12 Pagination (com.thoughtworks.go.server.util.Pagination)7 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)6 StageStatusCache (com.thoughtworks.go.domain.activity.StageStatusCache)6 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)6 StageStatusTopic (com.thoughtworks.go.server.messaging.StageStatusTopic)6 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)5 AgentInstance (com.thoughtworks.go.domain.AgentInstance)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)4 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)4 NullStage (com.thoughtworks.go.domain.NullStage)4 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)4 PipelineStatusModel (com.thoughtworks.go.presentation.PipelineStatusModel)4 Stage (com.thoughtworks.go.domain.Stage)3