View Javadoc

1   /*
2    * Copyright 2012 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Tests {@link HudsonConfigScmElement}.
30   */
31  @Uut(type = HudsonConfigScmElement.class)
32  public class HudsonConfigScmElementTest extends
33      AbstractHudsonConfigHelperTestBase
34  {
35    // ********************************* Fields *********************************
36  
37    // --- constants ------------------------------------------------------------
38  
39    private static final String SCM_SVN_URL =
40        "https://www.smartics.de/svn/public/trunk/test-project";
41  
42    // --- members --------------------------------------------------------------
43  
44    // ****************************** Inner Classes *****************************
45  
46    // ********************************* Methods ********************************
47  
48    // --- prepare --------------------------------------------------------------
49  
50    // --- helper ---------------------------------------------------------------
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    // --- tests ----------------------------------------------------------------
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"); // NOPMD
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  }