-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathURLParameterTests.java
More file actions
113 lines (90 loc) · 3.55 KB
/
URLParameterTests.java
File metadata and controls
113 lines (90 loc) · 3.55 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
package hudson.plugins.URLSCM;
import java.util.HashMap;
import java.util.Set;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Tests for {@link URLParameter}
*/
public class URLParameterTests {
/**
* Tests an exception is thrown if the parameter name contains invalid characters
*/
@Test(expected = IllegalArgumentException.class)
public void shouldThrowIfParameterContainsInvalidCharacters() {
URLParameter p = new URLParameter("invalid!par ameter");
}
/**
* Tests a parameter substitutes itself in a parameterised string.
*/
@Test
public void shouldSubstituteParameter() {
URLParameter param = new URLParameter("host");
HashMap<String, String> parameters = new HashMap<String, String>();
parameters.put("host", "example");
String result = param.substitute("http://${host}.com/path", parameters);
assertEquals("http://example.com/path", result);
}
/**
* Tests a parameter does not try to substitute itself if the corresponding build parameter does not exist.
*/
@Test
public void shouldNotSubstituteIfParameterNotFound() {
URLParameter param = new URLParameter("test");
String parameterised = "http://example.com/${test}";
String result = param.substitute(parameterised, new HashMap<String, String>());
assertEquals(parameterised, result);
}
/**
* Tests build parameters are found in a parameterised string.
*/
@Test
public void shouldFindParameters() {
String url = "http://${host}.com/${testPath}";
Set<URLParameter> parameters = URLParameter.getParameters(url);
assertEquals(2, parameters.size());
}
/**
* Tests no parameters are found in a string without any valid parameters.
*/
@Test
public void shouldNotFindAnyParameters() {
String str = "String ${with no parameters!}${}";
Set<URLParameter> parameters = URLParameter.getParameters(str);
assertEquals(0, parameters.size());
}
/**
* Tests repeated parameters are only returned once.
*/
@Test
public void shouldNotDuplicateParameters() {
String parameterised = "${param} followed by ${param}";
Set<URLParameter> parameters = URLParameter.getParameters(parameterised);
assertEquals(1, parameters.size());
}
/**
* Tests all parameters are substituted into a parameterised string.
*/
@Test
public void shouldSubstituteAll() {
String parameterised = "http://${host}.com/${path1}/${path2}";
HashMap<String, String> buildParameters = new HashMap<String, String>();
buildParameters.put("host", "example");
buildParameters.put("path1", "first");
buildParameters.put("path2", "second");
String sub = URLParameter.substituteAll(parameterised, buildParameters);
assertEquals("http://example.com/first/second", sub);
}
/**
* Tests a parameterless string is not modified.
*/
@Test
public void shouldNotModifyUrlWithNoParameters() {
String unparameterised = "http://example.com/some/path/without/parameters";
HashMap<String, String> buildParameters = new HashMap<String, String>();
buildParameters.put("param1", "first");
buildParameters.put("param2", "second");
String sub = URLParameter.substituteAll(unparameterised, buildParameters);
assertEquals(unparameterised, sub);
}
}