/
HtmlFileNameTest.java
72 lines (52 loc) · 2.84 KB
/
HtmlFileNameTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package htmlpublisher;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.CreateFileBuilder;
import org.jvnet.hudson.test.JenkinsRule;
import org.htmlunit.html.HtmlInlineFrame;
import org.htmlunit.html.HtmlPage;
import hudson.model.FreeStyleProject;
public class HtmlFileNameTest {
@Rule
public JenkinsRule j = new JenkinsRule();
@Test
public void fileNameWithSpecialCharactersAndSingleSlash() throws Exception {
final String content = "<html><head><title>test</title></head><body>Hello world!</body></html>";
FreeStyleProject job = j.createFreeStyleProject();
job.getBuildersList().add(new CreateFileBuilder("subdir/#$+,;= @.html", content));
job.getPublishersList().add(new HtmlPublisher(Arrays.asList(
new HtmlPublisherTarget("report-name", "", "subdir/*.html", true, true, false))));
job.save();
j.buildAndAssertSuccess(job);
JenkinsRule.WebClient client = j.createWebClient();
assertEquals(content,
client.getPage(job, "report-name/subdir/%23%24%2B%2C%3B%3D%20%40.html").getWebResponse().getContentAsString());
// published html page(s)
HtmlPage page = client.getPage(job, "report-name");
HtmlInlineFrame iframe = (HtmlInlineFrame) page.getElementById("myframe");
assertEquals("subdir/%23%24%2B%2C%3B%3D%20%40.html", iframe.getAttribute("src"));
HtmlPage pageInIframe = (HtmlPage) iframe.getEnclosedPage();
assertEquals("Hello world!", pageInIframe.getBody().asNormalizedText());
}
@Test
public void fileNameWithSpecialCharactersAndMultipleSlashes() throws Exception {
final String content = "<html><head><title>test</title></head><body>Hello world!</body></html>";
FreeStyleProject job = j.createFreeStyleProject();
job.getBuildersList().add(new CreateFileBuilder("subdir/subdir2/#$+,;= @.html", content));
job.getPublishersList().add(new HtmlPublisher(Arrays.asList(
new HtmlPublisherTarget("report-name", "", "subdir/subdir2/*.html", true, true, false))));
job.save();
j.buildAndAssertSuccess(job);
JenkinsRule.WebClient client = j.createWebClient();
assertEquals(content,
client.getPage(job, "report-name/subdir/subdir2/%23%24%2B%2C%3B%3D%20%40.html").getWebResponse().getContentAsString());
// published html page(s)
HtmlPage page = client.getPage(job, "report-name");
HtmlInlineFrame iframe = (HtmlInlineFrame) page.getElementById("myframe");
assertEquals("subdir/subdir2/%23%24%2B%2C%3B%3D%20%40.html", iframe.getAttribute("src"));
HtmlPage pageInIframe = (HtmlPage) iframe.getEnclosedPage();
assertEquals("Hello world!", pageInIframe.getBody().asNormalizedText());
}
}