-
Notifications
You must be signed in to change notification settings - Fork 274
/
PluginPatchsetCreatedEventTest.java
181 lines (155 loc) · 8.25 KB
/
PluginPatchsetCreatedEventTest.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.event;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginPatchsetCreatedEvent;
import com.sonymobile.tools.gerrit.gerritevents.dto.GerritChangeKind;
import com.sonymobile.tools.gerrit.gerritevents.dto.attr.Account;
import com.sonymobile.tools.gerrit.gerritevents.dto.attr.Change;
import com.sonymobile.tools.gerrit.gerritevents.dto.attr.PatchSet;
import com.sonymobile.tools.gerrit.gerritevents.dto.events.PatchsetCreated;
/**
* Tests for {@link PluginPatchsetCreatedEvent}.
*
* @author Hugo Arès <hugo.ares@ericsson.com>
*/
public class PluginPatchsetCreatedEventTest {
/**
* Tests that it should fire on all type of patchset.
*/
@Test
public void shouldFireOnAllTypeOfPatchset() {
PluginPatchsetCreatedEvent pluginPatchsetCreatedEvent =
new PluginPatchsetCreatedEvent();
PatchsetCreated patchsetCreated = new PatchsetCreated();
patchsetCreated.setPatchset(new PatchSet());
//should fire on regular patchset and drafts
assertTrue(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
patchsetCreated.getPatchSet().setDraft(true);
assertTrue(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
}
/**
* Tests that it should not fire on draft patchset when they are excluded.
*/
@Test
public void shouldNotFireOnDraftPatchsetWhenExcluded() {
PluginPatchsetCreatedEvent pluginPatchsetCreatedEvent =
new PluginPatchsetCreatedEvent();
pluginPatchsetCreatedEvent.setExcludeDrafts(true);
PatchsetCreated patchsetCreated = new PatchsetCreated();
patchsetCreated.setPatchset(new PatchSet());
//should fire only on regular patchset (no drafts)
assertTrue(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
patchsetCreated.getPatchSet().setDraft(true);
assertFalse(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
}
/**
* Tests that it should not fire on trivial rebase when they are excluded.
* Also tests that we don't fire for no change while ignoring trivial rebases.
* @author Doug Kelly <dougk.ff7@gmail.com>
*/
@Test
public void shouldNotFireOnTrivialRebaseWhenExcluded() {
PluginPatchsetCreatedEvent pluginPatchsetCreatedEvent =
new PluginPatchsetCreatedEvent();
pluginPatchsetCreatedEvent.setExcludeTrivialRebase(true);
PatchsetCreated patchsetCreated = new PatchsetCreated();
patchsetCreated.setPatchset(new PatchSet());
//should fire only on regular patchset (no drafts)
assertTrue(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
patchsetCreated.getPatchSet().setKind(GerritChangeKind.TRIVIAL_REBASE);
assertFalse(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
patchsetCreated.getPatchSet().setKind(GerritChangeKind.NO_CHANGE);
assertFalse(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
}
/**
* Tests that it should not fire on no code changes when they are excluded.
* Also tests that we don't fire for no change while ignoring no code change.
* @author Doug Kelly <dougk.ff7@gmail.com>
*/
@Test
public void shouldNotFireOnNoCodeChangeWhenExcluded() {
PluginPatchsetCreatedEvent pluginPatchsetCreatedEvent =
new PluginPatchsetCreatedEvent();
pluginPatchsetCreatedEvent.setExcludeNoCodeChange(true);
PatchsetCreated patchsetCreated = new PatchsetCreated();
patchsetCreated.setPatchset(new PatchSet());
//should fire only on regular patchset (no drafts)
assertTrue(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
patchsetCreated.getPatchSet().setKind(GerritChangeKind.NO_CODE_CHANGE);
assertFalse(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
patchsetCreated.getPatchSet().setKind(GerritChangeKind.NO_CHANGE);
assertFalse(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
}
/**
* Test that it should, or should not, fire if the commit message matches a regular expression.
*/
@Test
public void commitMessageRegExCheck() {
PluginPatchsetCreatedEvent pluginPatchsetCreatedEvent =
new PluginPatchsetCreatedEvent();
PatchsetCreated patchsetCreated = new PatchsetCreated();
patchsetCreated.setPatchset(new PatchSet());
StringBuilder commitMessage = new StringBuilder();
commitMessage.append("This is a summary\n");
commitMessage.append("\n");
commitMessage.append("This is my description.\n");
commitMessage.append("\n");
commitMessage.append("Issue: JENKINS-64091\n");
Change change = new Change();
change.setCommitMessage(commitMessage.toString());
patchsetCreated.setChange(change);
// Commit Message regular expression set to null
pluginPatchsetCreatedEvent.setCommitMessageContainsRegEx(null);
assertTrue(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
// Commit message Regular expression is an empty string
pluginPatchsetCreatedEvent.setCommitMessageContainsRegEx("");
assertTrue(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
// Commit message Regular expression matches
pluginPatchsetCreatedEvent.setCommitMessageContainsRegEx("JENKINS");
assertTrue(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
// Commit message Regular expression matches
pluginPatchsetCreatedEvent.setCommitMessageContainsRegEx("Issue:.*JENKINS.*");
assertTrue(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
// Commit message Regular expression does not match
pluginPatchsetCreatedEvent.setCommitMessageContainsRegEx("Issue:.*MY_THING.*");
boolean result = pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated);
assertFalse(result);
// Commit message Regular expression does not match
pluginPatchsetCreatedEvent.setCommitMessageContainsRegEx("MY_THING");
assertFalse(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
}
/**
* Test that it should, or should not, fire if the uploader name matches a regular expression.
*/
@Test
public void uploaderNameRegExCheck() {
PluginPatchsetCreatedEvent pluginPatchsetCreatedEvent =
new PluginPatchsetCreatedEvent();
PatchsetCreated patchsetCreated = new PatchsetCreated();
PatchSet patchSet = new PatchSet();
patchSet.setUploader(new Account("test-uploader-name", "test@test.com"));
patchsetCreated.setPatchset(patchSet);
Change change = new Change();
change.setCommitMessage("new commit");
patchsetCreated.setChange(change);
// Uploader name regular expression set to null
pluginPatchsetCreatedEvent.setUploaderNameContainsRegEx(null);
assertTrue(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
// Uploader name Regular expression is an empty string
pluginPatchsetCreatedEvent.setUploaderNameContainsRegEx("");
assertTrue(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
// Uploader name Regular expression matches
pluginPatchsetCreatedEvent.setUploaderNameContainsRegEx("test");
assertTrue(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
// Uploader name Regular expression matches
pluginPatchsetCreatedEvent.setUploaderNameContainsRegEx(".*uploader.*");
assertTrue(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
// Uploader name Regular expression does not match
pluginPatchsetCreatedEvent.setUploaderNameContainsRegEx(".*MY_THING.*");
assertFalse(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
// Uploader name Regular expression does not match
pluginPatchsetCreatedEvent.setUploaderNameContainsRegEx("MY_THING");
assertFalse(pluginPatchsetCreatedEvent.shouldTriggerOn(patchsetCreated));
}
}