Merged revisions 24854,24862,24946,25411,25418-25419,25478,25699,25701,25770,25832,25834,26401-26404 via svnmerge from

https://www.dev.java.net/svn/hudson/branches/test-result-refactor

........
  r24854 | bshine | 2009-12-22 12:52:32 -0800 (Tue, 22 Dec 2009) | 82 lines
  
  Generalize the junit-specific TestResult class into AbstractTestResult,
  and allow plugins to contribute test result parsers that generate
  AbstractTestResult subclasses.
  
  In order to support the increasing variety of test result file formats, we
  have added two extension points:
  
   * AbstractTestResult: a class that represents a general concept of a test
     result, without any language or implementation specifics.
  
   * AbstractTestResultParser: an API for parsing test result files and
     producing an instance of a concrete subclass of AbstractTestResult
  
   
   AbstractModelObject
      \
       TestObject 
          \
           AbstractTestResult is-a ExtensionPoint
                 \
                  |-- CaseResult 
                  |
                  |-- SimpleCaseResult
                  |
                  |-- TabulatedResult
                        \
                         |-- ClassResult
                         |
                         |-- MetaTabulatedResult
                               \
                                 |-- TestResult 
                                 |
                                 |-- PackageResult
  
  
   AbstractTestResultParser is-a ExtensionPoint
      \
       JUnitParser
  
  We have refactored the JUnit result publishing system so that it is "just"
  a subclass of AbstractTestResult. We have promoted functionality into
  AbstractTestResult from TestResult; we have also promoted jelly resources
  from TestResult up to AbstractTestResult. Together, these changes make it
  possible -- without much code -- to add a test result parser and a test
  result publisher that can participate in the test result ecosystem. See,
  for instance, TrivialTestResult, with its two supporting classes,
  TrivialTestResultAction and TrivialTestResultRecorder.
  
  We have moved the format-agnostic classes in the test result system into
  the hudson.tasks.test package, from hudson.tasks.junit:
     TestObject
     MetaTabulatedResult
     TabulatedResult
  
  We have attempted at every step to preserve backwards compatibility both
  with the existing APIs and with test results stored by earlier versions of
  Hudson. Numerous tests verify that the old APIs and historical data are
  still readable; all of the tests in hudson.tasks.junit operate on stored
  builds and test results created by Hudson around version 1.320. These
  tests have been created and expanded to exercise the HTML ui and the XML
  api of the test result publishing system, as well as the underlying java
  logic.
  
     hudson.tasks.junit.CaseResultTest
     hudson.tasks.junit.JUnitParserTest
     hudson.tasks.junit.JUnitResultArchiverTest 
     hudson.tasks.junit.TestResultLinksTest 
     hudson.tasks.junit.TestResultPublishingTest   
     
  This checkin also includes several smaller changes that were enacted in the course of this work: 
     Added convenience/utility methods
        - HudsonTestCase.java
     
     Added a read-only textbox.
        - core/src/main/resources/lib/form/readOnlyTextbox.jelly
  
     Added a standalone builder that touches all files in the workspace.
        - TouchBuilder.java
  
     Added a test: testUnwrappedLongString
        - src/test/java/hudson/model/ApiTest.java
........
  r24862 | bshine | 2009-12-22 17:30:04 -0800 (Tue, 22 Dec 2009) | 1 line
  
  Recreate the hudson.tasks.junit.TestObject class, and adapt the TestResultAction.Data class to be friendly to the refactoring. This makes the claim plugin and the junit-attachments plugin compile and pass tests against this branch.
........
  r24946 | bshine | 2009-12-24 21:59:14 -0800 (Thu, 24 Dec 2009) | 1 line
  
  Getting rid of some TODOs that don't apply anymore. The TODOs that remain are meaningful.
........
  r25411 | kohsuke | 2010-01-05 18:14:15 -0800 (Tue, 05 Jan 2010) | 3 lines
  
  Cosmetic change. It's not necessary to define our own constant for empty list when there's already one in JDK.
  
  I also think creating and wasting singleton list as needed is probably better use of memory than having a singleton list tied in memory for every CaseResult. It improves cognitive overhead for people reading the code, and modern GCs are very good at handling short-lived objects, and I don't see this method called in a busy loop.
........
  r25418 | kohsuke | 2010-01-05 18:37:17 -0800 (Tue, 05 Jan 2010) | 1 line
  
  pushed the get/setDescription implemention up to the AbstractTestResultAction. I believe the default implementation is sufficient for most purposes, and typical subtypes don't want to bother with the details that descriptions are actually persisted by the owning Action instead of in TestObjects.
