Search in sources :

Example 21 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)

Example 22 with JobIdentifier

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

the class ShineDaoIntegrationTest method shouldHandleExceptionsWhenTryingToPullUpTrace.

@Test
public void shouldHandleExceptionsWhenTryingToPullUpTrace() throws Exception {
    stageId = failureSetup.setupPipelineInstance(false, null, goURLRepository).stageId;
    FailureDetails details = shineDao.failureDetailsForTest(new JobIdentifier(stageId, "job1"), "testSuite1", "test1", result);
    assertThat(details.getMessage(), is("NOT_YET_AVAILABLE"));
    assertThat(details.getStackTrace(), is("NOT_YET_AVAILABLE"));
    assertThat("not successful", result.isSuccessful(), is(false));
    assertThat(result.replacementContent(localizer), is("Unable to retrieve failure results."));
}
Also used : JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) FailureDetails(com.thoughtworks.go.domain.testinfo.FailureDetails) Test(org.junit.Test)

Example 23 with JobIdentifier

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

the class ShineDaoIntegrationTest method shouldBeAbleToPullUpStackTrace.

@Test
public void shouldBeAbleToPullUpStackTrace() {
    FailureDetails failureDetails = shineDao.failureDetailsForTest(new JobIdentifier(stageId, "WinBuild"), "testSuite1", "test1", result);
    assertThat(failureDetails.getMessage(), is("Something assert failed..."));
    assertThat(failureDetails.getStackTrace(), is("junit.framework.AssertionFailedError: Something assert failed..."));
    failureDetails = shineDao.failureDetailsForTest(new JobIdentifier(stageId, "WinBuild"), "testSuite1", "test2", result);
    assertThat(failureDetails.getMessage(), is("Something went wrong"));
    assertThat(failureDetails.getStackTrace(), is("com.foo.MyException: Something went wrong..."));
    failureDetails = shineDao.failureDetailsForTest(new JobIdentifier(stageId, "NixBuild"), "testSuite1", "test1", result);
    assertThat(failureDetails.getMessage(), is("Something assert failed..."));
    assertThat(failureDetails.getStackTrace(), is("junit.framework.AssertionFailedError: Something assert failed..."));
}
Also used : JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) FailureDetails(com.thoughtworks.go.domain.testinfo.FailureDetails) Test(org.junit.Test)

Example 24 with JobIdentifier

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

the class StageNotificationServiceTest method shouldSendEmailWithFailureDetails.

