Search in sources :

Example 86 with HttpOperationResult

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

the class AgentServiceIntegrationTest method updateAgentAttributesShouldUpdateAnAgentEnvironments.

@Test
public void updateAgentAttributesShouldUpdateAnAgentEnvironments() throws Exception {
    createEnvironment("a", "b", "c", "d", "e");
    AgentConfig agent = createEnabledAgent(UUID);
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.modifyEnvironments(USERNAME, operationResult, Arrays.asList(UUID), Arrays.asList(new TriStateSelection("a", TriStateSelection.Action.add), new TriStateSelection("b", TriStateSelection.Action.add), new TriStateSelection("c", TriStateSelection.Action.add)));
    assertThat(operationResult.httpCode(), is(200));
    goConfigDao.load();
    assertThat(agentService.agents().size(), is(1));
    assertThat(getFirstAgent().getResourceConfigs(), is(empty()));
    operationResult = new HttpOperationResult();
    agentService.updateAgentAttributes(USERNAME, operationResult, UUID, null, null, "c,d,e", TriState.UNSET);
    assertThat(operationResult.httpCode(), is(200));
    assertThat(operationResult.message(), is("Updated agent with uuid uuid."));
    assertThat(agentService.agents().size(), is(1));
    assertThat(getEnvironments(getFirstAgent().getUuid()).equals(new HashSet<>(Arrays.asList("c", "d", "e"))), is(true));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 87 with HttpOperationResult

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

the class AgentServiceIntegrationTest method shouldReturn404WhenAgentUUIDNotKnownForDeleteAgents.

@Test
public void shouldReturn404WhenAgentUUIDNotKnownForDeleteAgents() {
    String agentId = "unknown-agent-id";
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.deleteAgents(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 88 with HttpOperationResult

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

the class AgentServiceIntegrationTest method shouldReturn401WhenAUnauthorizedUserTriesToEnable.

@Test
public void shouldReturn401WhenAUnauthorizedUserTriesToEnable() throws IOException {
    String agentId = "agent-id";
    CONFIG_HELPER.enableSecurity();
    HttpOperationResult operationResult = new HttpOperationResult();
    CONFIG_HELPER.addAdmins("admin1");
    agentService.enableAgents(new Username(new CaseInsensitiveString("not-admin")), operationResult, Arrays.asList(agentId));
    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 89 with HttpOperationResult

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

the class PipelineHistoryServiceTest method shouldReturnGraphWithADiffOfMaterialRevisionsForTheGivenPipeline.

@Test
public void shouldReturnGraphWithADiffOfMaterialRevisionsForTheGivenPipeline() throws Exception {
    PipelineInstanceModel pim = pim("blahPipeline");
    MaterialRevisions actualRevs = ModificationsMother.multipleModifications();
    pim.setId(23);
    pim.setMaterialRevisionsOnBuildCause(actualRevs);
    PipelineDependencyGraphOld expected = new PipelineDependencyGraphOld(pim, createPipelineInstanceModels());
    when(pipelineDao.pipelineGraphByNameAndCounter("blahPipeline", 12)).thenReturn(expected);
    ensureConfigHasPipeline("blahPipeline");
    when(goConfigService.downstreamPipelinesOf("blahPipeline")).thenReturn(new ArrayList<>());
    stubConfigServiceToReturnPipeline("blahPipeline", PipelineConfigMother.pipelineConfig("blahPipeline"));
    when(pipelineTimeline.pipelineBefore(23)).thenReturn(1L);
    when(pipelineDao.loadHistory(1L)).thenReturn(new PipelineInstanceModel("blahPipeline", 21, "prev-label", BuildCause.createWithEmptyModifications(), new StageInstanceModels()));
    ensureHasPermission(USERNAME, "blahPipeline");
    PipelineDependencyGraphOld actual = pipelineHistoryService.pipelineDependencyGraph("blahPipeline", 12, USERNAME, new HttpOperationResult());
    assertThat(actual.pipeline().getPreviousLabel(), is("prev-label"));
    assertThat(actual.pipeline().getPreviousCounter(), is(21));
    assertThat(actual.pipeline().getCurrentRevisions(), is(actualRevs));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) Test(org.junit.Test)

Example 90 with HttpOperationResult

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

the class PipelineHistoryServiceTest method shouldRemoveDependencyPipelineWhichIsNotPresentInConfig.

@Test
public void shouldRemoveDependencyPipelineWhichIsNotPresentInConfig() throws Exception {
    ensureConfigHasPipeline("blahPipeline");
    ensureConfigHasPipeline("down1");
    ensureConfigContainsPipelineIs("down2", false);
    when(goConfigService.downstreamPipelinesOf("blahPipeline")).thenReturn(Arrays.asList(PipelineConfigMother.pipelineConfig("down1")));
    stubConfigServiceToReturnPipeline("blahPipeline", PipelineConfigMother.pipelineConfig("blahPipeline"));
    PipelineConfig downOneConfig = PipelineConfigMother.pipelineConfig("down1");
    stubConfigServiceToReturnPipeline("down1", downOneConfig);
    when(goConfigService.isLockable("blahPipeline")).thenReturn(true);
    when(pipelineUnlockService.canUnlock("blahPipeline", USERNAME, new HttpOperationResult())).thenReturn(true);
    when(pipelineTimeline.pipelineBefore(23)).thenReturn(-1L);
    ensureHasPermission(USERNAME, "blahPipeline");
    ensureHasPermission(USERNAME, "down1");
    PipelineInstanceModel actualPim = pim("down1");
    actualPim.setCanRun(false);
    actualPim.setStageHistory(PipelineHistoryMother.stagePerJob("stage", PipelineHistoryMother.job(JobResult.Failed)));
    PipelineInstanceModel returned = pim("blahPipeline");
    returned.setId(23);
    PipelineDependencyGraphOld graph = new PipelineDependencyGraphOld(returned, createPipelineInstanceModels(actualPim, pim("down2")));
    when(pipelineDao.pipelineGraphByNameAndCounter("blahPipeline", 12)).thenReturn(graph);
    when(schedulingCheckerService.canManuallyTrigger(actualPim.getName(), USERNAME)).thenReturn(true);
    PipelineDependencyGraphOld actual = pipelineHistoryService.pipelineDependencyGraph("blahPipeline", 12, USERNAME, new HttpOperationResult());
    assertThat(actual.dependencies().size(), is(1));
    assertThat(actual.dependencies().get(0), is(actualPim));
    assertThat(actual.dependencies().get(0).getCanRun(), is(true));
}
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