Search in sources :

Example 16 with HttpOperationResult

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

the class AgentServiceIntegrationTest method updateAgentAttributesShouldNotUpdateAgentEnableStateIfTristateIsNotDefined.

@Test
public void updateAgentAttributesShouldNotUpdateAgentEnableStateIfTristateIsNotDefined() throws Exception {
    AgentConfig enabledAgent = createEnabledAgent("enabled");
    AgentConfig disabledAgent = createDisabledAgent("disabled");
    goConfigDao.load();
    assertThat(agentService.agents().size(), is(2));
    assertThat(agentService.findAgentAndRefreshStatus("enabled").agentConfig().isDisabled(), is(false));
    assertThat(agentService.findAgentAndRefreshStatus("disabled").agentConfig().isDisabled(), is(true));
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.updateAgentAttributes(USERNAME, operationResult, "enabled", "new.enabled.hostname", "linux,java", null, TriState.UNSET);
    agentService.updateAgentAttributes(USERNAME, operationResult, "disabled", "new.disabled.hostname", "linux,java", null, TriState.UNSET);
    assertThat(operationResult.httpCode(), is(200));
    assertThat(agentService.agents().size(), is(2));
    assertThat(agentService.findAgentAndRefreshStatus("enabled").agentConfig().isDisabled(), is(false));
    assertThat(agentService.findAgentAndRefreshStatus("disabled").agentConfig().isDisabled(), is(true));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Test(org.junit.Test)

Example 17 with HttpOperationResult

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

Example 18 with HttpOperationResult

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

the class AgentServiceIntegrationTest method shouldReturn200OnTryingToDisableADisabledAgent.

@Test
public void shouldReturn200OnTryingToDisableADisabledAgent() {
    String agentName = "agentName";
    String agentId = DatabaseAccessHelper.AGENT_UUID;
    AgentConfig agentConfig = new AgentConfig(agentId, agentName, "127.0.0.9");
    addAgent(agentConfig);
    disable(agentConfig);
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.disableAgents(USERNAME, operationResult, Arrays.asList(agentId));
    assertThat(operationResult.httpCode(), is(200));
    assertThat(operationResult.message(), is("Disabled 1 agent(s)"));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Test(org.junit.Test)

Example 19 with HttpOperationResult

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

the class AgentServiceIntegrationTest method shouldAddEnvironmentsToMultipleAgents.

@Test
public void shouldAddEnvironmentsToMultipleAgents() throws Exception {
    createEnvironment("uat", "prod");
    createEnabledAgent(UUID);
    createEnabledAgent(UUID2);
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.modifyEnvironments(USERNAME, operationResult, Arrays.asList(UUID, UUID2), Arrays.asList(new TriStateSelection("uat", TriStateSelection.Action.add), new TriStateSelection("prod", TriStateSelection.Action.add)));
    assertThat(operationResult.httpCode(), is(200));
    assertThat(operationResult.message(), is("Environment(s) modified on 2 agent(s)"));
    assertThat(environmentConfigService.environmentsFor(UUID), containsSet("uat", "prod"));
    assertThat(environmentConfigService.environmentsFor(UUID2), containsSet("uat", "prod"));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 20 with HttpOperationResult

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

the class AgentServiceIntegrationTest method shouldSetErrorState404OnTryingToDisableUnknownAgent.

@Test
public void shouldSetErrorState404OnTryingToDisableUnknownAgent() {
    // pending matches this as well
    String agentId = "unknown-agent-id";
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.disableAgents(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)

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