use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class JobStatusJsonPresentationModelTest method shouldReturnNotYetAssignedIfAgentUuidIsNull.
@Test
public void shouldReturnNotYetAssignedIfAgentUuidIsNull() {
JobInstance instance = building("Plan1");
instance.setAgentUuid(null);
// "Not assigned" should depend on whether or not the JobInstance has an agentUuid, regardless of
// the Agent object passed to the presenter, as this is the canonical definition of job assignment
JobStatusJsonPresentationModel presenter = new JobStatusJsonPresentationModel(instance, mock(Agent.class), mock(DurationBean.class));
assertThatJson(new Gson().toJson(presenter.toJsonHash())).when(IGNORING_EXTRA_FIELDS).isEqualTo("{\n \"agent\": \"Not yet assigned\"\n}");
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class JobStatusJsonPresentationModelTest method shouldReturnAgentHostname.
@Test
public void shouldReturnAgentHostname() {
JobInstance instance = building("Plan1");
instance.setAgentUuid("1234");
JobStatusJsonPresentationModel presenter = new JobStatusJsonPresentationModel(instance, new Agent("1234", "localhost", "address", "cookie"), mock(DurationBean.class));
assertThatJson(new Gson().toJson(presenter.toJsonHash())).when(IGNORING_EXTRA_FIELDS).isEqualTo("{\n" + " \"agent\": \"localhost\"\n" + "}");
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class ElasticAgentRequestProcessorV1Test method shouldProcessDeleteAgentRequest.
@Test
public void shouldProcessDeleteAgentRequest() {
AgentInstance agentInstance = AgentInstance.createFromAgent(new Agent("uuid"), null, null);
when(request.api()).thenReturn(REQUEST_DELETE_AGENTS);
when(request.requestBody()).thenReturn("[{\"agent_id\":\"foo\"}]");
when(agentService.findElasticAgent("foo", "cd.go.example.plugin")).thenReturn(agentInstance);
processor.process(pluginDescriptor, request);
verify(agentService, times(1)).findElasticAgent("foo", "cd.go.example.plugin");
verify(agentService, times(1)).deleteAgentsWithoutValidations(eq(singletonList(agentInstance.getUuid())));
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class ElasticAgentRequestProcessorV1Test method shouldProcessDisableAgentRequest.
@Test
public void shouldProcessDisableAgentRequest() {
AgentInstance agentInstance = AgentInstance.createFromAgent(new Agent("uuid"), null, null);
when(request.api()).thenReturn(REQUEST_DISABLE_AGENTS);
when(request.requestBody()).thenReturn("[{\"agent_id\":\"foo\"}]");
when(agentService.findElasticAgent("foo", "cd.go.example.plugin")).thenReturn(agentInstance);
processor.process(pluginDescriptor, request);
verify(agentService, times(1)).findElasticAgent("foo", "cd.go.example.plugin");
verify(agentService).disableAgents(singletonList(agentInstance.getUuid()));
}
use of com.thoughtworks.go.config.Agent in project gocd by gocd.
the class AgentRegistrationControllerIntegrationTest method shouldReIssueCertificateIfRegisteredAgentAsksForRegistrationWithoutAutoRegisterKeys.
@Test
public void shouldReIssueCertificateIfRegisteredAgentAsksForRegistrationWithoutAutoRegisterKeys() {
String uuid = UUID.randomUUID().toString();
agentService.saveOrUpdate(new Agent(uuid, "hostname", "127.0.01", uuidGenerator.randomUuid()));
assertTrue(agentService.findAgent(uuid).getAgentConfigStatus().equals(AgentConfigStatus.Enabled));
MockHttpServletRequest request = new MockHttpServletRequest();
final ResponseEntity responseEntity = controller.agentRequest("hostname", uuid, "sandbox", "100", null, null, null, null, null, null, null, token(uuid, goConfigService.serverConfig().getTokenGenerationKey()), request);
AgentInstance agentInstance = agentService.findAgent(uuid);
assertTrue(agentInstance.isIdle());
assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
assertThat(responseEntity.getBody().toString(), is(""));
}
Aggregations