1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
36
37 public class MavenInfoApplierTest
38 {
39
40
41
42
43
44
45 @Uut
46 private MavenInfoApplier uut;
47
48 private Document hudsonConfigXml;
49
50
51
52
53
54
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
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
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 }