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 de.smartics.ci.config.load;
17  
18  import static org.hamcrest.MatcherAssert.assertThat;
19  import static org.hamcrest.Matchers.equalTo;
20  import static org.hamcrest.Matchers.is;
21  import static org.junit.Assert.assertEquals;
22  
23  import org.jdom.Document;
24  import org.jdom.JDOMException;
25  import org.junit.Before;
26  import org.junit.Test;
27  
28  import de.smartics.ci.config.hudson.AbstractHudsonConfigHelper;
29  import de.smartics.ci.config.maven.MavenConfig;
30  import de.smartics.ci.config.test.JDomTestUtils;
31  import de.smartics.ci.config.test.MavenConfigBuilder;
32  import de.smartics.testdoc.annotations.Uut;
33  
34  /**
35   * Tests {@link MavenInfoApplier}.
36   */
37  public class MavenInfoApplierTest
38  {
39    // ********************************* Fields *********************************
40  
41    // --- constants ------------------------------------------------------------
42  
43    // --- members --------------------------------------------------------------
44  
45    @Uut
46    private MavenInfoApplier uut;
47  
48    private Document hudsonConfigXml;
49  
50    // ****************************** Inner Classes *****************************
51  
52    // ********************************* Methods ********************************
53  
54    // --- prepare --------------------------------------------------------------
55  
56    @Before
57    public void setUp()
58    {
59      final HudsonJobConfigurationLoaderConfig loaderConfig =
60          createLoaderConfig();
61  
62      final MavenConfig mavenConfig = MavenConfigBuilder.a().build();
63      final LoaderPlan plan = new LoaderPlan("testPlanId", mavenConfig);
64      uut = new MavenInfoApplier(loaderConfig, plan);
65  
66      hudsonConfigXml = AbstractHudsonConfigHelper.createDocument();
67    }
68  
69    // --- helper ---------------------------------------------------------------
70  
71    private static HudsonJobConfigurationLoaderConfig createLoaderConfig()
72    {
73      final HudsonJobConfigurationLoaderConfig.Builder builder =
74          new HudsonJobConfigurationLoaderConfig.Builder();
75      builder.withAddScmElementWithFullContent(true);
76      final HudsonJobConfigurationLoaderConfig loaderConfig = builder.build();
77      return loaderConfig;
78    }
79  
80    private static void runTest(final Document hudsonConfigXml,
81        final String expectedFile)
82    {
83      final String result = JDomTestUtils.toString(hudsonConfigXml);
84      final String expected =
85          JDomTestUtils.read(MavenInfoApplierTest.class, expectedFile);
86      assertEquals(expected, result);
87      assertThat(result, is(equalTo(expected)));
88    }
89  
90    // --- tests ----------------------------------------------------------------
91  
92    @Test
93    public void addsScmInfo() throws JDOMException
94    {
95      uut.addScmInfo(hudsonConfigXml);
96  
97      runTest(hudsonConfigXml, "010-addsScmInfo.xml");
98    }
99  
100   @Test
101   public void acceptsThatNoScmInfoIsProvided() throws JDOMException
102   {
103     final HudsonJobConfigurationLoaderConfig loaderConfig =
104         createLoaderConfig();
105     final MavenConfig mavenConfig = MavenConfigBuilder.aMinimal().build();
106     final LoaderPlan plan = new LoaderPlan("test", mavenConfig);
107     uut = new MavenInfoApplier(loaderConfig, plan);
108     uut.addScmInfo(hudsonConfigXml);
109 
110     runTest(hudsonConfigXml, "000-empty.xml");
111   }
112 
113   @Test
114   public void addsProjectInfo() throws JDOMException
115   {
116     uut.addProjectInfo(hudsonConfigXml);
117 
118     runTest(hudsonConfigXml, "011-addsProjectInfo.xml");
119   }
120 
121   @Test
122   public void addsProjectDescription() throws JDOMException
123   {
124     uut.addProjectDescription(hudsonConfigXml);
125 
126     runTest(hudsonConfigXml, "012-addsProjectDescription.xml");
127   }
128 }