........
  r25419 | kohsuke | 2010-01-05 18:59:29 -0800 (Tue, 05 Jan 2010) | 1 line
  
  we should allow the parse method to be called outside of the build, so this should be TaskListener.
........
  r25478 | kohsuke | 2010-01-07 11:44:34 -0800 (Thu, 07 Jan 2010) | 14 lines
  
  The ExtensionPoint interface primarily serves as a marker to call attention of the plugin developers as to where to hook into Hudson. Since the act of implementing AbstractTestResultParser naturally make them to implement AbstractTestResult, I'm removing the ExtensionPoint marker from this abstract class.
  
  The all() method is removed after the following discussion:
  
  >> - I propose we remove AbstractTestResult.all(). I don't think being  
  >> able
  >> to enumerate AbstractTestResult subtypes buy us anything, since those
  >> can only be instantiated by parsers that intimately know how to
  >> instantiate them properly. Or did I miss the purpose of this?
  > 
  > I put in the all method because it was suggested by the wiki:
  > "You also need to define the static "all" method..."
  > http://wiki.hudson-ci.org/display/HUDSON/Defining+a+new+extension+point
  > so I don't have a problem with removing it.
........
  r25699 | bshine | 2010-01-11 16:34:12 -0800 (Mon, 11 Jan 2010) | 1 line
  
  Removed a test that exercised AbstractTestResult.all(), because that API has been removed.
........
  r25701 | bshine | 2010-01-11 17:05:40 -0800 (Mon, 11 Jan 2010) | 1 line
  
  Don't test getDescription() on a TrivialTestResult because the TrivialTestResult doesn't actually implement a description.
........
  r25770 | bshine | 2010-01-13 11:52:27 -0800 (Wed, 13 Jan 2010) | 1 line
  
  Added a failing test to demonstrate bug HUDSON-5246, inter-build diffs for junit test results are wrong.
........
  r25832 | bshine | 2010-01-14 13:50:15 -0800 (Thu, 14 Jan 2010) | 1 line
  
  The id field was accidentally declared here; it was also declared in hudson.tasks.test.TestObject. This id field here is always hidden by the id field in the more-concrete TestObject. Therefore, I'm removing this field.
........
  r25834 | bshine | 2010-01-14 13:55:10 -0800 (Thu, 14 Jan 2010) | 5 lines
  
  Fixes bugs with getPreviousResult:
  HUDSON-5269 TestResult.getPreviousResult returns null when it shouldn't
  HUDSON-5246 test-result-refactor branch: inter-build diffs for junit test results are wrong 
........
  r26401 | kohsuke | 2010-01-25 17:24:51 -0800 (Mon, 25 Jan 2010) | 7 lines
  
  renamed:
   AbstractTestResultParser -> TestResultParser
   AbstractTestResult -> TestResult
  
  This discussion is in http://n4.nabble.com/Review-requested-Test-Result-Refactoring-td978100.html#a978100
  
  The conclusion of this renaming proposal isn't clear, but I'm assuming it's OK.
........
  r26402 | kohsuke | 2010-01-25 17:27:57 -0800 (Mon, 25 Jan 2010) | 1 line
  
  elsewhere in Hudson it's the "display name" that indicates a human readable name that programs don't try to interpret.
........
  r26403 | kohsuke | 2010-01-25 17:31:38 -0800 (Mon, 25 Jan 2010) | 1 line
  
  typo
........
  r26404 | kohsuke | 2010-01-25 17:35:41 -0800 (Mon, 25 Jan 2010) | 1 line
  
  doc improvement.
........


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@26406 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2010-01-26 01:49:47 +00:00
1 parent e30746eb34
commit 92ca98c4d6
71 files changed
+3740 -696

No files matched your search

