Search in sources :

Example 86 with Agent

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}");
}
Also used : Agent(com.thoughtworks.go.config.Agent) DurationBean(com.thoughtworks.go.dto.DurationBean) JobInstance(com.thoughtworks.go.domain.JobInstance) Gson(com.google.gson.Gson) Test(org.junit.jupiter.api.Test)

Example 87 with Agent

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" + "}");
}
Also used : Agent(com.thoughtworks.go.config.Agent) DurationBean(com.thoughtworks.go.dto.DurationBean) JobInstance(com.thoughtworks.go.domain.JobInstance) Gson(com.google.gson.Gson) Test(org.junit.jupiter.api.Test)

Example 88 with Agent

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())));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Agent(com.thoughtworks.go.config.Agent) Test(org.junit.jupiter.api.Test)

Example 89 with Agent

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()));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Agent(com.thoughtworks.go.config.Agent) Test(org.junit.jupiter.api.Test)

Example 90 with Agent

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(""));
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) Agent(com.thoughtworks.go.config.Agent) ResponseEntity(org.springframework.http.ResponseEntity) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Aggregations

Agent (com.thoughtworks.go.config.Agent)100 Test (org.junit.jupiter.api.Test)52 AgentInstance.createFromLiveAgent (com.thoughtworks.go.domain.AgentInstance.createFromLiveAgent)36 AgentInstance (com.thoughtworks.go.domain.AgentInstance)20 AgentStatusChangeListener (com.thoughtworks.go.listener.AgentStatusChangeListener)19 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)16 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)13 NullAgentInstance (com.thoughtworks.go.domain.NullAgentInstance)11 JobInstance (com.thoughtworks.go.domain.JobInstance)8 ResponseEntity (org.springframework.http.ResponseEntity)8 ServerConfig (com.thoughtworks.go.config.ServerConfig)6 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)6 Username (com.thoughtworks.go.server.domain.Username)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 AgentInstance.createFromAgent (com.thoughtworks.go.domain.AgentInstance.createFromAgent)4 AgentBuildingInfo (com.thoughtworks.go.server.service.AgentBuildingInfo)4 Query (org.hibernate.Query)4 TransactionCallback (org.springframework.transaction.support.TransactionCallback)4 Gson (com.google.gson.Gson)3 ResourceConfig (com.thoughtworks.go.config.ResourceConfig)3