use of com.thoughtworks.go.config.AgentConfig in project gocd by gocd.
the class AgentRegistrationControllerIntegrationTest method shouldRejectGenerateTokenRequestIfAgentIsInConfig.
@Test
public void shouldRejectGenerateTokenRequestIfAgentIsInConfig() throws Exception {
System.setProperty(SystemEnvironment.AUTO_REGISTER_LOCAL_AGENT_ENABLED.propertyName(), "false");
final String uuid = UUID.randomUUID().toString();
agentConfigService.addAgent(new AgentConfig(uuid, "hostname", "127.0.01"), Username.ANONYMOUS);
assertTrue(agentService.findAgent(uuid).getAgentConfigStatus().equals(AgentConfigStatus.Enabled));
final ResponseEntity responseEntity = controller.getToken(uuid);
assertThat(responseEntity.getStatusCode(), Matchers.is(CONFLICT));
assertThat(responseEntity.getBody(), Matchers.is("A token has already been issued for this agent."));
}
use of com.thoughtworks.go.config.AgentConfig in project gocd by gocd.
the class AgentRegistrationControllerIntegrationTest method shouldRegisterLocalAgent.
@Test
public void shouldRegisterLocalAgent() throws Exception {
System.setProperty(SystemEnvironment.AUTO_REGISTER_LOCAL_AGENT_ENABLED.propertyName(), "true");
String uuid = UUID.randomUUID().toString();
MockHttpServletRequest request = new MockHttpServletRequest();
final ResponseEntity responseEntity = controller.agentRequest("hostname", uuid, "sandbox", "100", null, null, null, null, null, null, null, false, token(uuid, goConfigService.serverConfig().getTokenGenerationKey()), request);
AgentConfig agentConfig = goConfigService.agentByUuid(uuid);
assertThat(agentConfig.getHostname(), is("hostname"));
assertThat(responseEntity.getStatusCode(), is(HttpStatus.OK));
assertThat(responseEntity.getHeaders().getContentType(), is(MediaType.APPLICATION_JSON));
assertTrue(RegistrationJSONizer.fromJson(responseEntity.getBody().toString()).isValid());
}
use of com.thoughtworks.go.config.AgentConfig in project gocd by gocd.
the class AgentRegistrationControllerIntegrationTest method shouldRejectGenerateTokenRequestIfAgentIsInPendingState.
@Test
public void shouldRejectGenerateTokenRequestIfAgentIsInPendingState() throws Exception {
System.setProperty(SystemEnvironment.AUTO_REGISTER_LOCAL_AGENT_ENABLED.propertyName(), "false");
final String uuid = UUID.randomUUID().toString();
final AgentRuntimeInfo agentRuntimeInfo = AgentRuntimeInfo.fromServer(new AgentConfig(uuid, "hostname", "127.0.01"), false, "sandbox", 0l, "linux", false);
agentService.requestRegistration(agentService.agentUsername(uuid, "127.0.0.1", "hostname"), agentRuntimeInfo);
final AgentInstance agentInstance = agentService.findAgent(uuid);
assertTrue(agentInstance.isPending());
final ResponseEntity responseEntity = controller.getToken(uuid);
assertThat(responseEntity.getStatusCode(), Matchers.is(CONFLICT));
assertThat(responseEntity.getBody(), Matchers.is("A token has already been issued for this agent."));
}
use of com.thoughtworks.go.config.AgentConfig in project gocd by gocd.
the class ElasticAgentRequestProcessorV1Test method shouldProcessDeleteAgentRequest.
@Test
public void shouldProcessDeleteAgentRequest() {
AgentInstance agentInstance = AgentInstance.createFromConfig(new AgentConfig("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(agentConfigService).deleteAgents(processor.usernameFor(pluginDescriptor.id()), agentInstance);
}
use of com.thoughtworks.go.config.AgentConfig in project gocd by gocd.
the class ElasticAgentRequestProcessorV1Test method shouldProcessDisableAgentRequest.
@Test
public void shouldProcessDisableAgentRequest() {
AgentInstance agentInstance = AgentInstance.createFromConfig(new AgentConfig("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(agentConfigService).disableAgents(processor.usernameFor(pluginDescriptor.id()), agentInstance);
}
Aggregations