Search in sources :

Example 71 with HttpOperationResult

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

the class AgentServiceIntegrationTest method shouldEnableMultipleAgents.

@Test
public void shouldEnableMultipleAgents() {
    AgentConfig agentConfig1 = createDisabledAgent(UUID);
    AgentConfig agentConfig2 = createDisabledAgent(UUID2);
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.enableAgents(USERNAME, operationResult, Arrays.asList(UUID, UUID2));
    assertThat(operationResult.httpCode(), is(200));
    assertThat(isDisabled(agentConfig1), is(false));
    assertThat(isDisabled(agentConfig2), is(false));
    assertThat(operationResult.message(), containsString("Enabled 2 agent(s)"));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Test(org.junit.Test)

Example 72 with HttpOperationResult

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

the class AgentServiceIntegrationTest method shouldDenyCorrectAgentWhenTwoOnSameBox.

@Test
public void shouldDenyCorrectAgentWhenTwoOnSameBox() throws Exception {
    CONFIG_HELPER.addAgent(new AgentConfig(UUID, "agentName", "127.0.0.9", new ResourceConfigs("agent1")));
    CONFIG_HELPER.addAgent(new AgentConfig(UUID2, "agentName", "127.0.0.9", new ResourceConfigs("agent2")));
    CruiseConfig cruiseConfig = goConfigDao.load();
    assertThat(cruiseConfig.agents().getAgentByUuid(UUID).isDisabled(), is(false));
    assertThat(cruiseConfig.agents().getAgentByUuid(UUID2).isDisabled(), is(false));
    agentService.initialize();
    agentService.disableAgents(USERNAME, new HttpOperationResult(), Arrays.asList(UUID2));
    CruiseConfig newCruiseConfig = goConfigDao.load();
    assertThat(newCruiseConfig.agents().getAgentByUuid(UUID).isDisabled(), is(false));
    assertThat(newCruiseConfig.agents().getAgentByUuid(UUID2).isDisabled(), is(true));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Test(org.junit.Test)

Example 73 with HttpOperationResult

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

the class AgentServiceIntegrationTest method updateAgentAttributesShouldUpdateAnAgentEnableState.

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

Example 74 with HttpOperationResult

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

the class AgentServiceIntegrationTest method shouldAllowEnablingOfADisabledAgent.

@Test
public void shouldAllowEnablingOfADisabledAgent() {
    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.enableAgents(USERNAME, operationResult, Arrays.asList(agentId));
    assertThat(operationResult.httpCode(), is(200));
    assertThat(operationResult.message(), is("Enabled 1 agent(s)"));
    assertThat(isDisabled(agentConfig), is(false));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Test(org.junit.Test)

Example 75 with HttpOperationResult

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

the class AgentServiceIntegrationTest method testShouldUpdateAnAgentIfInputsAreValid.

@Test
public void testShouldUpdateAnAgentIfInputsAreValid() throws Exception {
    String headCommitBeforeUpdate = configRepository.getCurrentRevCommit().name();
    AgentConfig agent = createDisabledAndIdleAgent(UUID);
    createEnvironment("a", "b");
    goConfigDao.load();
    assertThat(agentService.agents().size(), is(1));
    assertThat(getFirstAgent().getHostname(), is(not("some-hostname")));
    assertThat(getFirstAgent().isDisabled(), is(true));
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.updateAgentAttributes(USERNAME, operationResult, UUID, "some-hostname", "linux,java", "a,b", TriState.UNSET);
    assertThat(operationResult.httpCode(), is(200));
    assertThat(operationResult.message(), is("Updated agent with uuid uuid."));
    assertThat(agentService.agents().size(), is(1));
    assertThat(getFirstAgent().getHostname(), is("some-hostname"));
    assertThat(getFirstAgent().getResourceConfigs(), is(new ResourceConfigs("linux,java")));
    assertThat(getFirstAgent().isDisabled(), is(true));
    assertEquals(getEnvironments(getFirstAgent().getUuid()), new HashSet<>(Arrays.asList("a", "b")));
    assertThat(configRepository.getCurrentRevCommit().name(), is(not(headCommitBeforeUpdate)));
    assertThat(configRepository.getCurrentRevision().getUsername(), is(USERNAME.getDisplayName()));
}
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