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);
}
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));
}
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(""));
}
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);
}
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"));
}
Aggregations