File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\test\src\test\java\hudson\console\UrlAnnotatorTest.java.html

1 package hudson.console;
2
3 import com.gargoylesoftware.htmlunit.html.HtmlPage;
4 import hudson.Launcher;
5 import hudson.MarkupText;
6 import hudson.model.AbstractBuild;
7 import hudson.model.BuildListener;
8 import hudson.model.FreeStyleBuild;
9 import hudson.model.FreeStyleProject;
10 import org.jvnet.hudson.test.HudsonTestCase;
11 import org.jvnet.hudson.test.TestBuilder;
12
13 import java.io.IOException;
14
15 /**
16 * @author Kohsuke Kawaguchi
17 */
18 public class UrlAnnotatorTest extends HudsonTestCase {
19 public void test1() throws Exception {
20 FreeStyleProject p = createFreeStyleProject();
21 p.getBuildersList().add(new TestBuilder() {
22 @Override
23 public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
24 listener.getLogger().println("http://www.sun.com/");
25 listener.getLogger().println("<http://www.kohsuke.org/>");
26 listener.getLogger().println("<a href='http://www.oracle.com/'>");
27 return true;
28 }
29 });
30 FreeStyleBuild b = buildAndAssertSuccess(p);
31
32 HtmlPage c = createWebClient().getPage(b, "console");
33 String rsp = c.getWebResponse().getContentAsString();
34 assertTrue(rsp, rsp.contains("<a href='http://www.sun.com/'>http://www.sun.com/</a>"));
35 assertTrue(rsp, rsp.contains("<a href='http://www.kohsuke.org/'>http://www.kohsuke.org/</a>"));
36 assertTrue(rsp, rsp.contains("<a href='http://www.oracle.com/'>http://www.oracle.com/</a>"));
37 }
38
39 /**
40 * Mark up of URL should consider surrounding markers, if any.
41 */
42 public void test2() throws Exception {
43 MarkupText m = new MarkupText("{abc='http://url/',def='ghi'}");
44 new UrlAnnotator().newInstance(null).annotate(null,m);
45 String html = m.toString(false);
46 assertTrue(html.contains("<a href='http://url/'>http://url/</a>"));
47 System.out.println(html);
48 }
49 }
50