提交 87e66570 编写于 作者: J Jesse Glick

JUnit 4.

上级 8ec605a4
......@@ -20,30 +20,35 @@ import hudson.scm.RepositoryBrowser;
import hudson.scm.SCMDescriptor;
import hudson.scm.SCMRevisionState;
import hudson.triggers.SCMTrigger;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.SequenceLock;
import org.jvnet.hudson.test.SingleFileSCM;
import org.jvnet.hudson.test.TestBuilder;
import org.jvnet.hudson.test.TestExtension;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Future;
import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.SequenceLock;
import org.jvnet.hudson.test.SingleFileSCM;
import org.jvnet.hudson.test.TestBuilder;
import org.jvnet.hudson.test.TestExtension;
/**
* @author Kohsuke Kawaguchi
*/
public class ConsoleAnnotatorTest extends HudsonTestCase {
public class ConsoleAnnotatorTest {
@Rule public JenkinsRule r = new JenkinsRule();
/**
* Let the build complete, and see if stateless {@link ConsoleAnnotator} annotations happen as expected.
*/
@Bug(6031)
public void testCompletedStatelessLogAnnotation() throws Exception {
FreeStyleProject p = createFreeStyleProject();
@Test public void completedStatelessLogAnnotation() throws Exception {
FreeStyleProject p = r.createFreeStyleProject();
p.getBuildersList().add(new TestBuilder() {
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
listener.getLogger().println("---");
......@@ -53,14 +58,14 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
}
});
FreeStyleBuild b = buildAndAssertSuccess(p);
FreeStyleBuild b = r.buildAndAssertSuccess(p);
// make sure we see the annotation
HtmlPage rsp = createWebClient().getPage(b, "console");
HtmlPage rsp = r.createWebClient().getPage(b, "console");
assertEquals(1,rsp.selectNodes("//B[@class='demo']").size());
// make sure raw console output doesn't include the garbage
TextPage raw = (TextPage)createWebClient().goTo(b.getUrl()+"consoleText","text/plain");
TextPage raw = (TextPage)r.createWebClient().goTo(b.getUrl()+"consoleText","text/plain");
System.out.println(raw.getContent());
String nl = System.getProperty("line.separator");
assertTrue(raw.getContent().contains(nl+"---"+nl+"ooo"+nl+"ooo"+nl));
......@@ -73,7 +78,7 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
/**
* Only annotates the first occurrence of "ooo".
*/
@TestExtension("testCompletedStatelessLogAnnotation")
@TestExtension("completedStatelessLogAnnotation")
public static final ConsoleAnnotatorFactory DEMO_ANNOTATOR = new ConsoleAnnotatorFactory() {
public ConsoleAnnotator newInstance(Object context) {
return new DemoAnnotator();
......@@ -93,8 +98,8 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
}
@Bug(6034)
public void testConsoleAnnotationFilterOut() throws Exception {
FreeStyleProject p = createFreeStyleProject();
@Test public void consoleAnnotationFilterOut() throws Exception {
FreeStyleProject p = r.createFreeStyleProject();
p.getBuildersList().add(new TestBuilder() {
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
listener.getLogger().print("abc\n");
......@@ -103,14 +108,14 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
}
});
FreeStyleBuild b = buildAndAssertSuccess(p);
FreeStyleBuild b = r.buildAndAssertSuccess(p);
// make sure we see the annotation
HtmlPage rsp = createWebClient().getPage(b, "console");
HtmlPage rsp = r.createWebClient().getPage(b, "console");
assertEquals(1,rsp.selectNodes("//A[@href='http://infradna.com/']").size());
// make sure raw console output doesn't include the garbage
TextPage raw = (TextPage)createWebClient().goTo(b.getUrl()+"consoleText","text/plain");
TextPage raw = (TextPage)r.createWebClient().goTo(b.getUrl()+"consoleText","text/plain");
System.out.println(raw.getContent());
assertTrue(raw.getContent().contains("\nabc\ndef\n"));
}
......@@ -120,20 +125,20 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
class ProgressiveLogClient {
WebClient wc;
JenkinsRule.WebClient wc;
Run run;
String consoleAnnotator;
String start;
private Page p;
ProgressiveLogClient(WebClient wc, Run r) {
ProgressiveLogClient(JenkinsRule.WebClient wc, Run r) {
this.wc = wc;
this.run = r;
}
String next() throws IOException {
WebRequestSettings req = new WebRequestSettings(new URL(getURL() + run.getUrl() + "/logText/progressiveHtml"+(start!=null?"?start="+start:"")));
WebRequestSettings req = new WebRequestSettings(new URL(r.getURL() + run.getUrl() + "/logText/progressiveHtml"+(start!=null?"?start="+start:"")));
Map headers = new HashMap();
if (consoleAnnotator!=null)
headers.put("X-ConsoleAnnotator",consoleAnnotator);
......@@ -151,10 +156,10 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
* Tests the progressive output by making sure that the state of {@link ConsoleAnnotator}s are
* maintained across different progressiveLog calls.
*/
public void testProgressiveOutput() throws Exception {
@Test public void progressiveOutput() throws Exception {
final SequenceLock lock = new SequenceLock();
WebClient wc = createWebClient();
FreeStyleProject p = createFreeStyleProject();
JenkinsRule.WebClient wc = r.createWebClient();
FreeStyleProject p = r.createFreeStyleProject();
p.getBuildersList().add(new TestBuilder() {
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
lock.phase(0);
......@@ -186,10 +191,10 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
lock.done();
// should complete successfully
assertBuildStatusSuccess(f);
r.assertBuildStatusSuccess(f);
}
@TestExtension("testProgressiveOutput")
@TestExtension("progressiveOutput")
public static final ConsoleAnnotatorFactory STATEFUL_ANNOTATOR = new ConsoleAnnotatorFactory() {
public ConsoleAnnotator newInstance(Object context) {
return new StatefulAnnotator();
......@@ -210,10 +215,10 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
/**
* Place {@link ConsoleNote}s and make sure it works.
*/
public void testConsoleAnnotation() throws Exception {
@Test public void consoleAnnotation() throws Exception {
final SequenceLock lock = new SequenceLock();
WebClient wc = createWebClient();
FreeStyleProject p = createFreeStyleProject();
JenkinsRule.WebClient wc = r.createWebClient();
FreeStyleProject p = r.createFreeStyleProject();
p.getBuildersList().add(new TestBuilder() {
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
lock.phase(0);
......@@ -252,7 +257,7 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
lock.done();
// should complete successfully
assertBuildStatusSuccess(f);
r.assertBuildStatusSuccess(f);
}
/**
......@@ -276,11 +281,11 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
/**
* script.js defined in the annotator needs to be incorporated into the console page.
*/
public void testScriptInclusion() throws Exception {
FreeStyleProject p = createFreeStyleProject();
FreeStyleBuild b = buildAndAssertSuccess(p);
@Test public void scriptInclusion() throws Exception {
FreeStyleProject p = r.createFreeStyleProject();
FreeStyleBuild b = r.buildAndAssertSuccess(p);
HtmlPage html = createWebClient().getPage(b, "console");
HtmlPage html = r.createWebClient().getPage(b, "console");
// verify that there's an element inserted by the script
assertNotNull(html.getElementById("inserted-by-test1"));
assertNotNull(html.getElementById("inserted-by-test2"));
......@@ -291,7 +296,7 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
return null;
}
@TestExtension("testScriptInclusion")
@TestExtension("scriptInclusion")
public static final class DescriptorImpl extends ConsoleAnnotationDescriptor {
public String getDisplayName() {
return "just to include a script";
......@@ -299,7 +304,7 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
}
}
@TestExtension("testScriptInclusion")
@TestExtension("scriptInclusion")
public static final class JustToIncludeScriptAnnotator extends ConsoleAnnotatorFactory {
public ConsoleAnnotator newInstance(Object context) {
return null;
......@@ -311,8 +316,8 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
* Makes sure '<', '&', are escaped.
*/
@Bug(5952)
public void testEscape() throws Exception {
FreeStyleProject p = createFreeStyleProject();
@Test public void escape() throws Exception {
FreeStyleProject p = r.createFreeStyleProject();
p.getBuildersList().add(new TestBuilder() {
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
......@@ -321,31 +326,31 @@ public class ConsoleAnnotatorTest extends HudsonTestCase {
}
});
FreeStyleBuild b = buildAndAssertSuccess(p);
HtmlPage html = createWebClient().getPage(b, "console");
FreeStyleBuild b = r.buildAndAssertSuccess(p);
HtmlPage html = r.createWebClient().getPage(b, "console");
String text = html.asText();
System.out.println(text);
assertTrue(text.contains("<b>&amp;</b>"));
assertTrue(b.getLog().contains("<b>&amp;</b>"));
assertTrue(JenkinsRule.getLog(b).contains("<b>&amp;</b>"));
}
/**
* Makes sure that annotations in the polling output is handled correctly.
*/
public void testPollingOutput() throws Exception {
FreeStyleProject p = createFreeStyleProject();
@Test public void pollingOutput() throws Exception {
FreeStyleProject p = r.createFreeStyleProject();
p.setScm(new PollingSCM());
SCMTrigger t = new SCMTrigger("@daily");
t.start(p,true);
p.addTrigger(t);
buildAndAssertSuccess(p);
r.buildAndAssertSuccess(p);
// poll now
t.new Runner().run();
HtmlPage log = createWebClient().getPage(p, "scmPollLog");
HtmlPage log = r.createWebClient().getPage(p, "scmPollLog");
String text = log.asText();
assertTrue(text, text.contains("$$$hello from polling"));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册