@Test
  public void testRebuild() throws Exception {
    // job with promotion process
    FreeStyleProject p1 = j.createFreeStyleProject("promojob");

    // setup promotion process
    JobPropertyImpl promotion = new JobPropertyImpl(p1);
    p1.addProperty(promotion);
    PromotionProcess proc = promotion.addProcess("promo");
    proc.conditions.add(new SelfPromotionCondition(false));

    // build it
    FreeStyleBuild b1 = j.assertBuildStatusSuccess(p1.scheduleBuild2(0));
    j.waitUntilNoActivity();

    // verify that promotion happened
    Assert.assertSame(proc.getBuilds().getLastBuild().getTarget(), b1);

    // job with parameter
    FreeStyleProject p2 = j.createFreeStyleProject("paramjob");

    // add promoted build param
    p2.addProperty(
        new ParametersDefinitionProperty(
            new PromotedBuildParameterDefinition(
                "var", "promojob", "promo", "promoted build param to test rebuild")));

    // build with parameter
    FreeStyleBuild b2 = j.assertBuildStatusSuccess(p2.scheduleBuild2(0));

    // validate presence of parameter
    ParametersAction a1 = b2.getAction(ParametersAction.class);
    Assert.assertNotNull(a1);
    Assert.assertFalse(a1.getParameters().isEmpty());
    ParameterValue v1 = a1.getParameter("var");
    Assert.assertTrue(v1 instanceof PromotedBuildParameterValue);
    PromotedBuildParameterValue pbpv1 = (PromotedBuildParameterValue) v1;
    Assert.assertEquals(b1.getNumber(), pbpv1.getRun().getNumber());

    // rebuild it
    JenkinsRule.WebClient wc = j.createWebClient();
    HtmlPage page = wc.getPage(b2, "rebuild");
    HtmlForm form = page.getFormByName("config");
    j.submit(form);
    j.waitUntilNoActivity();

    // validate presence of parameter
    FreeStyleBuild rebuild = p2.getLastBuild();
    j.assertBuildStatusSuccess(rebuild);
    Assert.assertNotEquals(b2.getNumber(), rebuild.getNumber());
    ParametersAction a2 = rebuild.getAction(ParametersAction.class);
    Assert.assertNotNull(a2);
    Assert.assertFalse(a2.getParameters().isEmpty());
    ParameterValue v2 = a2.getParameter("var");
    Assert.assertTrue(v2 instanceof PromotedBuildParameterValue);
    PromotedBuildParameterValue pbpv2 = (PromotedBuildParameterValue) v2;
    Assert.assertEquals(b1.getNumber(), pbpv2.getRun().getNumber());
  }
コード例 #2
0
  @LocalData
  @Test
  public void setDescription() throws Exception {
    FreeStyleBuild build = project.scheduleBuild2(0).get(10, TimeUnit.SECONDS);

    CaseResult caseResult = build.getAction(TestResultAction.class).getFailedTests().get(0);
    String url =
        build.getUrl()
            + "/testReport/"
            + caseResult.getRelativePathFrom(caseResult.getTestResult());

    testSetDescription(url, caseResult);

    ClassResult classResult = caseResult.getParent();
    url =
        build.getUrl()
            + "/testReport/"
            + classResult.getParent().getSafeName()
            + "/"
            + classResult.getSafeName();
    testSetDescription(url, classResult);

    PackageResult packageResult = classResult.getParent();
    url = build.getUrl() + "/testReport/" + classResult.getParent().getSafeName();
    testSetDescription(url, packageResult);
  }
コード例 #3
0
  private void assertTestResults(FreeStyleBuild build) {
    TestResultAction testResultAction = build.getAction(TestResultAction.class);
    assertNotNull("no TestResultAction", testResultAction);

    TestResult result = testResultAction.getResult();
    assertNotNull("no TestResult", result);

    assertEquals("should have 1 failing test", 1, testResultAction.getFailCount());
    assertEquals("should have 1 failing test", 1, result.getFailCount());

    assertEquals("should have 132 total tests", 132, testResultAction.getTotalCount());
    assertEquals("should have 132 total tests", 132, result.getTotalCount());
  }
 /**
  * Tests that a legacy FoundFailureCause can be loaded by the annotator.
  *
  * @throws Exception if so.
  */
 @LocalData
 public void testLoadOldFailureCauseWithOnlyLineNumbers() throws Exception {
   FreeStyleProject job = (FreeStyleProject) Jenkins.getInstance().getItem("MyProject");
   assertNotNull(job);
   FreeStyleBuild build = job.getBuilds().getFirstBuild();
   OldDataConverter.getInstance().waitForInitialCompletion();
   FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class);
   List<FoundFailureCause> foundFailureCauses =
       Whitebox.getInternalState(action, "foundFailureCauses");
   FoundFailureCause foundFailureCause = foundFailureCauses.get(0);
   FoundIndication indication = foundFailureCause.getIndications().get(0);
   assertTrue(indication.getMatchingString().matches(indication.getPattern()));
   IndicationAnnotator annotator = new IndicationAnnotator(foundFailureCauses);
   Map<String, AnnotationHelper> helperMap = Whitebox.getInternalState(annotator, "helperMap");
   // since the old FoundIndication doesn't contain a matchingString from the start, we check it.
   AnnotationHelper annotationHelper = helperMap.get(indication.getMatchingString());
   assertNotNull(annotationHelper);
 }
コード例 #5
0
  @Test
  public void testPostCommitTrigger() throws Exception {
    // Disable crumbs because HTMLUnit refuses to mix request bodies with
    // request parameters
    hudson.setCrumbIssuer(null);

    FreeStyleProject p = createFreeStyleProject();
    String url = "https://tsethudsonsvn.googlecode.com/svn/trunk";
    SCMTrigger trigger = new SCMTrigger("0 */6 * * *");

    p.setScm(new SubversionSCM(url));
    p.addTrigger(trigger);
    trigger.start(p, true);

    String repoUUID = "b703df53-fdd9-0691-3d8c-58db40123d9f";

    WebClient wc = new WebClient();
    WebRequestSettings wr =
        new WebRequestSettings(
            new URL(getURL() + "subversion/" + repoUUID + "/notifyCommit"), HttpMethod.POST);
    wr.setRequestBody("A   trunk/testcommit.txt");
    wr.setAdditionalHeader("Content-Type", "text/plain;charset=UTF-8");

    wr.setAdditionalHeader("X-Hudson-Subversion-Revision", "16");

    WebConnection conn = wc.getWebConnection();
    WebResponse resp = conn.getResponse(wr);
    assertTrue(isGoodHttpStatus(resp.getStatusCode()));

    waitUntilNoActivity();
    FreeStyleBuild b = p.getLastBuild();
    assertNotNull(b);
    assertBuildStatus(Result.SUCCESS, b);

    SVNRevisionState revisionState = b.getAction(SVNRevisionState.class);

    assertNotNull("Failed to find revision", revisionState);

    assertNotNull("Failed to find revision", revisionState.revisions.get(url));

    assertEquals(16, revisionState.revisions.get(url).longValue());
  }