use of com.thoughtworks.go.dto.DurationBean in project gocd by gocd.
the class StageJsonPresentationModelTest method shouldGetAPresenterWithLabelAndRelevantBuildPlans.
@Test
public void shouldGetAPresenterWithLabelAndRelevantBuildPlans() throws Exception {
DurationBeans durations = new DurationBeans(new DurationBean(stage.getJobInstances().getByName("job-that-will-fail").getId(), 12L));
StageJsonPresentationModel presenter = new StageJsonPresentationModel(pipeline, stage, null, agentService, durations, new TrackingTool());
Map json = presenter.toJson();
JSONAssert.assertEquals("{\n" + " \"stageName\": \"stage\",\n" + " \"builds\": [\n" + " {\n" + " \"name\": \"job-that-will-fail\",\n" + " \"last_build_duration\": \"12\"\n" + " },\n" + " {\n" + " \"name\": \"job-that-will-pass\"\n" + " },\n" + " {\n" + " \"name\": \"scheduledBuild\"\n" + " }\n" + " ],\n" + " \"current_label\": \"10\",\n" + " \"id\": \"1\"\n" + "}", new Gson().toJson(json), false);
assertFalse("JSON shouldn't contain last_successful_label", json.toString().contains("last_successful_label"));
}
use of com.thoughtworks.go.dto.DurationBean in project gocd by gocd.
the class JobControllerTest method shouldFindTheLatestJobWhenJobStatusIsRequested.
@Test
public void shouldFindTheLatestJobWhenJobStatusIsRequested() {
JobInstance job = JobInstanceMother.buildEndingWithState(JobState.Rescheduled, JobResult.Unknown, "config");
job.assign("agent", new Date());
JobInstance newJob = JobInstanceMother.buildEndingWithState(JobState.Building, JobResult.Unknown, "another_config");
newJob.setId(2);
newJob.assign("another_agent", new Date());
String pipelineName = job.getPipelineName();
String stageName = job.getStageName();
when(jobInstanceService.buildByIdWithTransitions(job.getId())).thenReturn(job);
when(jobInstanceDao.mostRecentJobWithTransitions(job.getIdentifier())).thenReturn(newJob);
when(agentService.findAgentObjectByUuid(newJob.getAgentUuid())).thenReturn(Agent.blankAgent(newJob.getAgentUuid()));
when(stageService.getBuildDuration(pipelineName, stageName, newJob)).thenReturn(new DurationBean(newJob.getId(), 5l));
ModelAndView modelAndView = jobController.handleRequest(pipelineName, stageName, job.getId(), response);
verify(jobInstanceService).buildByIdWithTransitions(job.getId());
verify(agentService).findAgentObjectByUuid(newJob.getAgentUuid());
verify(jobInstanceDao).mostRecentJobWithTransitions(job.getIdentifier());
verify(stageService).getBuildDuration(pipelineName, stageName, newJob);
JsonValue json = from(((List) modelAndView.getModel().get("json")).get(0));
JsonValue buildingInfo = json.getObject("building_info");
assertThat(buildingInfo.getString("id"), is("2"));
assertThat(buildingInfo.getString("last_build_duration"), is("5"));
}
use of com.thoughtworks.go.dto.DurationBean in project gocd by gocd.
the class JobStatusJsonPresentationModelTest method shouldShowElapsedAndRemainingTimeForIncompleteBuild.
@Test
public void shouldShowElapsedAndRemainingTimeForIncompleteBuild() throws Exception {
JobInstance instance = JobInstanceMother.building("test", new DateTime().minusSeconds(5).toDate());
JobStatusJsonPresentationModel presenter = new JobStatusJsonPresentationModel(instance, mock(Agent.class), new DurationBean(instance.getId(), 10L));
Map json = presenter.toJsonHash();
JSONAssert.assertEquals("{\n" + " \"name\": \"test\",\n" + " \"current_status\": \"building\",\n" + " \"current_build_duration\": \"5\",\n" + " \"last_build_duration\": \"10\"\n" + "}", new Gson().toJson(json), false);
}
use of com.thoughtworks.go.dto.DurationBean in project gocd by gocd.
the class StageServiceIntegrationTest method shouldGetDurationBasedOnPipelineNameStageNameJobNameAndAgentUUID.
@Test
public // #2328
void shouldGetDurationBasedOnPipelineNameStageNameJobNameAndAgentUUID() throws Exception {
String pipelineName = "Cruise";
configFileHelper.addPipeline(pipelineName, STAGE_NAME);
Stage saveStage = dbHelper.saveTestPipeline(pipelineName, STAGE_NAME).getStages().first();
JobInstance job1 = completed("unit", Passed, new Date(), new DateTime().minusMinutes(1).toDate());
job1.setAgentUuid(UUID);
jobInstanceDao.save(saveStage.getId(), job1);
String pipeline2Name = "Cruise-1.1";
configFileHelper.addPipeline(pipeline2Name, STAGE_NAME);
Stage stage11 = dbHelper.saveTestPipeline(pipeline2Name, STAGE_NAME).getStages().first();
final JobInstance job2 = building("unit", new Date());
job2.setAgentUuid(UUID);
JobInstance buildingJob = jobInstanceDao.save(stage11.getId(), job2);
final DurationBean duration = stageService.getBuildDuration("Cruise-1.1", STAGE_NAME, buildingJob);
assertThat("we should not load duration according to stage name + job name + agent uuid only, " + "we should also use pipeline name as a paramater", duration.getDuration(), is(0L));
}
Aggregations