Search in sources :

Example 1 with JobInstanceModel

use of com.thoughtworks.go.server.ui.JobInstanceModel in project gocd by gocd.

the class JobPresentationServiceTest method shouldReturnJobModel.

@Test
public void shouldReturnJobModel() throws Exception {
    JobInstance dev = assignedWithAgentId("dev", "agent1");
    JobInstance DEv = assignedWithAgentId("DEv", "agent1");
    JobInstance bev = assignedWithAgentId("bev", "agent2");
    JobInstance tev = scheduled("tev");
    JobInstance lev = assignAgent(passed("lev"), "agent3");
    JobInstance kev = assignAgent(failed("kev"), "agent3");
    AgentInstance agent = building();
    when(agentService.findAgentAndRefreshStatus(any(String.class))).thenReturn(agent);
    List<JobInstanceModel> models = new JobPresentationService(jobDurationStrategy, agentService).jobInstanceModelFor(new JobInstances(dev, bev, tev, lev, kev, DEv));
    assertThat(models.size(), is(6));
    //failed
    assertThat(models.get(0), is(new JobInstanceModel(kev, jobDurationStrategy, agent)));
    //in progress. sort by name (case insensitive)
    assertThat(models.get(1), is(new JobInstanceModel(bev, jobDurationStrategy, agent)));
    assertThat(models.get(2), is(new JobInstanceModel(dev, jobDurationStrategy, agent)));
    assertThat(models.get(3), is(new JobInstanceModel(DEv, jobDurationStrategy, agent)));
    assertThat(models.get(4), is(new JobInstanceModel(tev, jobDurationStrategy)));
    //passed
    assertThat(models.get(5), is(new JobInstanceModel(lev, jobDurationStrategy, agent)));
    //assert agent info
    verify(agentService, times(2)).findAgentAndRefreshStatus("agent1");
    verify(agentService).findAgentAndRefreshStatus("agent2");
    verify(agentService, times(2)).findAgentAndRefreshStatus("agent3");
    verifyNoMoreInteractions(agentService);
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) JobInstance(com.thoughtworks.go.domain.JobInstance) JobInstanceModel(com.thoughtworks.go.server.ui.JobInstanceModel) JobInstances(com.thoughtworks.go.domain.JobInstances) Test(org.junit.Test)

Example 2 with JobInstanceModel

use of com.thoughtworks.go.server.ui.JobInstanceModel in project gocd by gocd.

the class JobPresentationService method jobInstanceModelFor.

public List<JobInstanceModel> jobInstanceModelFor(JobInstances jobInstances) {
    ArrayList<JobInstanceModel> models = new ArrayList<>();
    for (JobInstance jobInstance : jobInstances) {
        AgentInstance agentInstance = jobInstance.isAssignedToAgent() ? agentService.findAgentAndRefreshStatus(jobInstance.getAgentUuid()) : null;
        models.add(new JobInstanceModel(jobInstance, jobDurationStrategy, agentInstance));
    }
    sort(models, JobInstanceModel.JOB_MODEL_COMPARATOR);
    return models;
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) JobInstance(com.thoughtworks.go.domain.JobInstance) ArrayList(java.util.ArrayList) JobInstanceModel(com.thoughtworks.go.server.ui.JobInstanceModel)

Aggregations

AgentInstance (com.thoughtworks.go.domain.AgentInstance)2 JobInstance (com.thoughtworks.go.domain.JobInstance)2 JobInstanceModel (com.thoughtworks.go.server.ui.JobInstanceModel)2 JobInstances (com.thoughtworks.go.domain.JobInstances)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1