Search in sources :

Example 61 with JobIdentifier

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

the class TestInformationTest method equalsFalseWhenStatusSameNameSameAndJobIdentifiersHaveDifferentNamesButSameLength.

@Test
public void equalsFalseWhenStatusSameNameSameAndJobIdentifiersHaveDifferentNamesButSameLength() {
    TestInformation info1 = new TestInformation("test", TestStatus.Error);
    info1.addJob(new JobIdentifier(null, 1, null, null, null, "job1"));
    info1.addJob(new JobIdentifier(null, 2, null, null, null, "job"));
    TestInformation info2 = new TestInformation("test", TestStatus.Error);
    info2.addJob(new JobIdentifier(null, 3, null, null, null, "job1"));
    info2.addJob(new JobIdentifier(null, 4, null, null, null, "job33"));
    assertThat(info1, not(info2));
}
Also used : JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Test(org.junit.Test)

Example 62 with JobIdentifier

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

the class TestSuiteTest method shouldRemoveTestsThatHaveSameContext.

@Test
public void shouldRemoveTestsThatHaveSameContext() {
    testSuite.addTest("testB", TestStatus.Error, new JobIdentifier("", -1, "", "", "", "job-1"));
    testSuite.addTest("testA", TestStatus.Error, new JobIdentifier("", -1, "", "", "", "job-1"));
    TestSuite testSuite1 = new TestSuite("another-suite");
    testSuite1.addTest("testA", TestStatus.Error, new JobIdentifier("", 23, "", "", "", "job-1"));
    testSuite.removeDuplicateTestEntries(testSuite1);
    List<TestInformation> list = testSuite.tests();
    assertThat(list.size(), is(1));
    assertThat(list.get(0).getName(), is("testB"));
}
Also used : JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Test(org.junit.Test)

Example 63 with JobIdentifier

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

the class ArtifactsControllerTest method testConsoleOutShouldReturnErrorWhenJobHasBeenCompletedAndLogsNotFound.

@Test
public void testConsoleOutShouldReturnErrorWhenJobHasBeenCompletedAndLogsNotFound() throws Exception {
    JobIdentifier jobIdentifier = new JobIdentifier("pipeline", 10, "label-10", "stage", "2", "build", 103l);
    when(restfulService.findJob("pipeline", "10", "stage", "2", "build")).thenReturn(jobIdentifier);
    when(jobInstanceDao.isJobCompleted(jobIdentifier)).thenReturn(true);
    when(consoleService.doesLogExist(jobIdentifier)).thenReturn(false);
    ModelAndView view = artifactsController.consoleout("pipeline", "10", "stage", "build", "2", 1L);
    assertThat(view.getView().getContentType(), is(RESPONSE_CHARSET));
    assertThat(view.getView(), is(instanceOf((ResponseCodeView.class))));
    assertThat(((ResponseCodeView) view.getView()).getContent(), containsString("Console log for Build [pipeline/10/stage/2/build/103] is unavailable as it may have been purged by Go or deleted externally"));
}
Also used : ResponseCodeView(com.thoughtworks.go.server.web.ResponseCodeView) ModelAndView(org.springframework.web.servlet.ModelAndView) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Test(org.junit.Test)

Example 64 with JobIdentifier

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

the class ArtifactsControllerTest method shouldUpdateLastConsoleActivityOnConsoleLogPut.

@Test
public void shouldUpdateLastConsoleActivityOnConsoleLogPut() throws Exception {
    String content = "Testing:";
    request.setContent(content.getBytes());
    JobIdentifier jobIdentifier = new JobIdentifier("pipeline", 10, "label-10", "stage", "2", "build", 103l);
    when(restfulService.findJob("pipeline", "10", "stage", "2", "build", 103l)).thenReturn(jobIdentifier);
    String path = "cruise-output/console.log";
    File artifactFile = new File("junk");
    when(consoleService.consoleLogFile(jobIdentifier)).thenReturn(artifactFile);
    when(consoleService.updateConsoleLog(eq(artifactFile), any(InputStream.class))).thenReturn(true);
    assertThat(((ResponseCodeView) artifactsController.putArtifact("pipeline", "10", "stage", "2", "build", 103l, path, "agent-id", request).getView()).getStatusCode(), is(HttpServletResponse.SC_OK));
    verify(consoleActivityMonitor).consoleUpdatedFor(jobIdentifier);
}
Also used : InputStream(java.io.InputStream) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) File(java.io.File) Test(org.junit.Test)

Example 65 with JobIdentifier

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

the class RestfulService method findJob.

/**
 * buildId should only be given when caller is absolutely sure about the job instance
 * (makes sense in agent-uploading artifacts/properties scenario because agent won't run a job if its copied over(it only executes real jobs)) -JJ
 */
public JobIdentifier findJob(String pipelineName, String counterOrLabel, String stageName, String stageCounter, String buildName, Long buildId) {
    JobConfigIdentifier jobConfig = goConfigService.translateToActualCase(new JobConfigIdentifier(pipelineName, stageName, buildName));
    Pipeline pipeline = pipelineService.findPipelineByCounterOrLabel(jobConfig.getPipelineName(), counterOrLabel);
    stageCounter = StringUtils.isEmpty(stageCounter) ? JobIdentifier.LATEST : stageCounter;
    StageIdentifier stageIdentifier = translateStageCounter(pipeline.getIdentifier(), jobConfig.getStageName(), stageCounter);
    JobIdentifier jobId;
    if (buildId == null) {
        jobId = jobResolverService.actualJobIdentifier(new JobIdentifier(stageIdentifier, jobConfig.getJobName()));
    } else {
        jobId = new JobIdentifier(stageIdentifier, jobConfig.getJobName(), buildId);
    }
    if (jobId == null) {
        // fix for #5739
        throw new JobNotFoundException(pipelineName, stageName, buildName);
    }
    return jobId;
}
Also used : StageIdentifier(com.thoughtworks.go.domain.StageIdentifier) JobNotFoundException(com.thoughtworks.go.config.JobNotFoundException) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) JobConfigIdentifier(com.thoughtworks.go.domain.JobConfigIdentifier) Pipeline(com.thoughtworks.go.domain.Pipeline)

Aggregations

JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)113 Test (org.junit.Test)85 File (java.io.File)16 JobInstance (com.thoughtworks.go.domain.JobInstance)15 Pipeline (com.thoughtworks.go.domain.Pipeline)13 DateTime (org.joda.time.DateTime)12 Before (org.junit.Before)10 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 Stage (com.thoughtworks.go.domain.Stage)6 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)5 IllegalArtifactLocationException (com.thoughtworks.go.domain.exception.IllegalArtifactLocationException)5 AgentMetadata (com.thoughtworks.go.plugin.access.elastic.models.AgentMetadata)5 IOException (java.io.IOException)5 ModelAndView (org.springframework.web.servlet.ModelAndView)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)3 Property (com.thoughtworks.go.domain.Property)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 RunIf (com.googlecode.junit.ext.RunIf)2 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)2 HeaderConstraint (com.thoughtworks.go.server.security.HeaderConstraint)2