-
Notifications
You must be signed in to change notification settings - Fork 399
Expand file tree
/
Copy pathGlobalConfigSubmitTest.java
More file actions
100 lines (87 loc) · 3.54 KB
/
GlobalConfigSubmitTest.java
File metadata and controls
100 lines (87 loc) · 3.54 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
package com.cloudbees.jenkins;
import jenkins.model.Jenkins;
import org.htmlunit.html.HtmlForm;
import org.htmlunit.html.HtmlTextInput;
import org.jenkinsci.plugins.github.GitHubPlugin;
import org.jenkinsci.plugins.github.config.GitHubPluginConfig;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsSessionRule;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
/**
* Test Class for {@link GitHubPushTrigger}.
*
* @author Seiji Sogabe, Frank Genois
*/
public class GlobalConfigSubmitTest {
public static final String HOOK_URL_INPUT = "_.hookUrl";
@Rule
public JenkinsSessionRule sessions = new JenkinsSessionRule();
@Test
public void shouldBeAbleToParseAnEmptyConfig() throws Throwable {
sessions.then(r -> {
GitHubPluginConfig githubPluginConfig = GitHubPlugin.configuration();
assertThat("empty config by default", githubPluginConfig.getConfigs().isEmpty());
assertFalse("no override hook url by default", githubPluginConfig.isOverrideHookUrl());
assertEquals(
"uses default url by default",
getDefaultHookUrl(),
githubPluginConfig.getHookUrl().toString()
);
});
}
@Test
public void shouldBeAbleToSetCustomHook() throws Throwable {
sessions.then(r -> {
HtmlForm config = r.createWebClient().goTo("configure").getFormByName("config");
HtmlTextInput textbox = config.getInputByName(HOOK_URL_INPUT);
textbox.setText("http://jenkinsci.example.com/jenkins/github-webhook/");
r.submit(config);
assertEquals(
"global config page let us edit the webhook url",
"http://jenkinsci.example.com/jenkins/github-webhook/",
GitHubPlugin.configuration().getHookUrl().toString()
);
});
sessions.then(r -> {
assertEquals(
"webhook url still present after restart of Jenkins",
"http://jenkinsci.example.com/jenkins/github-webhook/",
GitHubPlugin.configuration().getHookUrl().toString()
);
});
}
@Test
public void shouldSetDefaultHookUrlWhenLeftEmpty() throws Throwable {
sessions.then(r -> {
HtmlForm config = r.createWebClient().goTo("configure").getFormByName("config");
HtmlTextInput textbox = config.getInputByName(HOOK_URL_INPUT);
textbox.setText("");
r.submit(config);
assertEquals(
"global config page let us edit the webhook url",
getDefaultHookUrl(),
GitHubPlugin.configuration().getHookUrl().toString()
);
});
}
@Test
public void shouldSetDefaultHookUrlWhenGivenMalformedUrl() throws Throwable {
sessions.then(r -> {
HtmlForm config = r.createWebClient().goTo("configure").getFormByName("config");
HtmlTextInput textbox = config.getInputByName(HOOK_URL_INPUT);
textbox.setText("I'm not a URL!");
r.submit(config);
assertEquals(
"global config page let us edit the webhook url",
getDefaultHookUrl(),
GitHubPlugin.configuration().getHookUrl().toString()
);
});
}
public String getDefaultHookUrl() {
return Jenkins.getInstance().getRootUrl() + "github-webhook/";
}
}