@@ -145,13 +145,13 @@ import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.xml.XmlPage;
import com.gargoylesoftware.htmlunit.html.*;
import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
import com.gargoylesoftware.htmlunit.javascript.host.Stylesheet;
import hudson.model.Computer;
import hudson.slaves.ComputerListener;
import java.util.concurrent.CountDownLatch;
/**
* Base class for all Hudson test cases.
@@ -552,6 +552,43 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
}
}
/**
* Create a new slave on the local host and wait for it to come onilne
* before returning.
*/
public DumbSlave createOnlineSlave() throws Exception {
return createOnlineSlave(null);
}
/**
* Create a new slave on the local host and wait for it to come onilne
* before returning.
*/
public DumbSlave createOnlineSlave(Label l) throws Exception {
return createOnlineSlave(l, null);
}
/**
* Create a new slave on the local host and wait for it to come online
* before returning
*/
public DumbSlave createOnlineSlave(Label l, EnvVars env) throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
ComputerListener waiter = new ComputerListener() {
@Override
public void onOnline(Computer C, TaskListener t) {
latch.countDown();
unregister();
}
};
waiter.register();
DumbSlave s = createSlave(l, env);
latch.await();
return s;
}
/**
* Blocks until the ENTER key is hit.
* This is useful during debugging a test so that one can inspect the state of Hudson through the web browser.
@@ -604,6 +641,8 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
return new WebClient().search(q);
}
/**
* Asserts that the outcome of the build is a specific outcome.
*/
@@ -623,6 +662,26 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
return r;
}
/** Determines whether the specifed HTTP status code is generally "good" */
public boolean isGoodHttpStatus(int status) {
if ((400 <= status) && (status <= 417)) {
return false;
}
if ((500 <= status) && (status <= 505)) {
return false;
}
return true;
}
/** Assert that the specifed page can be served with a "good" HTTP status,
* eg, the page is not missing and can be served without a server error
* @param page
*/
public void assertGoodStatus(Page page) {
assertTrue(isGoodHttpStatus(page.getWebResponse().getStatusCode()));
}
public <R extends Run> R assertBuildStatusSuccess(R r) throws Exception {
assertBuildStatus(Result.SUCCESS,r);
return r;
@@ -656,6 +715,73 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
page.getDocumentElement().selectSingleNode(xpath));
}
/** Asserts that the XPath matches the contents of a DomNode page. This
* variant of assertXPath(HtmlPage page, String xpath) allows us to
* examine XmlPages.
* @param page
* @param xpath
*/
public void assertXPath(DomNode page, String xpath) {
List< ? extends Object> nodes = page.getByXPath(xpath);
assertFalse("There should be an object that matches XPath:"+xpath, nodes.isEmpty());
}
public void assertXPathValue(DomNode page, String xpath, String expectedValue) {
Object node = page.getFirstByXPath(xpath);
assertNotNull("no node found", node);
assertTrue("the found object was not a Node " + xpath, node instanceof org.w3c.dom.Node);
org.w3c.dom.Node n = (org.w3c.dom.Node) node;
String textString = n.getTextContent();
assertEquals("xpath value should match for " + xpath, expectedValue, textString);
}
public void assertXPathValueContains(DomNode page, String xpath, String needle) {
Object node = page.getFirstByXPath(xpath);
assertNotNull("no node found", node);
assertTrue("the found object was not a Node " + xpath, node instanceof org.w3c.dom.Node);
org.w3c.dom.Node n = (org.w3c.dom.Node) node;
String textString = n.getTextContent();
assertTrue("needle found in haystack", textString.contains(needle));
}
public void assertXPathResultsContainText(DomNode page, String xpath, String needle) {
List<? extends Object> nodes = page.getByXPath(xpath);
assertFalse("no nodes matching xpath found", nodes.isEmpty());
boolean found = false;
for (Object o : nodes) {
if (o instanceof org.w3c.dom.Node) {
org.w3c.dom.Node n = (org.w3c.dom.Node) o;
String textString = n.getTextContent();
if ((textString != null) && textString.contains(needle)) {
found = true;
break;
}
}
}
assertTrue("needle found in haystack", found);
}
public void assertStringContains(String message, String haystack, String needle) {
if (haystack.contains(needle)) {
// good
return;
} else {
fail(message + " (seeking '" + needle + "')");
}
}
public void assertStringContains(String haystack, String needle) {
if (haystack.contains(needle)) {
// good
return;
} else {
fail("Could not find '" + needle + "'.");
}
}
/**
* Submits the form.
*/
@@ -1165,6 +1291,22 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
return p;
}
/** Loads a page as XML. Useful for testing Hudson's xml api, in concert with
* assertXPath(DomNode page, String xpath)
* @param path the path part of the url to visit
* @return the XmlPage found at that url
* @throws IOException
* @throws SAXException
*/
public XmlPage goToXml(String path) throws IOException, SAXException {
Page page = goTo(path, "application/xml");
if (page instanceof XmlPage)
return (XmlPage) page;
else
return null;
}
/**
* Returns the URL of the webapp top page.
* URL ends with '/'.
@@ -0,0 +1,45 @@
/*
* The MIT License
*
* Copyright (c) 2009, Yahoo!, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.jvnet.hudson.test;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.tasks.Builder;
import java.io.IOException;
import java.io.Serializable;
public class TouchBuilder extends Builder implements Serializable {
@Override
public boolean perform(AbstractBuild<?, ?> build,
Launcher launcher, BuildListener listener)
throws InterruptedException, IOException {
for (FilePath f : build.getWorkspace().list()) {
f.touch(System.currentTimeMillis());
}
return true;
}
}