1 package org.apache.maven.plugin.doap;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.FileReader;
24 import java.io.IOException;
25
26 import org.apache.maven.plugin.doap.options.DoapArtifact;
27 import org.apache.maven.plugin.doap.options.DoapOptions;
28 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
29 import org.apache.maven.project.MavenProject;
30 import org.codehaus.plexus.util.IOUtil;
31 import org.codehaus.plexus.util.StringUtils;
32
33
34
35
36
37
38
39 public class DoapMojoTest
40 extends AbstractMojoTestCase
41 {
42 @Override
43 protected void setUp()
44 throws Exception
45 {
46 super.setUp();
47 }
48
49 @Override
50 protected void tearDown()
51 throws Exception
52 {
53 super.tearDown();
54 }
55
56
57
58
59
60
61 public void testGeneratedDoap()
62 throws Exception
63 {
64 File pluginXmlFile =
65 new File( getBasedir(), "src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml" );
66 DoapMojo mojo = (DoapMojo) lookupMojo( "generate", pluginXmlFile );
67 assertNotNull( "Mojo found.", mojo );
68
69 MavenProject mavenProject = (MavenProject) getVariableValueFromObject( mojo, "project" );
70 assertNotNull( mavenProject );
71
72
73 setVariableValueToObject( mojo, "remoteRepositories", mavenProject.getRemoteArtifactRepositories() );
74 setVariableValueToObject( mojo, "about", mavenProject.getUrl() );
75
76 mojo.execute();
77
78 File doapFile = new File( getBasedir(), "target/test/unit/doap-configuration/doap-configuration.rdf" );
79 assertTrue( "Doap File was not generated!", doapFile.exists() );
80
81 String readed = readFile( doapFile );
82
83
84
85
86 assertTrue( readed.contains( "<rdf:RDF xml:lang=\"en\" xmlns=\"http://usefulinc.com/ns/doap#\" "
87 + "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" "
88 + "xmlns:foaf=\"http://xmlns.com/foaf/0.1/\">" ) );
89 assertTrue( readed.contains( "<Project rdf:about=\"" + mavenProject.getUrl() + "\">" ) );
90 assertTrue( readed.contains( "<description xml:lang=\"en\">Test the DOAP plugin</description>" ) );
91 assertTrue( readed.contains( "<shortdesc xml:lang=\"en\">Test the DOAP plugin</shortdesc>" ) );
92 assertTrue( readed.contains( "<homepage rdf:resource=\"" + mavenProject.getUrl() + "\"/>" ) );
93 assertTrue( readed.contains( "<category>library</category>" ) );
94 assertTrue( readed.contains( "<created>2008-01-01</created>" ) );
95 assertTrue( readed.contains( "<name>" + mavenProject.getName() + "</name>" ) );
96 assertTrue( readed.contains( "<download-page rdf:resource=\"http://foo.org/download.html\"/>" ) );
97 assertTrue( readed.contains( "<programming-language>Java</programming-language>" ) );
98 assertTrue( readed.contains( "<bug-database rdf:resource=\"http://jira.codehaus.org/browse/MDOAPTEST\"/>" ) );
99 assertTrue( readed.contains( "<license rdf:resource=\"http://www.apache.org/licenses/LICENSE-2.0.txt\"/>" ) );
100 assertTrue( readed.contains( "<SVNRepository>" ) );
101 assertTrue( readed.contains( "<location rdf:resource=\"http://svn.foo.org/repos/asf/maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/doap-configuration\"/>" ) );
102 assertTrue( readed.contains( "<browse rdf:resource=\"http://svn.foo.org/viewvc/maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/doap-configuration\"/>" ) );
103 assertTrue( readed.contains( "<location rdf:resource=\"https://svn.foo.org/repos/asf/maven/plugins/trunk/maven-doap-plugin/src/test/resources/unit/doap-configuration\"/>" ) );
104
105
106 assertTrue( readed.contains( "<audience>developers</audience>" ) );
107 assertTrue( readed.contains( "<blog rdf:resource=\"http://myblog.foo.org\"/>" ) );
108 assertTrue( readed.contains( "<implements>JSR-foo</implements>" ) );
109 assertTrue( readed.contains( "<language>en</language>" ) );
110 assertTrue( readed.contains( "<language>fr</language>" ) );
111 assertTrue( readed.contains( "<old-homepage rdf:resource=\"http://old.foo.org\"/>" ) );
112 assertTrue( readed.contains( "<os>windows</os>" ) );
113 assertTrue( readed.contains( "<os>linux</os>" ) );
114 assertTrue( readed.contains( "<os>mac</os>" ) );
115 assertTrue( readed.contains( "<platform>java</platform>" ) );
116 assertTrue( readed.contains( "<platform>firefox</platform>" ) );
117 assertTrue( readed.contains( "<screenshots rdf:resource=\"" + mavenProject.getUrl() +"/screenshots.html\"/>" ) );
118 assertTrue( readed.contains( "<service-endpoint rdf:resource=\"http://webservice.foo.org\"/>" ) );
119 assertTrue( readed.contains( "<wiki rdf:resource=\"http://wiki.foo.org\"/>" ) );
120
121
122 assertFalse( readed.contains( "<asfext:pmc rdf:resource=\"" + mavenProject.getUrl() + "\"/>" ) );
123 assertFalse( readed.contains( "<asfext:name>" + mavenProject.getName() + "</name>" ) );
124
125
126 assertTrue( readed.contains( "<maintainer>" ) );
127 assertTrue( readed.contains( "<foaf:Person rdf:nodeID=\"b1\">" ) );
128 assertTrue( readed.contains( "<foaf:name>Jane Doe</foaf:name>" ) );
129 assertTrue( readed.contains( "<foaf:Organization>" ) );
130 assertTrue( readed.contains( "<foaf:homepage rdf:resource=\"http://www.example.org\"/>" ) );
131 assertTrue( readed.contains( "<foaf:member rdf:nodeID=\"b1\"/>" ) );
132 }
133
134
135
136
137 public void testLangParameter()
138 throws Exception
139 {
140 File pluginXmlFile =
141 new File( getBasedir(), "src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml" );
142 DoapMojo mojo = (DoapMojo) lookupMojo( "generate", pluginXmlFile );
143 assertNotNull( "Mojo found.", mojo );
144
145 MavenProject mavenProject = (MavenProject) getVariableValueFromObject( mojo, "project" );
146 assertNotNull( mavenProject );
147
148
149 setVariableValueToObject( mojo, "remoteRepositories", mavenProject.getRemoteArtifactRepositories() );
150 setVariableValueToObject( mojo, "lang", "foo" );
151 try
152 {
153 mojo.execute();
154 assertTrue( "No lang checked", false );
155 }
156 catch ( Exception e )
157 {
158 assertTrue( true );
159 }
160 }
161
162
163
164
165 public void testAboutParameter()
166 throws Exception
167 {
168 File pluginXmlFile =
169 new File( getBasedir(), "src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml" );
170 DoapMojo mojo = (DoapMojo) lookupMojo( "generate", pluginXmlFile );
171 assertNotNull( "Mojo found.", mojo );
172
173 MavenProject mavenProject = (MavenProject) getVariableValueFromObject( mojo, "project" );
174 assertNotNull( mavenProject );
175
176
177 setVariableValueToObject( mojo, "remoteRepositories", mavenProject.getRemoteArtifactRepositories() );
178 setVariableValueToObject( mojo, "about", "foo" );
179 try
180 {
181 mojo.execute();
182 }
183 catch ( Exception e )
184 {
185 assertTrue( true );
186 }
187 }
188
189
190
191
192
193
194 public void testGeneratedDoapArtifact()
195 throws Exception
196 {
197 File pluginXmlFile =
198 new File( getBasedir(), "src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml" );
199 DoapMojo mojo = (DoapMojo) lookupMojo( "generate", pluginXmlFile );
200 assertNotNull( "Mojo found.", mojo );
201
202 MavenProject mavenProject = (MavenProject) getVariableValueFromObject( mojo, "project" );
203 assertNotNull( mavenProject );
204
205
206 setVariableValueToObject( mojo, "remoteRepositories", mavenProject.getRemoteArtifactRepositories() );
207 setVariableValueToObject( mojo, "about", mavenProject.getUrl() );
208 DoapOptions doapOptions = (DoapOptions)getVariableValueFromObject( mojo, "doapOptions" );
209 doapOptions.setDescription( "Common Utilities" );
210 doapOptions.setShortdesc( "Common Utilities" );
211 doapOptions.setDownloadPage( "http://plexus.codehaus.org/download-binaries.html" );
212 setVariableValueToObject( mojo, "doapOptions", doapOptions );
213
214 DoapArtifact artifact = new DoapArtifact();
215 artifact.setGroupId( "org.codehaus.plexus" );
216 artifact.setArtifactId( "plexus-utils" );
217 artifact.setVersion( "1.5.5" );
218 setVariableValueToObject( mojo, "artifact", artifact );
219 setVariableValueToObject( mojo, "outputDirectory", "target/test/unit/doap-configuration/" );
220
221 mojo.execute();
222
223 File doapFile = new File( getBasedir(), "target/test/unit/doap-configuration/doap_plexus-utils.rdf" );
224 assertTrue( "Doap File was not generated!", doapFile.exists() );
225
226 String readed = readFile( doapFile );
227
228
229
230
231 assertTrue( readed.contains( "<rdf:RDF xml:lang=\"en\" xmlns=\"http://usefulinc.com/ns/doap#\" "
232 + "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" "
233 + "xmlns:foaf=\"http://xmlns.com/foaf/0.1/\">" ) );
234 assertTrue( readed.contains( "<Project rdf:about=\"http://plexus.codehaus.org/plexus-utils\">" ) );
235 assertTrue( readed.contains( "<name>Plexus Common Utilities</name>" ) );
236 assertTrue( readed.contains( "<description xml:lang=\"en\">Common Utilities</description>" ) );
237 assertTrue( readed.contains( "<shortdesc xml:lang=\"en\">Common Utilities</shortdesc>" ) );
238 assertTrue( readed.contains( "<created>2001-01-01</created>" ) );
239 assertTrue( readed.contains( "<download-page rdf:resource=\"http://plexus.codehaus.org/download-binaries.html\"/>" ) );
240 assertTrue( readed.contains( "<programming-language>Java</programming-language>" ) );
241 assertTrue( readed.contains( "<bug-database rdf:resource=\"http://jira.codehaus.org/browse/PLXUTILS\"/>" ) );
242 assertTrue( readed.contains( "<license rdf:resource=\"http://www.apache.org/licenses/LICENSE-2.0.txt\"/>" ) );
243 assertTrue( readed.contains( "<SVNRepository>" ) );
244 assertTrue( readed.contains( "<location rdf:resource=\"http://svn.codehaus.org/plexus/plexus-utils/tags/plexus-utils-1.5.5\"/>" ) );
245 assertTrue( readed.contains( "<browse rdf:resource=\"http://fisheye.codehaus.org/browse/plexus/plexus-utils/tags/plexus-utils-1.5.5\"/>" ) );
246
247
248 assertTrue( readed.contains( "<audience>developers</audience>" ) );
249 assertTrue( readed.contains( "<blog rdf:resource=\"http://myblog.foo.org\"/>" ) );
250 assertTrue( readed.contains( "<implements>JSR-foo</implements>" ) );
251 assertTrue( readed.contains( "<language>en</language>" ) );
252 assertTrue( readed.contains( "<language>fr</language>" ) );
253 assertTrue( readed.contains( "<old-homepage rdf:resource=\"http://old.foo.org\"/>" ) );
254 assertTrue( readed.contains( "<os>windows</os>" ) );
255 assertTrue( readed.contains( "<os>linux</os>" ) );
256 assertTrue( readed.contains( "<os>mac</os>" ) );
257 assertTrue( readed.contains( "<platform>java</platform>" ) );
258 assertTrue( readed.contains( "<screenshots rdf:resource=\"http://plexus.codehaus.org/plexus-utils/screenshots.html\"/>" ) );
259 assertTrue( readed.contains( "<service-endpoint rdf:resource=\"http://webservice.foo.org\"/>" ) );
260 assertTrue( readed.contains( "<wiki rdf:resource=\"http://wiki.foo.org\"/>" ) );
261 }
262
263
264
265
266
267
268 public void testGeneratedDoapArtifactMinimalist()
269 throws Exception
270 {
271 File pluginXmlFile =
272 new File( getBasedir(), "src/test/resources/unit/doap-configuration/doap-configuration-plugin-config.xml" );
273 DoapMojo mojo = (DoapMojo) lookupMojo( "generate", pluginXmlFile );
274 assertNotNull( "Mojo found.", mojo );
275
276 MavenProject mavenProject = (MavenProject) getVariableValueFromObject( mojo, "project" );
277 assertNotNull( mavenProject );
278
279
280 setVariableValueToObject( mojo, "remoteRepositories", mavenProject.getRemoteArtifactRepositories() );
281 setVariableValueToObject( mojo, "about", "foo" );
282 DoapOptions doapOptions = new DoapOptions();
283 doapOptions.setName( "XStream" );
284 doapOptions.setDescription( "XStream is a simple library to serialize objects to XML and back again." );
285 doapOptions.setShortdesc( "XML Serializer" );
286 doapOptions.setHomepage( "http://xstream.codehaus.org/" );
287 doapOptions.setDownloadPage( "http://xstream.codehaus.org/download.html" );
288 doapOptions.setBugDatabase( "http://jira.codehaus.org/browse/XSTR" );
289 doapOptions.setLicense( "http://xstream.codehaus.org/license.html" );
290 doapOptions.setScmDeveloper( "http://svn.codehaus.org/xstream/trunk/xstream" );
291 doapOptions.setMailingList( "http://xstream.codehaus.org/list-user.html" );
292 doapOptions.setCreated( "2000-01-01");
293 setVariableValueToObject( mojo, "doapOptions", doapOptions );
294
295 DoapArtifact artifact = new DoapArtifact();
296 artifact.setGroupId( "xstream" );
297 artifact.setArtifactId( "xstream" );
298 artifact.setVersion( "1.1" );
299 setVariableValueToObject( mojo, "artifact", artifact );
300 setVariableValueToObject( mojo, "outputDirectory", "target/test/unit/doap-configuration/" );
301
302 mojo.execute();
303
304 File doapFile = new File( getBasedir(), "target/test/unit/doap-configuration/doap_xstream.rdf" );
305 assertTrue( "Doap File was not generated!", doapFile.exists() );
306
307 String readed = readFile( doapFile );
308
309
310
311
312 assertTrue( readed.contains( "<rdf:RDF xml:lang=\"en\" xmlns=\"http://usefulinc.com/ns/doap#\" "
313 + "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" "
314 + "xmlns:foaf=\"http://xmlns.com/foaf/0.1/\">" ) );
315 assertTrue( readed.contains( "<Project>" ) );
316 assertTrue( readed.contains( "<name>XStream</name>" ) );
317 assertTrue( readed.contains( "<description xml:lang=\"en\">XStream is a simple library to serialize objects to XML and back again.</description>" ) );
318 assertTrue( readed.contains( "<shortdesc xml:lang=\"en\">XML Serializer</shortdesc>" ) );
319 assertTrue( readed.contains( "<created>2000-01-01</created>" ) );
320 assertTrue( readed.contains( "<download-page rdf:resource=\"http://xstream.codehaus.org/download.html\"/>" ) );
321 assertTrue( readed.contains( "<programming-language>Java</programming-language>" ) );
322 assertTrue( readed.contains( "<bug-database rdf:resource=\"http://jira.codehaus.org/browse/XSTR\"/>" ) );
323 assertTrue( readed.contains( "<license rdf:resource=\"http://xstream.codehaus.org/license.html\"/>" ) );
324 assertTrue( readed.contains( "<Repository>" ) );
325 assertTrue( readed.contains( "<location rdf:resource=\"http://svn.codehaus.org/xstream/trunk/xstream\"/>" ) );
326 assertTrue( readed.contains( "<mailing-list rdf:resource=\"http://xstream.codehaus.org/list-user.html\"/>" ) );
327
328
329 assertFalse( readed.contains( "<audience>" ) );
330 assertFalse( readed.contains( "<blog rdf:resource=" ) );
331 assertFalse( readed.contains( "<implements>" ) );
332 assertFalse( readed.contains( "<language>" ) );
333 assertFalse( readed.contains( "<old-homepage rdf:resource=" ) );
334 assertFalse( readed.contains( "<os>" ) );
335 assertFalse( readed.contains( "<platform>" ) );
336 assertFalse( readed.contains( "<screenshots rdf:resource=" ) );
337 assertFalse( readed.contains( "<service-endpoint rdf:resource=" ) );
338 assertFalse( readed.contains( "<wiki rdf:resource=" ) );
339 }
340
341
342
343
344
345
346 public void testGeneratedDoapForASF()
347 throws Exception
348 {
349 File pluginXmlFile =
350 new File( getBasedir(),
351 "src/test/resources/unit/asf-doap-configuration/asf-doap-configuration-plugin-config.xml" );
352 DoapMojo mojo = (DoapMojo) lookupMojo( "generate", pluginXmlFile );
353 assertNotNull( "Mojo found.", mojo );
354
355 MavenProject mavenProject = (MavenProject) getVariableValueFromObject( mojo, "project" );
356 assertNotNull( mavenProject );
357
358
359 setVariableValueToObject( mojo, "remoteRepositories", mavenProject.getRemoteArtifactRepositories() );
360 setVariableValueToObject( mojo, "about", mavenProject.getUrl() );
361
362 mojo.execute();
363
364 File doapFile = new File( getBasedir(), "target/test/unit/asf-doap-configuration/asf-doap-configuration.rdf" );
365 assertTrue( "Doap File was not generated!", doapFile.exists() );
366
367 String readed = readFile( doapFile );
368
369
370
371
372 assertTrue( readed.contains( "<rdf:RDF xml:lang=\"en\" xmlns=\"http://usefulinc.com/ns/doap#\" "
373 + "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" "
374 + "xmlns:foaf=\"http://xmlns.com/foaf/0.1/\" " + "xmlns:asfext=\"http://projects.apache.org/ns/asfext#\">" ) );
375 if ( StringUtils.isNotEmpty( mavenProject.getUrl() ) )
376 {
377 assertTrue( readed.contains( "<Project rdf:about=\"" + mavenProject.getUrl() + "\">" ) );
378 assertTrue( readed.contains( "<homepage rdf:resource=\"" + mavenProject.getUrl() + "\"/>" ) );
379 }
380 assertTrue( readed.contains( "<name>Apache " + mavenProject.getName() + "</name>" ) );
381 assertTrue( readed.contains( "<programming-language>Java</programming-language>" ) );
382 assertTrue( readed.contains( "<category rdf:resource=\"http://projects.apache.org/category/library\"/>" ) );
383
384
385 assertTrue( readed.contains( "<asfext:pmc rdf:resource=\"" + mavenProject.getUrl() + "\"/>" ) );
386 assertTrue( readed.contains( "<asfext:name>Apache " + mavenProject.getName() + "</asfext:name>" ) );
387 assertTrue( readed.contains( "<asfext:charter>" ) );
388 assertTrue( readed.contains( "<asfext:chair>" ) );
389 }
390
391
392
393
394
395
396 public void testGeneratedExtraDoap()
397 throws Exception
398 {
399 File pluginXmlFile =
400 new File( getBasedir(),
401 "src/test/resources/unit/doap-configuration/doap-extra-configuration-plugin-config.xml" );
402 DoapMojo mojo = (DoapMojo) lookupMojo( "generate", pluginXmlFile );
403 assertNotNull( "Mojo found.", mojo );
404
405 MavenProject mavenProject = (MavenProject) getVariableValueFromObject( mojo, "project" );
406 assertNotNull( mavenProject );
407
408
409 setVariableValueToObject( mojo, "remoteRepositories", mavenProject.getRemoteArtifactRepositories() );
410 setVariableValueToObject( mojo, "about", mavenProject.getUrl() );
411
412 mojo.execute();
413
414 File doapFile = new File( getBasedir(), "target/test/unit/doap-configuration/doap-extra-configuration.rdf" );
415 assertTrue( "Doap File was not generated!", doapFile.exists() );
416
417 String readed = readFile( doapFile );
418
419 assertTrue( readed.contains( "<ciManagement rdf:resource=\"http://ci.foo.org\"/>" ) );
420 assertTrue( readed.contains( "<asfext:status>active</asfext:status>" ) );
421 assertTrue( readed.contains( "<labs:status>active</labs:status>" ) );
422 }
423
424
425
426
427
428
429 private String readFile( File file )
430 throws IOException
431 {
432 String result = null;
433
434 FileReader reader = null;
435 try
436 {
437
438 reader = new FileReader( file );
439
440 result = IOUtil.toString( reader );
441 }
442 finally
443 {
444 IOUtil.close( reader );
445 }
446
447 return result;
448 }
449 }