use of com.thoughtworks.go.config.AgentConfig in project gocd by gocd.
the class AgentRegistrationControllerTest method shouldNotAutoRegisterAgentIfKeysDoNotMatch.
@Test
public void shouldNotAutoRegisterAgentIfKeysDoNotMatch() throws Exception {
String uuid = "uuid";
when(goConfigService.hasAgent(uuid)).thenReturn(false);
ServerConfig serverConfig = mockedServerConfig("token-generation-key", "someKey");
when(goConfigService.serverConfig()).thenReturn(serverConfig);
when(agentService.agentUsername(uuid, request.getRemoteAddr(), "host")).thenReturn(new Username("some-agent-login-name"));
controller.agentRequest("host", uuid, "location", "233232", "osx", "", "", "", "", "", "", false, token(uuid, serverConfig.getTokenGenerationKey()), request);
verify(agentService).requestRegistration(new Username("some-agent-login-name"), AgentRuntimeInfo.fromServer(new AgentConfig(uuid, "host", request.getRemoteAddr()), false, "location", 233232L, "osx", false));
verify(goConfigService, never()).updateConfig(any(UpdateConfigCommand.class));
}
use of com.thoughtworks.go.config.AgentConfig in project gocd by gocd.
the class AgentRegistrationControllerTest method shouldAutoRegisterAgentWithHostnameFromAutoRegisterProperties.
@Test
public void shouldAutoRegisterAgentWithHostnameFromAutoRegisterProperties() throws Exception {
String uuid = "uuid";
when(goConfigService.hasAgent(uuid)).thenReturn(false);
ServerConfig serverConfig = mockedServerConfig("token-generation-key", "someKey");
when(goConfigService.serverConfig()).thenReturn(serverConfig);
when(agentService.agentUsername(uuid, request.getRemoteAddr(), "autoregister-hostname")).thenReturn(new Username("some-agent-login-name"));
when(agentConfigService.updateAgent(any(UpdateConfigCommand.class), eq(uuid), any(HttpOperationResult.class), eq(new Username("some-agent-login-name")))).thenReturn(new AgentConfig(uuid, "autoregister-hostname", request.getRemoteAddr()));
controller.agentRequest("host", uuid, "location", "233232", "osx", "someKey", "", "", "autoregister-hostname", "", "", false, token(uuid, serverConfig.getTokenGenerationKey()), request);
verify(agentService).requestRegistration(new Username("some-agent-login-name"), AgentRuntimeInfo.fromServer(new AgentConfig(uuid, "autoregister-hostname", request.getRemoteAddr()), false, "location", 233232L, "osx", false));
verify(agentConfigService).updateAgent(any(UpdateConfigCommand.class), eq(uuid), any(HttpOperationResult.class), eq(new Username("some-agent-login-name")));
}
use of com.thoughtworks.go.config.AgentConfig in project gocd by gocd.
the class AgentRegistrationControllerTest method shouldRegisterWithProvidedAgentInformation.
@Test
public void shouldRegisterWithProvidedAgentInformation() throws Exception {
when(goConfigService.hasAgent("blahAgent-uuid")).thenReturn(false);
ServerConfig serverConfig = mockedServerConfig("token-generation-key", "someKey");
when(goConfigService.serverConfig()).thenReturn(serverConfig);
when(agentService.agentUsername("blahAgent-uuid", request.getRemoteAddr(), "blahAgent-host")).thenReturn(new Username("some-agent-login-name"));
controller.agentRequest("blahAgent-host", "blahAgent-uuid", "blah-location", "34567", "osx", "", "", "", "", "", "", false, token("blahAgent-uuid", serverConfig.getTokenGenerationKey()), request);
verify(agentService).requestRegistration(new Username("some-agent-login-name"), AgentRuntimeInfo.fromServer(new AgentConfig("blahAgent-uuid", "blahAgent-host", request.getRemoteAddr()), false, "blah-location", 34567L, "osx", false));
}
use of com.thoughtworks.go.config.AgentConfig in project gocd by gocd.
the class AgentRegistrationControllerTest method shouldAutoRegisterAgent.
@Test
public void shouldAutoRegisterAgent() throws Exception {
String uuid = "uuid";
final ServerConfig serverConfig = mockedServerConfig("token-generation-key", "someKey");
final String token = token(uuid, serverConfig.getTokenGenerationKey());
when(goConfigService.hasAgent(uuid)).thenReturn(false);
when(goConfigService.serverConfig()).thenReturn(serverConfig);
when(agentService.agentUsername(uuid, request.getRemoteAddr(), "host")).thenReturn(new Username("some-agent-login-name"));
when(agentConfigService.updateAgent(any(UpdateConfigCommand.class), eq(uuid), any(HttpOperationResult.class), eq(new Username("some-agent-login-name")))).thenReturn(new AgentConfig(uuid, "host", request.getRemoteAddr()));
controller.agentRequest("host", uuid, "location", "233232", "osx", "someKey", "", "", "", "", "", false, token, request);
verify(agentService).requestRegistration(new Username("some-agent-login-name"), AgentRuntimeInfo.fromServer(new AgentConfig(uuid, "host", request.getRemoteAddr()), false, "location", 233232L, "osx", false));
verify(agentConfigService).updateAgent(any(UpdateConfigCommand.class), eq(uuid), any(HttpOperationResult.class), eq(new Username("some-agent-login-name")));
}
use of com.thoughtworks.go.config.AgentConfig in project gocd by gocd.
the class AgentStatusChangeNotifierTest method shouldNotifyIfAgentIsElastic.
@Test
public void shouldNotifyIfAgentIsElastic() throws Exception {
ElasticAgentRuntimeInfo agentRuntimeInfo = new ElasticAgentRuntimeInfo(new AgentIdentifier("localhost", "127.0.0.1", "uuid"), AgentRuntimeStatus.Idle, "/foo/one", null, "42", "go.cd.elastic-agent-plugin.docker");
AgentConfig agentConfig = new AgentConfig();
agentConfig.setElasticAgentId("42");
agentConfig.setElasticPluginId("go.cd.elastic-agent-plugin.docker");
agentConfig.setIpAddress("127.0.0.1");
AgentInstance agentInstance = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment(), mock(AgentStatusChangeListener.class));
agentInstance.update(agentRuntimeInfo);
when(notificationPluginRegistry.isAnyPluginInterestedIn("agent-status")).thenReturn(true);
agentStatusChangeNotifier.onAgentStatusChange(agentInstance);
verify(pluginNotificationQueue).post(captor.capture());
assertThat(captor.getValue().getData() instanceof AgentNotificationData, is(true));
AgentNotificationData data = (AgentNotificationData) captor.getValue().getData();
assertTrue(data.isElastic());
}
Aggregations