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));
}
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."));
}
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"));
}
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));
}
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));
}
Aggregations