@Test
public void shouldSendEmailWithFailureDetails() throws Exception {
    final String expectedBaseUrl = String.format("http://test.host:8153");
    String jezMail = prepareOneMatchedUser();
    final Date date = new Date();
    stubPipelineAndStage(date);
    final TestSuite suite1 = new TestSuite("com.thoughtworks.go.FailOne");
    suite1.addTest("shouldCompile", TestStatus.Error, new JobIdentifier(stageIdentifier, "compile"));
    suite1.addTest("shouldPass", TestStatus.Failure, new JobIdentifier(stageIdentifier, "test"));
    suite1.addTest("shouldPass", TestStatus.Failure, new JobIdentifier(stageIdentifier, "twist"));
    suite1.addTest("shouldCompile2", TestStatus.Failure, new JobIdentifier(stageIdentifier, "compile"));
    final TestSuite suite2 = new TestSuite("com.thoughtworks.go.FailTwo");
    suite2.addTest("shouldCompile", TestStatus.Error, new JobIdentifier(stageIdentifier, "test"));
    suite2.addTest("shouldTest", TestStatus.Failure, new JobIdentifier(stageIdentifier, "test"));
    when(serverConfigService.siteUrlFor(anyString(), eq(false))).thenAnswer(new Answer<String>() {

        public String answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            return morphURl((String) args[0], expectedBaseUrl);
        }
    });
    when(systemEnvironment.isShineEnabled()).thenReturn(true);
    when(shineDao.failedTestsFor(stageIdentifier)).thenReturn(Arrays.asList(suite1, suite2));
    stageNotificationService.sendNotifications(stageIdentifier, StageEvent.Fails, new Username(new CaseInsensitiveString("loser")));
    String body = inMemoryEmailNotificationTopic.getBody(jezMail);
    assertThat(body, containsString(StageNotificationService.FAILED_TEST_SECTION));
    String restOfThebody = textAfter(body, StageNotificationService.FAILED_TEST_SECTION);
    String failuresText = restOfThebody.substring(0, restOfThebody.indexOf(StageNotificationService.MATERIAL_SECTION_HEADER));
    assertEquals("\n\nThe following tests failed in pipeline 'go' (instance 'go-1'):\n\n" + "* com.thoughtworks.go.FailOne\n" + "   shouldCompile\n" + "     Errored on 'compile' (" + expectedBaseUrl + "/go/tab/build/detail/go/1/dev/2/compile)\n" + "   shouldCompile2\n" + "     Failed on 'compile' (" + expectedBaseUrl + "/go/tab/build/detail/go/1/dev/2/compile)\n" + "   shouldPass\n" + "     Failed on 'test' (" + expectedBaseUrl + "/go/tab/build/detail/go/1/dev/2/test)\n" + "     Failed on 'twist' (" + expectedBaseUrl + "/go/tab/build/detail/go/1/dev/2/twist)\n" + "\n\n* com.thoughtworks.go.FailTwo\n" + "   shouldCompile\n" + "     Errored on 'test' (" + expectedBaseUrl + "/go/tab/build/detail/go/1/dev/2/test)\n" + "   shouldTest\n" + "     Failed on 'test' (" + expectedBaseUrl + "/go/tab/build/detail/go/1/dev/2/test)\n\n\n", failuresText);
}
Also used : TestSuite(com.thoughtworks.go.domain.testinfo.TestSuite) Username(com.thoughtworks.go.server.domain.Username) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyString(org.mockito.Matchers.anyString) StringContains.containsString(org.hamcrest.core.StringContains.containsString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Date(java.util.Date) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 25 with JobIdentifier

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

the class FailingTestsInPipelineTest method shouldRemoveDuplicate.

@Test
public void shouldRemoveDuplicate() {
    failingTests.add("suiteA", "testA", TestStatus.Error, new JobIdentifier("", 3, "", "", "", "job-1"));
    failingTests.add("suiteA", "testB", TestStatus.Error, new JobIdentifier("", 3, "", "", "", "job-1"));
    FailingTestsInPipeline failingTests1 = new FailingTestsInPipeline("1.3", 3);
    failingTests1.add("suiteA", "testA", TestStatus.Error, new JobIdentifier("", 4, "", "", "", "job-1"));
    failingTests1.add("suiteA", "testB", TestStatus.Error, new JobIdentifier("", 4, "", "", "", "job-2"));
    failingTests.removeDuplicateTestEntries(failingTests1);
    assertThat(failingTests.failingSuites().size(), is(1));
    List<TestInformation> tests = failingTests.failingSuites().get(0).tests();
    assertThat(tests.size(), is(1));
    assertThat(tests.get(0).getName(), is("testB"));
}
Also used : JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Test(org.junit.Test)

Aggregations

JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)100 Test (org.junit.Test)74 JobInstance (com.thoughtworks.go.domain.JobInstance)17 Pipeline (com.thoughtworks.go.domain.Pipeline)16 File (java.io.File)15 DateTime (org.joda.time.DateTime)12 Stage (com.thoughtworks.go.domain.Stage)9 Before (org.junit.Before)8 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 LogFile (com.thoughtworks.go.server.domain.LogFile)5 IllegalArtifactLocationException (com.thoughtworks.go.domain.exception.IllegalArtifactLocationException)4 Property (com.thoughtworks.go.domain.Property)3 Username (com.thoughtworks.go.server.domain.Username)3 IOException (java.io.IOException)3 Expectations (org.jmock.Expectations)3 RunIf (com.googlecode.junit.ext.RunIf)2 Tabs (com.thoughtworks.go.config.Tabs)2 Properties (com.thoughtworks.go.domain.Properties)2