Search in sources :

Example 1 with DurationBean

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"));
}
Also used : DurationBean(com.thoughtworks.go.dto.DurationBean) Gson(com.google.gson.Gson) Map(java.util.Map) DurationBeans(com.thoughtworks.go.dto.DurationBeans) TrackingTool(com.thoughtworks.go.config.TrackingTool) Test(org.junit.Test)

Example 2 with DurationBean

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"));
}
Also used : DurationBean(com.thoughtworks.go.dto.DurationBean) ModelAndView(org.springframework.web.servlet.ModelAndView) JsonValue(com.thoughtworks.go.util.JsonValue) Date(java.util.Date) Test(org.junit.Test)

Example 3 with DurationBean

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);
}
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) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 4 with DurationBean

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));
}
Also used : DurationBean(com.thoughtworks.go.dto.DurationBean) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

DurationBean (com.thoughtworks.go.dto.DurationBean)4 Test (org.junit.Test)4 Gson (com.google.gson.Gson)2 Date (java.util.Date)2 Map (java.util.Map)2 DateTime (org.joda.time.DateTime)2 TrackingTool (com.thoughtworks.go.config.TrackingTool)1 JobInstance (com.thoughtworks.go.domain.JobInstance)1 DurationBeans (com.thoughtworks.go.dto.DurationBeans)1 Agent (com.thoughtworks.go.server.domain.Agent)1 JsonValue (com.thoughtworks.go.util.JsonValue)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1