Skip to content
Permalink
Browse files

JENKINS-19353 - Exception error message newlines are escaped

Added a new test as well for testing both the test description and exception messages
  • Loading branch information
nullin committed Feb 8, 2014
1 parent 379f8f0 commit 8777f912835184269e66214f00567da44209e79a
3 README
@@ -16,6 +16,9 @@ graph and all details about which tests that failed are also presented.
Release Notes
-------

### Upcoming
* Fixed: JENKINS-19353 - Exception error message newlines are escaped

### v1.5
* Fixed: JENKINS-19157 - Make st:bind work when Jenkins has jQuery plugin installed
* Add failure details to failed configuration methods on TestNG results page
@@ -90,7 +90,7 @@ div(id: "report") {
p(id:"exp-msg") {
b("Message: ")
if (my.exception.message) {
raw("${testngProjAction.escapeExceptionMsg ? my.annotate(my.exception.message) : my.exception.message}")
raw("${testngProjAction.escapeExceptionMsg ? my.annotate(my.exception.message) : my.exception.message.replace("\n", "<br/>")}")
} else {
text("(none)")
}
@@ -44,4 +44,8 @@
* Test description has HTML tags
*/
public static final String TESTNG_DESCRIPTION_HTML = "testng-description-html.xml";
/**
* Test description and Exception message have multi-lines
*/
public static final String TESTNG_MULTILINE_EXCEPTION_AND_DESCRIPTION = "testng-xml-multiline-exp-msg-and-descp.xml";
}
@@ -1,9 +1,15 @@
package hudson.plugins.testng.results;

import java.io.IOException;

import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.Launcher;
import hudson.model.*;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import hudson.plugins.testng.CommonUtil;
import hudson.plugins.testng.Constants;
import hudson.plugins.testng.PluginImpl;
@@ -14,8 +20,6 @@
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.TestBuilder;

import java.io.IOException;

/**
* Tests for {@link MethodResult}'s view page
*
@@ -100,8 +104,8 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
//Compare output
String methodUrl = build.getUrl() + PluginImpl.URL + "/com.test/com.test.UploadTest/uploadFile";
HtmlPage page = createWebClient().goTo(methodUrl);
HtmlElement expMsg = page.getElementById("description");
String contents = expMsg.getTextContent();
HtmlElement description = page.getElementById("description");
String contents = description.getTextContent();
assertFalse(contents.contains("</a>")); //non-escaped HTML so it doesn't show up as text
assertFalse(contents.contains("<a href=\"")); //non-escaped HTML
}
@@ -128,11 +132,50 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
//Compare output
String methodUrl = build.getUrl() + PluginImpl.URL + "/com.test/com.test.UploadTest/uploadFile";
HtmlPage page = createWebClient().goTo(methodUrl);
HtmlElement expMsg = page.getElementById("description");
String contents = expMsg.getTextContent();
HtmlElement description = page.getElementById("description");
String contents = description.getTextContent();
assertStringContains(contents, "</a>"); //escaped HTML so it shows up as text
}

/**
* Tests to make sure that newline characters are escaped correctly in description and
* exception message even when escape settings are set to false.
*
* Note that newline in description has to be denoted by &#10; as it's an attribute in
* testng result XML, where as exception message doesn't as it's wrapped in a CDATA
*
* @throws Exception
*/
@Test
public void testMultilineDescriptionAndExceptionMessage() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("testng.xml", false /*escapeDescription*/, false /*escapeException*/);
p.getPublishersList().add(publisher);
p.onCreatedFromScratch(); //to setup project action

p.getBuildersList().add(new TestBuilder() {
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
BuildListener listener) throws InterruptedException, IOException {
String contents = CommonUtil.getContents(Constants.TESTNG_MULTILINE_EXCEPTION_AND_DESCRIPTION);
build.getWorkspace().child("testng.xml").write(contents,"UTF-8");
return true;
}
});

//run build
FreeStyleBuild build = p.scheduleBuild2(0).get();

//Compare output
String methodUrl = build.getUrl() + PluginImpl.URL + "/com.fakepkg.test/com.fakepkg.test.FoobarTests/test";
HtmlPage page = createWebClient().goTo(methodUrl);
HtmlElement description = page.getElementById("description");
assertEquals(2, description.getElementsByTagName("br").size());

HtmlElement exp = page.getElementById("exp-msg");
assertEquals(2, exp.getElementsByTagName("br").size());

}

@Test
public void testReporterLogOutput() throws Exception {
FreeStyleProject p = createFreeStyleProject();
@@ -245,7 +288,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
* @throws Exception
*/
@Test
public void testMethodResults2() throws Exception {
public void testMethodResults_dataProviderTests() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("testng.xml", false, false);
p.getPublishersList().add(publisher);
@@ -321,7 +364,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
* @throws Exception
*/
@Test
public void testMethodResults3() throws Exception {
public void testMethodResults_testInstanceNames() throws Exception {
FreeStyleProject p = createFreeStyleProject();
Publisher publisher = new Publisher("testng.xml", false, false);
p.getPublishersList().add(publisher);
@@ -0,0 +1,45 @@
<testng-results>
<reporter-output>
</reporter-output>
<suite name="Multiline Exception message and Test Description" duration-ms="44881" started-at="2011-05-05T00:59:00Z" finished-at="2011-05-05T00:59:45Z">
<groups>
</groups>
<test name="Multiline Exception message and Test Description test" duration-ms="44881" started-at="2011-05-05T00:59:00Z" finished-at="2011-05-05T00:59:45Z">
<class name="com.fakepkg.test.FoobarTests">
<test-method status="PASS" signature="setUp()" name="setUp" is-config="true" duration-ms="1" started-at="2011-05-05T00:59:42Z" finished-at="2011-05-05T00:59:42Z">
</test-method>
<test-method status="FAIL" signature="test()" name="test" description="This description has
&#10;multiple lines.
&#10;Really it does" duration-ms="3043" started-at="2011-05-05T00:59:42Z" finished-at="2011-05-05T00:59:44Z">
<exception class="java.lang.AssertionError">
<message>
<![CDATA[Test did not generate the expected output.
1. See files for details (this should be a separate line).
2. Do something to fix it.(this should be a separate line).]]>
</message>
<full-stacktrace>
<![CDATA[java.lang.AssertionError: Test did not generate the expected output.
1. See files for details (this should be a separate line).
2. Do something to fix it.(this should be a separate line).
at org.testng.Assert.fail(Assert.java:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:74)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:673)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:846)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1170)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
]]>
</full-stacktrace>
</exception>
</test-method>
</class>
</test>
</suite>
</testng-results>

0 comments on commit 8777f91

Please sign in to comment.
You can’t perform that action at this time.