1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package test.de.smartics.ci.config.hudson;
17
18 import static org.junit.Assert.assertEquals;
19
20 import org.jdom.Document;
21 import org.jdom.JDOMException;
22 import org.junit.Test;
23
24 import de.smartics.ci.config.hudson.HudsonConfigScmElement;
25 import de.smartics.ci.config.hudson.ScmType;
26 import de.smartics.testdoc.annotations.Uut;
27
28
29
30
31 @Uut(type = HudsonConfigScmElement.class)
32 public class HudsonConfigScmElementTest extends
33 AbstractHudsonConfigHelperTestBase
34 {
35
36
37
38
39 private static final String SCM_SVN_URL =
40 "https://www.smartics.de/svn/public/trunk/test-project";
41
42
43
44
45
46
47
48
49
50
51
52 private void runTests(final String testResource, final String expectedResource)
53 throws JDOMException
54 {
55 final Document hudsonConfigXml = load(testResource);
56
57 final HudsonConfigScmElement uut =
58 new HudsonConfigScmElement(hudsonConfigXml);
59
60 uut.addScmConfig(ScmType.SVN, SCM_SVN_URL);
61
62 final Document hudsonConfig = uut.getHudsonConfig();
63
64 final String resultString = toString(hudsonConfig);
65 final String expected = read(expectedResource);
66 assertEquals(expected, resultString);
67 }
68
69
70
71 @Test
72 public void addsScmElementIfNoneIsPresent() throws JDOMException
73 {
74 runTests("hudson-config-no-scm-element.xml", "002-scm-element-with-structure-added.xml");
75 }
76
77 @Test
78 public void addsScmElementIfPresentWithoutUrl() throws JDOMException
79 {
80 runTests("hudson-config-with-scm-element-and-url.xml",
81 "001-scm-element-added.xml");
82 }
83
84 @Test
85 public void addsScmElementIfPresentWithUrl() throws JDOMException
86 {
87 runTests("hudson-config-with-scm-element-no-url.xml",
88 "002-scm-element-with-structure-added.xml");
89 }
90
91 @Test
92 public void addsScmElementIfPresentWithLocations() throws JDOMException
93 {
94 runTests("hudson-config-with-scm-element-and-locations.xml",
95 "001-scm-element-added.xml");
96 }
97 }