1 package org.apache.maven.model.inheritance;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.model.Model;
23 import org.apache.maven.model.building.SimpleProblemCollector;
24 import org.apache.maven.model.io.DefaultModelReader;
25 import org.apache.maven.model.io.DefaultModelWriter;
26 import org.apache.maven.model.io.ModelReader;
27 import org.apache.maven.model.io.ModelWriter;
28
29 import org.xmlunit.matchers.CompareMatcher;
30
31 import junit.framework.TestCase;
32
33 import java.io.File;
34 import java.io.IOException;
35
36 import static org.junit.Assert.assertThat;
37
38
39
40
41 public class DefaultInheritanceAssemblerTest
42 extends TestCase
43 {
44 private ModelReader reader;
45
46 private ModelWriter writer;
47
48 private InheritanceAssembler assembler;
49
50 @Override
51 protected void setUp()
52 throws Exception
53 {
54 super.setUp();
55
56 reader = new DefaultModelReader();
57 writer = new DefaultModelWriter();
58 assembler = new DefaultInheritanceAssembler();
59 }
60
61 private File getPom( String name )
62 {
63 return new File( "src/test/resources/poms/inheritance/" + name + ".xml" );
64 }
65
66 private Model getModel( String name )
67 throws IOException
68 {
69 return reader.read( getPom( name ), null );
70 }
71
72 public void testPluginConfiguration()
73 throws Exception
74 {
75 testInheritance( "plugin-configuration" );
76 }
77
78
79
80
81
82
83 public void testUrls()
84 throws Exception
85 {
86 testInheritance( "urls" );
87 }
88
89
90
91
92
93 public void testFlatUrls()
94 throws IOException
95 {
96 testInheritance( "flat-urls" );
97 }
98
99
100
101
102
103 public void testNoAppendUrls()
104 throws Exception
105 {
106 testInheritance( "no-append-urls" );
107 }
108
109
110
111
112
113 public void testNoAppendUrls2()
114 throws Exception
115 {
116 testInheritance( "no-append-urls2" );
117 }
118
119
120
121
122
123 public void testNoAppendUrls3()
124 throws Exception
125 {
126 testInheritance( "no-append-urls3" );
127 }
128
129
130
131
132
133
134
135 public void testFlatTrickyUrls()
136 throws IOException
137 {
138
139
140 try
141 {
142
143 testInheritance( "tricky-flat-artifactId-urls", false );
144
145 }
146 catch ( AssertionError afe )
147 {
148
149 assertTrue( afe.getMessage(),
150 afe.getMessage().contains(
151 "Expected text value 'http://www.apache.org/path/to/parent/child-artifact-id/' but was " +
152 "'http://www.apache.org/path/to/parent/../child-artifact-id/'" ) );
153 }
154
155 testInheritance( "tricky-flat-artifactId-urls", true );
156
157
158
159 testInheritance( "tricky-flat-directory-urls", false );
160 try
161 {
162 testInheritance( "tricky-flat-directory-urls", true );
163 fail( "should have failed since module reference == directory name != artifactId" );
164 }
165 catch ( AssertionError afe )
166 {
167
168 assertTrue( afe.getMessage(), afe.getMessage().contains(
169 "Expected text value 'http://www.apache.org/path/to/parent/../child-artifact-id/' but was " +
170 "'http://www.apache.org/path/to/parent/child-artifact-id/'" ) );
171 }
172 }
173
174 public void testWithEmptyUrl()
175 throws IOException
176 {
177 testInheritance( "empty-urls", false );
178 }
179
180 public void testInheritance( String baseName )
181 throws IOException
182 {
183 testInheritance( baseName, false );
184 testInheritance( baseName, true );
185 }
186
187 public void testInheritance( String baseName, boolean fromRepo )
188 throws IOException
189 {
190 Model parent = getModel( baseName + "-parent" );
191
192 Model child = getModel( baseName + "-child" );
193
194 if ( fromRepo )
195 {
196
197
198 parent.setPomFile( null );
199 child.setPomFile( null );
200 }
201
202 SimpleProblemCollector problems = new SimpleProblemCollector();
203
204 assembler.assembleModelInheritance( child, parent, null, problems );
205
206
207 File actual = new File( "target/test-classes/poms/inheritance/" + baseName
208 + ( fromRepo ? "-build" : "-repo" ) + "-actual.xml" );
209 writer.write( actual, null, child );
210
211
212 File expected = getPom( baseName + "-expected" );
213
214 assertThat( actual, CompareMatcher.isIdenticalTo( expected ).ignoreComments().ignoreWhitespace() );
215 }
216
217 public void testModulePathNotArtifactId()
218 throws IOException
219 {
220 Model parent = getModel( "module-path-not-artifactId-parent" );
221
222 Model child = getModel( "module-path-not-artifactId-child" );
223
224 SimpleProblemCollector problems = new SimpleProblemCollector();
225
226 assembler.assembleModelInheritance( child, parent, null, problems );
227
228 File actual = new File( "target/test-classes/poms/inheritance/module-path-not-artifactId-actual.xml" );
229
230 writer.write( actual, null, child );
231
232
233 File expected = getPom( "module-path-not-artifactId-expected" );
234
235 assertThat( actual, CompareMatcher.isIdenticalTo(expected).ignoreComments().ignoreWhitespace() );
236 }
237 }