/**
   * Verifies that we find the correct results for the following constellation.
   *
   * <ol>
   *   <li>Build with result, build result = SUCCESS
   *   <li>Build with no result
   *   <li>Build with result, build result = FAILURE
   *   <li>Build with no result
   *   <li>Baseline
   * </ol>
   *
   * @throws Exception the exception
   */
  @SuppressWarnings("rawtypes")
  @Test
  public void testHasReferenceResult() throws Exception {
    AbstractBuild withSuccessResult = mock(AbstractBuild.class);
    AbstractBuild noResult2 = mock(AbstractBuild.class);
    AbstractBuild withFailureResult = mock(AbstractBuild.class);
    AbstractBuild noResult1 = mock(AbstractBuild.class);
    AbstractBuild baseline = mock(AbstractBuild.class);
    when(baseline.getPreviousBuild()).thenReturn(noResult1);
    when(noResult1.getPreviousBuild()).thenReturn(withFailureResult);
    when(withFailureResult.getPreviousBuild()).thenReturn(noResult2);
    when(noResult2.getPreviousBuild()).thenReturn(withSuccessResult);

    TestResultAction failureAction = mock(TestResultAction.class);
    when(withFailureResult.getAction(TestResultAction.class)).thenReturn(failureAction);
    when(failureAction.isSuccessful()).thenReturn(false);
    BuildResult failureResult = mock(BuildResult.class);
    when(failureAction.getResult()).thenReturn(failureResult);

    TestResultAction successAction = mock(TestResultAction.class);
    when(withSuccessResult.getAction(TestResultAction.class)).thenReturn(successAction);
    when(successAction.isSuccessful()).thenReturn(true);
    BuildResult successResult = mock(BuildResult.class);
    AnnotationContainer container = mock(AnnotationContainer.class);
    when(successResult.getContainer()).thenReturn(container);
    when(successAction.getResult()).thenReturn(successResult);

    BuildHistory history = createHistory(baseline);

    assertTrue("Build has no previous result", history.hasPreviousResult());
    assertSame("Build has wrong previous result", failureResult, history.getPreviousResult());
    assertSame("Build has wrong reference result", container, history.getReferenceAnnotations());
  }
Example #2
0
  // public void appendPath(ExtendedGeneralPath path, BuildHistory hist)
  public void appendPath(GeneralPath path, BuildHistory hist) {
    float offx = isRelative ? hist.lastPoint.x : 0f;
    float offy = isRelative ? hist.lastPoint.y : 0f;

    path.quadTo(kx + offx, ky + offy, x + offx, y + offy);
    hist.setLastPoint(x + offx, y + offy);
    hist.setLastKnot(kx + offx, ky + offy);
  }
 /** Test size */
 @Test
 public void testAddAndSize() {
   assertEquals(1, history.size());
   history.add(new BuildHistoryItem("second"));
   assertEquals(2, history.size());
   history.add(new BuildHistoryItem("third"));
   assertEquals(3, history.size());
 }
  /** Test history list does not exceed the max size */
  @Test
  public void testHistoryListDoesNotExceedMaxSize() {

    while (history.size() < BuildHistory.SIZE) {
      history.add(new BuildHistoryItem("test"));
    }

    assertEquals(BuildHistory.SIZE, history.size());

    history.add(new BuildHistoryItem("one more"));
    assertEquals(BuildHistory.SIZE, history.size());
  }
  /**
   * Verifies that we have no results for the first build.
   *
   * @throws Exception the exception
   */
  @Test(expected = NoSuchElementException.class)
  public void testNoPreviousResult() throws Exception {
    BuildHistory history = createHistory(mock(AbstractBuild.class));

    assertFalse("Build has a previous result", history.hasPreviousResult());
    assertEquals(
        "Build has wrong reference annotations",
        0,
        history.getReferenceAnnotations().getNumberOfAnnotations());

    history.getPreviousResult();
  }
  /**
   * Verifies that we find the correct results for the following constellation.
   *
   * <ol>
   *   <li>Build with result
   *   <li>Build with no result
   *   <li>Baseline
   * </ol>
   *
   * @throws Exception the exception
   */
  @Test
  @SuppressWarnings("rawtypes")
  public void testHasPreviousResult() throws Exception {
    AbstractBuild withResult = mock(AbstractBuild.class);
    AbstractBuild noResult = mock(AbstractBuild.class);
    AbstractBuild baseline = mock(AbstractBuild.class);
    when(baseline.getPreviousBuild()).thenReturn(noResult);
    when(noResult.getPreviousBuild()).thenReturn(withResult);

    TestResultAction action = mock(TestResultAction.class);
    when(withResult.getAction(TestResultAction.class)).thenReturn(action);
    BuildResult result = mock(BuildResult.class);
    when(action.getResult()).thenReturn(result);
    AnnotationContainer container = mock(AnnotationContainer.class);
    when(result.getContainer()).thenReturn(container);
    BuildHistory history = createHistory(baseline);

    assertTrue("Build has no previous result", history.hasPreviousResult());
    assertSame("Build has wrong previous result", result, history.getPreviousResult());
    assertSame("Build has wrong reference result", container, history.getReferenceAnnotations());
  }
  public final void doBuild(StaplerRequest req, StaplerResponse rsp)
      throws ServletException, IOException {
    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.log(Level.FINE, "doBuild action called");
    }

    String buildAction = req.getParameter("action");
    if (buildAction == null) {
      rsp.forwardToPreviousPage(req);
      return;
    }

    String buildType = req.getParameter("build");
    if (buildType == null) {
      rsp.forwardToPreviousPage(req);
      return;
    }

    BuildAction action;
    BuildType type;

    try {
      action = BuildAction.valueOf(buildAction.toUpperCase());
      type = BuildType.valueOf(buildType.toUpperCase());
    } catch (IllegalArgumentException e) {
      rsp.forwardToPreviousPage(req);
      return;
    }

    Builder builder = new Builder(action);

    String params = req.getParameter("params");
    BulkParamProcessor processor = new BulkParamProcessor(params);
    Map<String, String> projectParams = processor.getProjectParams();

    String paramBuild = req.getParameter("paramBuild");
    if (paramBuild != null && !paramBuild.isEmpty() && !projectParams.isEmpty()) {
      builder.setUserParams(projectParams);
    }

    String pattern = req.getParameter("pattern");
    if (pattern != null && !pattern.isEmpty()) {
      builder.setPattern(pattern);
      BuildHistory history = Jenkins.getInstance().getPlugin(BuildHistory.class);
      history.add(new BuildHistoryItem(pattern));
    }

    String view = req.getParameter("view");
    if (view != null && !view.isEmpty()) {
      builder.setView(view);
    }

    switch (type) {
      case ABORTED:
        builder.buildAborted();
        break;
      case ALL:
        builder.buildAll();
        break;
      case FAILED:
        builder.buildFailed();
        break;
      case FAILED_ONLY:
        builder.buildFailedOnly();
        break;
      case NOT_BUILD_ONLY:
        builder.buildNotBuildOnly();
        break;
      case NOT_BUILT:
        builder.buildNotBuilt();
        break;
      case UNSTABLE:
        builder.buildUnstable();
        break;
      case UNSTABLE_ONLY:
        builder.buildUnstableOnly();
        break;
    }

    rsp.forwardToPreviousPage(req);
  }
 /** Test clear */
 @Test
 public void testClear() {
   assertNotSame(0, history.size());
   history.clear();
   assertEquals(0, history.size());
 }
 @Before
 public void setUp() {
   item = new BuildHistoryItem(pattern);
   history.add(item);
 }