-
-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathDescriptionSetterPublisherTest.java
More file actions
133 lines (114 loc) · 5.46 KB
/
Copy pathDescriptionSetterPublisherTest.java
File metadata and controls
133 lines (114 loc) · 5.46 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package hudson.plugins.descriptionsetter;
import hudson.markup.RawHtmlMarkupFormatter;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import jenkins.model.Jenkins;
import org.jvnet.hudson.test.HudsonTestCase;
public class DescriptionSetterPublisherTest extends HudsonTestCase {
public void testSuccessDefaultDescription() throws Exception {
assertEquals("one", getDescription("text one", Result.SUCCESS, "text (.*)", null, null, null));
}
public void testSuccessConfiguredDescription() throws Exception {
assertEquals(
"description one",
getDescription("text one", Result.SUCCESS, "text (.*)", null, "description \\1", null));
}
public void testSuccessConfiguredDescription2() throws Exception {
assertEquals(
"description one two",
getDescription(
"text one two", Result.SUCCESS, "text (\\w+) (\\w+)", null, "description \\1 \\2", null));
}
public void testFailureWithNoFailureRegex() throws Exception {
assertEquals("one", getDescription("text one", Result.FAILURE, "text (.*)", null, null, null));
}
public void testFailureWithFailureRegexAndDefaultDescrption() throws Exception {
assertEquals("text", getDescription("text one", Result.FAILURE, "text (.*)", "(.*) one", null, null));
}
public void testFailureWithFailureRegexAndConfiguredDescription() throws Exception {
assertEquals(
"description text",
getDescription("text one", Result.FAILURE, "text (.*)", "(.*) one", null, "description \\1"));
}
public void testSuccessWithFixedDescription() throws Exception {
assertEquals(
"description success",
getDescription("xxx", Result.SUCCESS, null, null, "description success", "description failure"));
}
public void testFailureWithFixedDescription() throws Exception {
assertEquals(
"description failure",
getDescription("xxx", Result.FAILURE, null, null, "description success", "description failure"));
}
public void testSuccessNoMatch() throws Exception {
assertEquals(null, getDescription("xxx", Result.SUCCESS, "regex", null, "description success", null));
}
public void testURL() throws Exception {
assertEquals(
"<a href=\"http://foo/bar\">http://foo/bar</a>",
getDescription("url:http://foo/bar", Result.SUCCESS, "url:(.*)", null, null, null));
}
public void testNullMatch1() throws Exception {
assertEquals(
"Match=(MatchOne) MatchTwo",
getDescription(
"Prefix: MatchOne MatchTwo",
Result.SUCCESS,
"^Prefix: (\\S+)( .*)?$",
null,
"Match=(\\1)\\2",
null));
}
public void testNullMatch2() throws Exception {
assertEquals(
"Match=(MatchOne)",
getDescription(
"Prefix: MatchOne", Result.SUCCESS, "^Prefix: (\\S+)( .*)?$", null, "Match=(\\1)\\2", null));
}
public void testAppendDescriptionInPublisher() throws Exception {
FreeStyleProject project = createFreeStyleProject();
project.getBuildersList().add(new DescriptionSetterBuilder("", "test1", false, true));
project.getPublishersList().add(new DescriptionSetterPublisher("", "", "test2", "", false, true, true));
FreeStyleBuild build = project.scheduleBuild2(0).get();
assertEquals("test1 test2", build.getDescription());
/* Use the safe HTML markup formatter */
Jenkins.get().setMarkupFormatter(new RawHtmlMarkupFormatter(false));
FreeStyleBuild buildWithFormatter = project.scheduleBuild2(0).get();
assertEquals("test1<br>test2", buildWithFormatter.getDescription());
}
public void testRewriteDescriptionInPublisher() throws Exception {
FreeStyleProject project = createFreeStyleProject();
project.getBuildersList().add(new DescriptionSetterBuilder("", "test1", false, true));
project.getPublishersList().add(new DescriptionSetterPublisher("", "", "test2", "", false, false, true));
FreeStyleBuild build = project.scheduleBuild2(0).get();
assertEquals("test2", build.getDescription());
}
private String getDescription(
String text,
Result result,
String regexp,
String regexpForFailed,
String description,
String descriptionForFailed,
boolean appendMode)
throws Exception {
FreeStyleProject project = createFreeStyleProject();
project.getBuildersList().add(new TestBuilder(text, result));
project.getPublishersList()
.add(new DescriptionSetterPublisher(
regexp, regexpForFailed, description, descriptionForFailed, false, appendMode, true));
FreeStyleBuild build = project.scheduleBuild2(0).get();
return build.getDescription();
}
private String getDescription(
String text,
Result result,
String regexp,
String regexpForFailed,
String description,
String descriptionForFailed)
throws Exception {
return getDescription(text, result, regexp, regexpForFailed, description, descriptionForFailed, true);
}
}