Search in sources :

Example 76 with HttpOperationResult

use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldAddResourcesToMultipleAgents.

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

Example 77 with HttpOperationResult

use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.

the class AgentServiceIntegrationTest method updateAgentAttributesShouldUpdateAnAgentDisableState.

@Test
public void updateAgentAttributesShouldUpdateAnAgentDisableState() throws Exception {
    AgentConfig agent = createEnabledAgent(UUID);
    goConfigDao.load();
    assertThat(agentService.agents().size(), is(1));
    assertThat(getFirstAgent().isDisabled(), is(false));
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.updateAgentAttributes(USERNAME, operationResult, UUID, null, null, null, TriState.FALSE);
    assertThat(operationResult.httpCode(), is(200));
    assertThat(operationResult.message(), is("Updated agent with uuid uuid."));
    assertThat(agentService.agents().size(), is(1));
    assertThat(getFirstAgent().isDisabled(), is(true));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Test(org.junit.Test)

Example 78 with HttpOperationResult

use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldReturn404WhenAgentUUIDNotKnown.

@Test
public void shouldReturn404WhenAgentUUIDNotKnown() {
    // pending matches that as well
    String agentId = "unknown-agent-id";
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.enableAgents(USERNAME, operationResult, Arrays.asList(agentId));
    assertThat(operationResult.httpCode(), is(404));
    assertThat(operationResult.message(), is("Agent not found."));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Test(org.junit.Test)

Example 79 with HttpOperationResult

use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldReturn401WhenAUnauthorizedUserTriesToDelete.

@Test
public void shouldReturn401WhenAUnauthorizedUserTriesToDelete() 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)

Example 80 with HttpOperationResult

use of com.thoughtworks.go.server.service.result.HttpOperationResult in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldBeAbleToDenyBuildingAgent.

@Test
public void shouldBeAbleToDenyBuildingAgent() throws Exception {
    String agentName = "agentName";
    String agentId = DatabaseAccessHelper.AGENT_UUID;
    AgentConfig agentConfig = new AgentConfig(agentId, agentName, "127.0.0.9");
    addAgent(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);
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.disableAgents(USERNAME, operationResult, Arrays.asList(agentId));
    assertAgentDisablingSucceeded(operationResult, agentId);
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) 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