use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentViewModelTest method shouldDisplayTheRightStatusMessage.
@Test
public void shouldDisplayTheRightStatusMessage() {
AgentInstance building = AgentInstanceMother.building();
assertThat(new AgentViewModel(updateRuntimeStatus(building, AgentRuntimeStatus.Idle)).getStatusForDisplay(), is("Idle"));
assertThat(new AgentViewModel(updateRuntimeStatus(building, AgentRuntimeStatus.Building)).getStatusForDisplay(), is("Building"));
assertThat(new AgentViewModel(updateRuntimeStatus(building, AgentRuntimeStatus.Cancelled)).getStatusForDisplay(), is("Building (Cancelled)"));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentsViewModelTest method agentsViewModel.
private AgentsViewModel agentsViewModel() {
AgentsViewModel agents = new AgentsViewModel();
AgentInstance idle = AgentInstanceMother.idle(new Date(), "CCeDev01");
AgentInstanceMother.updateOS(idle, "macos");
idle.getResources().add(new Resource("foo"));
idle.getResources().add(new Resource("bar"));
agents.add(new AgentViewModel(idle, "uat"));
AgentInstance building = AgentInstanceMother.building();
building.getResources().add(new Resource("goofooboo"));
agents.add(new AgentViewModel(building, "dev", "uat"));
agents.add(new AgentViewModel(AgentInstanceMother.pending()));
agents.add(new AgentViewModel(AgentInstanceMother.disabled(), "prod"));
return agents;
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class ElasticAgentRequestProcessorTest method shouldProcessDisableAgentRequest.
@Test
public void shouldProcessDisableAgentRequest() throws Exception {
AgentMetadata agent = new AgentMetadata("foo", null, null, null);
DefaultGoApiRequest goPluginApiRequest = new DefaultGoApiRequest(PROCESS_DISABLE_AGENTS, "1.0", pluginIdentifier);
goPluginApiRequest.setRequestBody(extension.getElasticAgentMessageConverter(goPluginApiRequest.apiVersion()).listAgentsResponseBody(Arrays.asList(agent)));
AgentInstance agentInstance = AgentInstance.createFromConfig(new AgentConfig("uuid"), null);
when(agentService.findElasticAgent("foo", "docker")).thenReturn(agentInstance);
processor.process(pluginDescriptor, goPluginApiRequest);
verify(agentConfigService).disableAgents(processor.usernameFor(pluginDescriptor), agentInstance);
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentConfigServiceTest method shouldEnableMultipleAgents.
@Test
public void shouldEnableMultipleAgents() {
AgentRuntimeInfo agentRuntimeInfo = AgentRuntimeInfo.fromAgent(new AgentIdentifier("remote-host", "50.40.30.20", "abc"), AgentRuntimeStatus.Unknown, "cookie", false);
AgentInstance pending = AgentInstance.createFromLiveAgent(agentRuntimeInfo, new SystemEnvironment());
AgentConfig agentConfig = new AgentConfig("UUID2", "remote-host", "50.40.30.20");
agentConfig.disable();
AgentInstance fromConfigFile = AgentInstance.createFromConfig(agentConfig, new SystemEnvironment());
when(goConfigService.hasAgent(fromConfigFile.getUuid())).thenReturn(true);
when(goConfigService.hasAgent(pending.getUuid())).thenReturn(false);
agentConfigService.enableAgents(Username.ANONYMOUS, pending, fromConfigFile);
GoConfigDao.CompositeConfigCommand command = new GoConfigDao.CompositeConfigCommand(new AgentConfigService.AddAgentCommand(pending.agentConfig()), new AgentConfigService.UpdateAgentApprovalStatus("UUID2", false));
ArgumentCaptor<AgentsUpdateCommand> captor = ArgumentCaptor.forClass(AgentsUpdateCommand.class);
verify(goConfigService).updateConfig(captor.capture(), eq(Username.ANONYMOUS));
AgentsUpdateCommand updateCommand = captor.getValue();
assertThat(ReflectionUtil.getField(updateCommand, "command"), is(command));
}
use of com.thoughtworks.go.domain.AgentInstance in project gocd by gocd.
the class AgentServiceTest method shouldFailWhenDeleteIsNotSuccessful.
@Test
public void shouldFailWhenDeleteIsNotSuccessful() throws Exception {
SecurityService securityService = mock(SecurityService.class);
AgentConfigService agentConfigService = mock(AgentConfigService.class);
AgentInstance agentInstance = mock(AgentInstance.class);
String uuid = "1234";
Username username = new Username(new CaseInsensitiveString("test"));
HttpOperationResult operationResult = mock(HttpOperationResult.class);
when(securityService.hasOperatePermissionForAgents(username)).thenReturn(true);
when(agentInstance.canBeDeleted()).thenReturn(true);
doThrow(new RuntimeException()).when(agentConfigService).deleteAgents(username, agentInstance);
when(agentInstances.findAgentAndRefreshStatus(uuid)).thenReturn(agentInstance);
AgentService agentService = new AgentService(agentConfigService, new SystemEnvironment(), agentInstances, mock(EnvironmentConfigService.class), mock(GoConfigService.class), securityService, agentDao, uuidGenerator, serverHealthService = mock(ServerHealthService.class));
agentService.deleteAgents(username, operationResult, Arrays.asList(uuid));
verify(operationResult).internalServerError(any(String.class), any(HealthStateType.class));
}
Aggregations