Search in sources :

Example 31 with JobInstance

use of com.thoughtworks.go.domain.JobInstance 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 agentInstance = building();
    when(agentService.findAgentAndRefreshStatus(any(String.class))).thenReturn(agentInstance);
    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, agentInstance)));
    // in progress. sort by name (case insensitive)
    assertThat(models.get(1), is(new JobInstanceModel(bev, jobDurationStrategy, agentInstance)));
    assertThat(models.get(2), is(new JobInstanceModel(dev, jobDurationStrategy, agentInstance)));
    assertThat(models.get(3), is(new JobInstanceModel(DEv, jobDurationStrategy, agentInstance)));
    assertThat(models.get(4), is(new JobInstanceModel(tev, jobDurationStrategy)));
    // passed
    assertThat(models.get(5), is(new JobInstanceModel(lev, jobDurationStrategy, agentInstance)));
    // 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 32 with JobInstance

use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.

the class JobDetailPresentationModelTest method shouldAddFakeConsoleOutputEntryIfJobIsNotCompleted.

@Test
public void shouldAddFakeConsoleOutputEntryIfJobIsNotCompleted() throws Exception {
    JobInstance job = building("job");
    JobDetailPresentationModel model = new JobDetailPresentationModel(job, null, null, null, null, null, artifactsService, null, custom("stage"));
    when(artifactsService.findArtifact(job.getIdentifier(), "")).thenReturn(mock(File.class));
    when(artifactsService.findArtifactUrl(job.getIdentifier(), getConsoleOutputFolderAndFileName())).thenReturn("path/to/console");
    when(directoryReader.listEntries(any(File.class), eq(""))).thenReturn(new DirectoryEntries());
    DirectoryEntries expected = new DirectoryEntries();
    expected.addFolder("cruise-output").addFile("console.log", "path/to/console");
    assertThat(model.getArtifactFiles(directoryReader), is(expected));
}
Also used : DirectoryEntries(com.thoughtworks.go.domain.DirectoryEntries) JobInstance(com.thoughtworks.go.domain.JobInstance) File(java.io.File) Test(org.junit.Test)

Example 33 with JobInstance

use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.

the class JobStatusJsonPresentationModelTest method shouldShowDefaultTabwhenBuildIsNeitherFailedNorPassed.

@Test
public void shouldShowDefaultTabwhenBuildIsNeitherFailedNorPassed() throws Exception {
    JobInstance instance = JobInstanceMother.cancelled("plan1");
    JobStatusJsonPresentationModel buildStatusJson = new JobStatusJsonPresentationModel(instance);
    assertThat(buildStatusJson.getTabToShow(), is(""));
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) Test(org.junit.Test)

Example 34 with JobInstance

use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.

the class JobStatusJsonPresentationModelTest method shouldShowBuildStatus.

@Test
public void shouldShowBuildStatus() throws Exception {
    JobInstance instance = JobInstanceMother.assigned("test");
    instance.setId(12);
    instance.setAgentUuid("1234");
    final Agent agent = new Agent("1234", "cookie", "localhost", "1234");
    JobStatusJsonPresentationModel presenter = new JobStatusJsonPresentationModel(instance, agent, mock(DurationBean.class));
    Map json = presenter.toJsonHash();
    JSONAssert.assertEquals("{\n" + "  \"name\": \"test\",\n" + "  \"id\": \"12\",\n" + "  \"agent\": \"localhost\",\n" + "  \"current_status\": \"assigned\"\n" + "}", new Gson().toJson(json), false);
}
Also used : Agent(com.thoughtworks.go.server.domain.Agent) DurationBean(com.thoughtworks.go.dto.DurationBean) JobInstance(com.thoughtworks.go.domain.JobInstance) Gson(com.google.gson.Gson) Map(java.util.Map) Test(org.junit.Test)

Example 35 with JobInstance

use of com.thoughtworks.go.domain.JobInstance in project gocd by gocd.

the class JobStatusJsonPresentationModelTest method shouldEncodeBuildLocator.

@Test
public void shouldEncodeBuildLocator() throws Exception {
    JobInstance instance = JobInstanceMother.completed("job-%", JobResult.Passed);
    instance.setIdentifier(new JobIdentifier("cruise-%", 1, "label-1", "dev-%", "1", "job-%", -1L));
    JobStatusJsonPresentationModel presenter = new JobStatusJsonPresentationModel(instance);
    Map json = presenter.toJsonHash();
    assertThat(JsonUtils.from(json).getString("buildLocator"), is("cruise-%25/1/dev-%25/1/job-%25"));
}
Also used : JobInstance(com.thoughtworks.go.domain.JobInstance) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Map(java.util.Map) Test(org.junit.Test)

Aggregations

JobInstance (com.thoughtworks.go.domain.JobInstance)82 Test (org.junit.Test)56 Stage (com.thoughtworks.go.domain.Stage)16 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)15 Pipeline (com.thoughtworks.go.domain.Pipeline)15 JobInstances (com.thoughtworks.go.domain.JobInstances)12 JobConfigIdentifier (com.thoughtworks.go.domain.JobConfigIdentifier)7 Agent (com.thoughtworks.go.server.domain.Agent)6 Gson (com.google.gson.Gson)5 Stages (com.thoughtworks.go.domain.Stages)5 Map (java.util.Map)5 DurationBean (com.thoughtworks.go.dto.DurationBean)4 DateTime (org.joda.time.DateTime)4 ArtifactPropertiesGenerator (com.thoughtworks.go.config.ArtifactPropertiesGenerator)3 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)3 Resource (com.thoughtworks.go.config.Resource)3 DirectoryEntries (com.thoughtworks.go.domain.DirectoryEntries)3 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)3 ProjectStatus (com.thoughtworks.go.domain.activity.ProjectStatus)3 JobInstanceModel (com.thoughtworks.go.server.ui.JobInstanceModel)3