1 package org.apache.maven.plugin.javadoc;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.BufferedReader;
23 import java.io.File;
24 import java.io.FileReader;
25 import java.io.IOException;
26 import java.io.Reader;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30
31 import org.apache.commons.lang.SystemUtils;
32 import org.apache.maven.plugin.MojoExecutionException;
33 import org.apache.maven.plugin.javadoc.ProxyServer.AuthAsyncProxyServlet;
34 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
35 import org.apache.maven.settings.Proxy;
36 import org.apache.maven.settings.Settings;
37 import org.codehaus.plexus.util.FileUtils;
38 import org.codehaus.plexus.util.IOUtil;
39 import org.codehaus.plexus.util.ReaderFactory;
40 import org.codehaus.plexus.util.StringUtils;
41
42
43
44
45
46
47
48 public class JavadocReportTest
49 extends AbstractMojoTestCase
50 {
51 private static final char LINE_SEPARATOR = ' ';
52
53
54 private static boolean TEST_REPO_CREATED = false;
55
56 private File unit;
57
58
59 protected void setUp()
60 throws Exception
61 {
62 super.setUp();
63
64 unit = new File( getBasedir(), "src/test/resources/unit" );
65
66 createTestRepo();
67 }
68
69
70
71
72
73
74 private void createTestRepo()
75 throws IOException
76 {
77 if ( TEST_REPO_CREATED )
78 {
79 return;
80 }
81
82 File localRepo = new File( getBasedir(), "target/local-repo/" );
83 localRepo.mkdirs();
84
85
86
87
88
89 File sourceDir = new File( unit, "doclet-test/artifact-doclet" );
90 assertTrue( sourceDir.exists() );
91 FileUtils.copyDirectoryStructure( sourceDir, localRepo );
92
93
94
95
96
97 sourceDir = new File( unit, "doclet-path-test/artifact-doclet" );
98 assertTrue( sourceDir.exists() );
99 FileUtils.copyDirectoryStructure( sourceDir, localRepo );
100
101
102
103
104
105
106 sourceDir = new File( unit, "taglet-test/artifact-taglet" );
107 assertTrue( sourceDir.exists() );
108 FileUtils.copyDirectoryStructure( sourceDir, localRepo );
109
110
111
112
113
114 sourceDir = new File( unit, "stylesheetfile-test/artifact-stylesheetfile" );
115 assertTrue( sourceDir.exists() );
116 FileUtils.copyDirectoryStructure( sourceDir, localRepo );
117
118
119
120
121
122 sourceDir = new File( unit, "helpfile-test/artifact-helpfile" );
123 assertTrue( sourceDir.exists() );
124 FileUtils.copyDirectoryStructure( sourceDir, localRepo );
125
126
127 List<String> files =
128 FileUtils.getFileAndDirectoryNames( localRepo, FileUtils.getDefaultExcludesAsString(), null, true,
129 true, true, true );
130 for ( String filename : files )
131 {
132 File file = new File( filename );
133
134 if ( file.isDirectory() )
135 {
136 FileUtils.deleteDirectory( file );
137 }
138 else
139 {
140 file.delete();
141 }
142 }
143
144 TEST_REPO_CREATED = true;
145 }
146
147
148
149
150
151
152
153
154
155
156 private static String readFile( File file )
157 throws IOException
158 {
159 String strTmp;
160 StringBuffer str = new StringBuffer( (int) file.length() );
161 BufferedReader in = new BufferedReader( new FileReader( file ) );
162
163 try
164 {
165 while ( ( strTmp = in.readLine() ) != null )
166 {
167 str.append( LINE_SEPARATOR );
168 str.append( strTmp );
169 }
170 }
171 finally
172 {
173 in.close();
174 }
175
176 return str.toString();
177 }
178
179
180
181
182
183
184 public void testDefaultConfiguration()
185 throws Exception
186 {
187 File testPom = new File( unit, "default-configuration/default-configuration-plugin-config.xml" );
188 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
189 mojo.execute();
190
191
192 File apidocs = new File( getBasedir(), "target/test/unit/default-configuration/target/site/apidocs" );
193
194 File generatedFile = new File( apidocs, "def/configuration/App.html" );
195 assertTrue( generatedFile.exists() );
196 assertTrue( FileUtils.fileRead( generatedFile, "UTF-8" ).contains( "/docs/api/java/lang/Object.html" ) );
197
198 assertTrue( new File( apidocs, "def/configuration/AppSample.html" ).exists() );
199 assertTrue( new File( apidocs, "def/configuration/package-frame.html" ).exists() );
200 assertTrue( new File( apidocs, "def/configuration/package-summary.html" ).exists() );
201 assertTrue( new File( apidocs, "def/configuration/package-tree.html" ).exists() );
202 assertTrue( new File( apidocs, "def/configuration/package-use.html" ).exists() );
203
204
205 assertTrue( new File( apidocs, "def/configuration/class-use/App.html" ).exists() );
206 assertTrue( new File( apidocs, "def/configuration/class-use/AppSample.html" ).exists() );
207
208
209 assertTrue( new File( apidocs, "allclasses-frame.html" ).exists() );
210 assertTrue( new File( apidocs, "allclasses-noframe.html" ).exists() );
211 assertTrue( new File( apidocs, "constant-values.html" ).exists() );
212 assertTrue( new File( apidocs, "deprecated-list.html" ).exists() );
213 assertTrue( new File( apidocs, "help-doc.html" ).exists() );
214 assertTrue( new File( apidocs, "index-all.html" ).exists() );
215 assertTrue( new File( apidocs, "index.html" ).exists() );
216 assertTrue( new File( apidocs, "overview-tree.html" ).exists() );
217 assertTrue( new File( apidocs, "package-list" ).exists() );
218 assertTrue( new File( apidocs, "stylesheet.css" ).exists() );
219 }
220
221
222
223
224
225
226 public void testSubpackages()
227 throws Exception
228 {
229 File testPom = new File( unit, "subpackages-test/subpackages-test-plugin-config.xml" );
230 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
231 mojo.execute();
232
233 File apidocs = new File( getBasedir(), "target/test/unit/subpackages-test/target/site/apidocs" );
234
235
236 assertFalse( new File( apidocs, "subpackages/test/excluded" ).exists() );
237 assertFalse( new File( apidocs, "subpackages/test/included/exclude" ).exists() );
238
239
240 assertTrue( new File( apidocs, "subpackages/test/App.html" ).exists() );
241 assertTrue( new File( apidocs, "subpackages/test/AppSample.html" ).exists() );
242 assertTrue( new File( apidocs, "subpackages/test/included/IncludedApp.html" ).exists() );
243 assertTrue( new File( apidocs, "subpackages/test/included/IncludedAppSample.html" ).exists() );
244 }
245
246
247
248
249
250
251 public void testDocfiles()
252 throws Exception
253 {
254 File testPom = new File( unit, "docfiles-test/docfiles-test-plugin-config.xml" );
255 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
256 mojo.execute();
257
258 File apidocs = new File( getBasedir(), "target/test/unit/docfiles-test/target/site/apidocs/" );
259
260
261 assertTrue( new File( apidocs, "doc-files" ).exists() );
262 assertTrue( new File( apidocs, "doc-files/included-dir1/sample-included1.gif" ).exists() );
263 assertTrue( new File( apidocs, "doc-files/included-dir2/sample-included2.gif" ).exists() );
264 assertFalse( new File( apidocs, "doc-files/excluded-dir1" ).exists() );
265 assertFalse( new File( apidocs, "doc-files/excluded-dir2" ).exists() );
266
267 testPom = new File( unit, "docfiles-with-java-test/docfiles-with-java-test-plugin-config.xml" );
268 mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
269 mojo.execute();
270 }
271
272
273
274
275
276
277
278 public void testCustomConfiguration()
279 throws Exception
280 {
281 File testPom = new File( unit, "custom-configuration/custom-configuration-plugin-config.xml" );
282 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
283 mojo.execute();
284
285 File apidocs = new File( getBasedir(), "target/test/unit/custom-configuration/target/site/apidocs" );
286
287
288 assertFalse( new File( apidocs, "overview-tree.html" ).exists() );
289 assertFalse( new File( apidocs, "custom/configuration/package-tree.html" ).exists() );
290
291
292 assertFalse( new File( apidocs, "index-all.html" ).exists() );
293
294
295
296
297 assertFalse( new File( apidocs, "deprecated-list.html" ).exists() );
298 assertFalse( new File( apidocs, "custom/configuration/App.html" ).exists() );
299
300
301
302 String str = readFile( new File( apidocs, "custom/configuration/AppSample.html" ) );
303 assertFalse( str.toLowerCase().contains( "author" ) );
304
305
306 assertTrue( str.toUpperCase().contains( "SAMPLE BOTTOM CONTENT" ) );
307
308
309 assertTrue( str.toLowerCase().contains( "href=\"http://java.sun.com/j2se/1.4.2/docs/api/java/lang/string.html" ) );
310
311
312 assertTrue( str.toUpperCase().contains( "MAVEN JAVADOC PLUGIN TEST" ) );
313
314
315 assertTrue( str.toUpperCase().contains( "MAVEN JAVADOC PLUGIN TEST FOOTER" ) );
316
317
318 assertFalse( str.toUpperCase().contains( "/HELP-DOC.HTML" ) );
319
320
321 assertTrue( new File( apidocs, "custom/configuration/exclude1/Exclude1App.html" ).exists() );
322 assertFalse( new File( apidocs, "custom/configuration/exclude1/subexclude/SubexcludeApp.html" ).exists() );
323 assertFalse( new File( apidocs, "custom/configuration/exclude2/Exclude2App.html" ).exists() );
324
325 File options = new File( apidocs, "options" );
326 assertTrue( options.isFile() );
327 String contentOptions = null;
328 Reader reader = null;
329 try
330 {
331 reader = ReaderFactory.newPlatformReader( options );
332 contentOptions = IOUtil.toString( reader );
333 }
334 finally
335 {
336 IOUtil.close( reader );
337 }
338
339 assertTrue( contentOptions != null );
340 assertTrue( contentOptions.contains( "-link" ) );
341 assertTrue( contentOptions.contains( "http://java.sun.com/j2se/" ) );
342 }
343
344
345
346
347
348
349 public void testDoclets()
350 throws Exception
351 {
352
353
354
355
356
357 File testPom = new File( unit, "doclet-test/doclet-test-plugin-config.xml" );
358 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
359 mojo.execute();
360
361 File generatedFile = new File( getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot" );
362 assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
363
364 File optionsFile = new File( mojo.getOutputDirectory(), "options" );
365 assertTrue( optionsFile.exists() );
366 String options = readFile( optionsFile );
367 assertTrue( options.contains( "/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar" ) );
368
369
370
371
372
373
374 testPom = new File( unit, "doclet-path-test/doclet-path-test-plugin-config.xml" );
375 mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
376 mojo.execute();
377
378 generatedFile = new File( getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot" );
379 assertTrue( FileUtils.fileExists( generatedFile.getAbsolutePath() ) );
380
381 optionsFile = new File( mojo.getOutputDirectory(), "options" );
382 assertTrue( optionsFile.exists() );
383 options = readFile( optionsFile );
384 assertTrue( options.contains( "/target/local-repo/umlgraph/UMLGraph/2.1/UMLGraph-2.1.jar" ) );
385 assertTrue( options.contains( "/target/local-repo/umlgraph/UMLGraph-bis/2.1/UMLGraph-bis-2.1.jar" ) );
386 }
387
388
389
390
391
392
393 public void testAggregate()
394 throws Exception
395 {
396 File testPom = new File( unit, "aggregate-test/aggregate-test-plugin-config.xml" );
397 JavadocReport mojo = (JavadocReport) lookupMojo( "aggregate", testPom );
398 mojo.execute();
399
400 File apidocs = new File( getBasedir(), "target/test/unit/aggregate-test/target/site/apidocs/" );
401
402
403 assertTrue( new File( apidocs, "aggregate/test/project1/Project1App.html" ).exists() );
404 assertTrue( new File( apidocs, "aggregate/test/project1/Project1AppSample.html" ).exists() );
405 assertTrue( new File( apidocs, "aggregate/test/project1/Project1Sample.html" ).exists() );
406 assertTrue( new File( apidocs, "aggregate/test/project1/Project1Test.html" ).exists() );
407
408
409 assertTrue( new File( apidocs, "aggregate/test/project2/Project2App.html" ).exists() );
410 assertTrue( new File( apidocs, "aggregate/test/project2/Project2AppSample.html" ).exists() );
411 assertTrue( new File( apidocs, "aggregate/test/project2/Project2Sample.html" ).exists() );
412 assertTrue( new File( apidocs, "aggregate/test/project2/Project2Test.html" ).exists() );
413
414 }
415
416
417
418
419
420
421 public void testQuotedPath()
422 throws Exception
423 {
424 File testPom = new File( unit, "quotedpath'test/quotedpath-test-plugin-config.xml" );
425 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
426 mojo.execute();
427
428 File apidocs = new File( getBasedir(), "target/test/unit/quotedpath'test/target/site/apidocs" );
429
430
431 assertTrue( new File( apidocs, "quotedpath/test/App.html" ).exists() );
432 assertTrue( new File( apidocs, "quotedpath/test/AppSample.html" ).exists() );
433
434
435 assertTrue( new File( apidocs, "index-all.html" ).exists() );
436 assertTrue( new File( apidocs, "index.html" ).exists() );
437 assertTrue( new File( apidocs, "overview-tree.html" ).exists() );
438 assertTrue( new File( apidocs, "package-list" ).exists() );
439 assertTrue( new File( apidocs, "stylesheet.css" ).exists() );
440 }
441
442
443
444
445 public void testExceptions()
446 throws Exception
447 {
448 try
449 {
450 File testPom = new File( unit, "default-configuration/exception-test-plugin-config.xml" );
451 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
452 mojo.execute();
453
454 fail( "Must throw exception." );
455 }
456 catch ( Exception e )
457 {
458 assertTrue( true );
459
460 try
461 {
462 FileUtils.deleteDirectory( new File( getBasedir(), "exception" ) );
463 }
464 catch ( IOException ie )
465 {
466
467 }
468 }
469 }
470
471
472
473
474
475
476 public void testTaglets()
477 throws Exception
478 {
479
480
481
482
483 File testPom = new File( unit, "taglet-test/taglet-test-plugin-config.xml" );
484 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
485 mojo.execute();
486
487 File apidocs = new File( getBasedir(), "target/test/unit/taglet-test/target/site/apidocs" );
488
489 assertTrue( new File( apidocs, "index.html" ).exists() );
490
491 File appFile = new File( apidocs, "taglet/test/App.html" );
492 assertTrue( appFile.exists() );
493 String appString = readFile( appFile );
494 assertTrue( appString.contains( "<b>To Do:</b>" ) );
495 }
496
497
498
499
500
501
502 public void testJdk5()
503 throws Exception
504 {
505 if ( !SystemUtils.isJavaVersionAtLeast( 1.5f ) )
506 {
507 getContainer().getLogger().warn(
508 "JDK 5.0 or more is required to run javadoc for '"
509 + getClass().getName() + "#" + getName() + "()'." );
510 return;
511 }
512
513 File testPom = new File( unit, "jdk5-test/jdk5-test-plugin-config.xml" );
514 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
515 mojo.execute();
516
517 File apidocs = new File( getBasedir(), "target/test/unit/jdk5-test/target/site/apidocs" );
518
519 File index = new File( apidocs, "index.html" );
520 assertTrue( FileUtils.fileExists( index.getAbsolutePath() ) );
521
522 File overviewSummary = new File( apidocs, "overview-summary.html" );
523 assertTrue( overviewSummary.exists() );
524 String content = readFile( overviewSummary );
525 assertTrue( content.contains( "<b>Test the package-info</b>" ) );
526
527 File packageSummary = new File( apidocs, "jdk5/test/package-summary.html" );
528 assertTrue( packageSummary.exists() );
529 content = readFile( packageSummary );
530 assertTrue( content.contains( "<b>Test the package-info</b>" ) );
531 }
532
533
534
535
536
537
538
539 public void testToFindJavadoc()
540 throws Exception
541 {
542 String oldJreHome = System.getProperty( "java.home" );
543 System.setProperty( "java.home", "foo/bar" );
544
545 File testPom = new File( unit, "javaHome-test/javaHome-test-plugin-config.xml" );
546 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
547 mojo.execute();
548
549 System.setProperty( "java.home", oldJreHome );
550 }
551
552
553
554
555
556
557 public void testJavadocResources()
558 throws Exception
559 {
560 File testPom = new File( unit, "resources-test/resources-test-plugin-config.xml" );
561 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
562 mojo.execute();
563
564 File apidocs = new File( getBasedir(), "target/test/unit/resources-test/target/site/apidocs/" );
565
566 File app = new File( apidocs, "resources/test/App.html" );
567 assertTrue( app.exists() );
568 String content = readFile( app );
569 assertTrue( content.contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\"/>" ) );
570 assertTrue( new File( apidocs, "resources/test/doc-files/maven-feather.png" ).exists() );
571
572 File app2 = new File( apidocs, "resources/test2/App2.html" );
573 assertTrue( app2.exists() );
574 content = readFile( app2 );
575 assertTrue( content.contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\"/>" ) );
576 assertFalse( new File( apidocs, "resources/test2/doc-files/maven-feather.png" ).exists() );
577
578
579 testPom = new File( unit, "resources-with-excludes-test/resources-with-excludes-test-plugin-config.xml" );
580 mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
581 mojo.execute();
582
583 apidocs = new File( getBasedir(), "target/test/unit/resources-with-excludes-test/target/site/apidocs" );
584
585 app = new File( apidocs, "resources/test/App.html" );
586 assertTrue( app.exists() );
587 content = readFile( app );
588 assertTrue( content.contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\"/>" ) );
589 assertFalse( new File( apidocs, "resources/test/doc-files/maven-feather.png" ).exists() );
590
591 app2 = new File( apidocs, "resources/test2/App2.html" );
592 assertTrue( app2.exists() );
593 content = readFile( app2 );
594 assertTrue( content.contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\"/>" ) );
595 assertTrue( new File( apidocs, "resources/test2/doc-files/maven-feather.png" ).exists() );
596 }
597
598
599
600
601
602
603 public void testAggregateJavadocResources()
604 throws Exception
605 {
606 File testPom = new File( unit, "aggregate-resources-test/aggregate-resources-test-plugin-config.xml" );
607 JavadocReport mojo = (JavadocReport) lookupMojo( "aggregate", testPom );
608 mojo.execute();
609
610 File apidocs = new File( getBasedir(), "target/test/unit/aggregate-resources-test/target/site/apidocs" );
611
612
613 File overviewSummary = new File( apidocs, "overview-summary.html" );
614 assertTrue( overviewSummary.exists() );
615 String readed = readFile( overviewSummary );
616 assertTrue( readed.contains( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" + LINE_SEPARATOR
617 + "<TD WIDTH=\"20%\"><B><A HREF=\"resources/test/package-summary.html\">resources.test</A></B></TD>"
618 + LINE_SEPARATOR + "<TD>blabla</TD>" + LINE_SEPARATOR + "</TR>" ) );
619 assertTrue( readed.contains( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" + LINE_SEPARATOR
620 + "<TD WIDTH=\"20%\"><B><A HREF=\"resources/test2/package-summary.html\">resources.test2</A></B></TD>"
621 + LINE_SEPARATOR + "<TD> </TD>" + LINE_SEPARATOR + "</TR>" ) );
622 assertTrue( readed.contains( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" + LINE_SEPARATOR
623 + "<TD WIDTH=\"20%\"><B><A HREF=\"resources2/test/package-summary.html\">resources2.test</A></B></TD>"
624 + LINE_SEPARATOR + "<TD>blabla</TD>" + LINE_SEPARATOR + "</TR>" ) );
625 assertTrue( readed.contains( "<TR BGCOLOR=\"white\" CLASS=\"TableRowColor\">" + LINE_SEPARATOR
626 + "<TD WIDTH=\"20%\"><B><A HREF=\"resources2/test2/package-summary.html\">resources2.test2</A></B></TD>"
627 + LINE_SEPARATOR + "<TD> </TD>" + LINE_SEPARATOR + "</TR>" ) );
628
629
630 File app = new File( apidocs, "resources/test/App.html" );
631 assertTrue( app.exists() );
632 readed = readFile( app );
633 assertTrue( readed.contains( "<img src=\"doc-files/maven-feather.png\" alt=\"Maven\"/>" ) );
634 assertTrue( new File( apidocs, "resources/test/doc-files/maven-feather.png" ).exists() );
635 }
636
637
638
639
640
641
642 public void testPom()
643 throws Exception
644 {
645 File testPom = new File( unit, "pom-test/pom-test-plugin-config.xml" );
646 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
647 mojo.execute();
648
649 assertFalse( new File( getBasedir(), "target/test/unit/pom-test" ).exists() );
650 }
651
652
653
654
655
656
657 public void testTag()
658 throws Exception
659 {
660 File testPom = new File( unit, "tag-test/tag-test-plugin-config.xml" );
661 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
662 mojo.execute();
663
664 File app = new File( getBasedir(), "target/test/unit/tag-test/target/site/apidocs/tag/test/App.html" );
665 assertTrue( FileUtils.fileExists( app.getAbsolutePath() ) );
666 String readed = readFile( app );
667 assertTrue( readed.contains( "<B>To do something:</B>" ) );
668 assertTrue( readed.contains( "<B>Generator Class:</B>" ) );
669 assertTrue( readed.contains( "<B>Version:</B>" ) );
670 assertTrue( readed.contains( "<DT><B>Version:</B></DT>" + LINE_SEPARATOR + " <DD>1.0</DD>" + LINE_SEPARATOR
671 + "</DL>" ) );
672 }
673
674
675
676
677
678
679 public void testHeaderFooter()
680 throws Exception
681 {
682 File testPom = new File( unit, "header-footer-test/header-footer-test-plugin-config.xml" );
683 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
684 try
685 {
686 mojo.execute();
687 }
688 catch ( MojoExecutionException e )
689 {
690 assertTrue( "Doesnt handle correctly newline for header or footer parameter", false );
691 }
692
693 assertTrue( true );
694 }
695
696
697
698
699
700
701 public void testNewline()
702 throws Exception
703 {
704 File testPom = new File( unit, "newline-test/newline-test-plugin-config.xml" );
705 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
706 try
707 {
708 mojo.execute();
709 }
710 catch ( MojoExecutionException e )
711 {
712 fail( "Doesn't handle correctly newline for string parameters. See options and packages files." );
713 }
714
715 assertTrue( true );
716 }
717
718
719
720
721
722
723 public void testJdk6()
724 throws Exception
725 {
726 if ( !SystemUtils.isJavaVersionAtLeast( 1.6f ) )
727 {
728 getContainer().getLogger().warn(
729 "JDK 6.0 or more is required to run javadoc for '"
730 + getClass().getName() + "#" + getName() + "()'." );
731 return;
732 }
733
734 File testPom = new File( unit, "jdk6-test/jdk6-test-plugin-config.xml" );
735 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
736 mojo.execute();
737
738 File apidocs = new File( getBasedir(), "target/test/unit/jdk6-test/target/site/apidocs" );
739
740 assertTrue( new File( apidocs, "index.html" ).exists() );
741
742 File overviewSummary = new File( apidocs, "overview-summary.html" );
743 assertTrue( overviewSummary.exists() );
744 String content = readFile( overviewSummary );
745 assertTrue( content.contains( "Top - Copyright © All rights reserved." ) );
746 assertTrue( content.contains( "Header - Copyright © All rights reserved." ) );
747 assertTrue( content.contains( "Footer - Copyright © All rights reserved." ) );
748
749 File packageSummary = new File( apidocs, "jdk6/test/package-summary.html" );
750 assertTrue( packageSummary.exists() );
751 content = readFile( packageSummary );
752 assertTrue( content.contains( "Top - Copyright © All rights reserved." ) );
753 assertTrue( content.contains( "Header - Copyright © All rights reserved." ) );
754 assertTrue( content.contains( "Footer - Copyright © All rights reserved." ) );
755 }
756
757
758
759
760
761
762 public void testProxy()
763 throws Exception
764 {
765 Settings settings = new Settings();
766 Proxy proxy = new Proxy();
767
768
769 proxy.setActive( true );
770 proxy.setHost( "127.0.0.1" );
771 proxy.setPort( 80 );
772 proxy.setProtocol( "http" );
773 proxy.setUsername( "toto" );
774 proxy.setPassword( "toto" );
775 proxy.setNonProxyHosts( "www.google.com|*.somewhere.com" );
776 settings.addProxy( proxy );
777
778 File testPom = new File( getBasedir(), "src/test/resources/unit/proxy-test/proxy-test-plugin-config.xml" );
779 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
780 assertNotNull( mojo );
781 setVariableValueToObject( mojo, "settings", settings );
782 setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
783 mojo.execute();
784
785 File commandLine = new File( getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/javadoc." + ( SystemUtils.IS_OS_WINDOWS ? "bat" : "sh" ) );
786 assertTrue( FileUtils.fileExists( commandLine.getAbsolutePath() ) );
787 String readed = readFile( commandLine );
788 assertTrue( readed.contains( "-J-Dhttp.proxySet=true" ) );
789 assertTrue( readed.contains( "-J-Dhttp.proxyHost=127.0.0.1" ) );
790 assertTrue( readed.contains( "-J-Dhttp.proxyPort=80" ) );
791 assertTrue( readed.contains( "-J-Dhttp.proxyUser=\\\"toto\\\"" ) );
792 assertTrue( readed.contains( "-J-Dhttp.proxyPassword=\\\"toto\\\"" ) );
793 assertTrue( readed.contains( "-J-Dhttp.nonProxyHosts=\\\"www.google.com|*.somewhere.com\\\"" ) );
794
795 File options = new File( getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/options" );
796 assertTrue( FileUtils.fileExists( options.getAbsolutePath() ) );
797 String optionsContent = readFile( options );
798
799 assertFalse( optionsContent.contains( "-link" ) );
800
801
802 ProxyServer proxyServer = null;
803 AuthAsyncProxyServlet proxyServlet = null;
804 try
805 {
806 proxyServlet = new AuthAsyncProxyServlet();
807 proxyServer = new ProxyServer( proxyServlet );
808 proxyServer.start();
809
810 settings = new Settings();
811 proxy = new Proxy();
812 proxy.setActive( true );
813 proxy.setHost( proxyServer.getHostName() );
814 proxy.setPort( proxyServer.getPort() );
815 proxy.setProtocol( "http" );
816 settings.addProxy( proxy );
817
818 mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
819 setVariableValueToObject( mojo, "settings", settings );
820 setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
821 mojo.execute();
822 readed = readFile( commandLine );
823 assertTrue( readed.contains( "-J-Dhttp.proxySet=true" ) );
824 assertTrue( readed.contains( "-J-Dhttp.proxyHost=" + proxyServer.getHostName() ) );
825 assertTrue( readed.contains( "-J-Dhttp.proxyPort=" + proxyServer.getPort() ) );
826
827 optionsContent = readFile( options );
828
829
830
831
832
833
834
835
836
837
838 }
839 finally
840 {
841 if ( proxyServer != null )
842 {
843 proxyServer.stop();
844 }
845 }
846
847
848 Map<String, String> authentications = new HashMap<String, String>();
849 authentications.put( "foo", "bar" );
850 try
851 {
852 proxyServlet = new AuthAsyncProxyServlet( authentications );
853 proxyServer = new ProxyServer( proxyServlet );
854 proxyServer.start();
855
856 settings = new Settings();
857 proxy = new Proxy();
858 proxy.setActive( true );
859 proxy.setHost( proxyServer.getHostName() );
860 proxy.setPort( proxyServer.getPort() );
861 proxy.setProtocol( "http" );
862 proxy.setUsername( "foo" );
863 proxy.setPassword( "bar" );
864 settings.addProxy( proxy );
865
866 mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
867 setVariableValueToObject( mojo, "settings", settings );
868 setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
869 mojo.execute();
870 readed = readFile( commandLine );
871 assertTrue( readed.contains( "-J-Dhttp.proxySet=true" ) );
872 assertTrue( readed.contains( "-J-Dhttp.proxyHost=" + proxyServer.getHostName() ) );
873 assertTrue( readed.contains( "-J-Dhttp.proxyPort=" + proxyServer.getPort() ) );
874 assertTrue( readed.contains( "-J-Dhttp.proxyUser=\\\"foo\\\"" ) );
875 assertTrue( readed.contains( "-J-Dhttp.proxyPassword=\\\"bar\\\"" ) );
876
877 optionsContent = readFile( options );
878
879
880
881 }
882 finally
883 {
884 if ( proxyServer != null )
885 {
886 proxyServer.stop();
887 }
888 }
889 }
890
891
892
893
894
895
896 public void testValidateOptions()
897 throws Exception
898 {
899
900 File testPom = new File( unit, "validate-options-test/wrong-encoding-test-plugin-config.xml" );
901 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
902 try
903 {
904 mojo.execute();
905 assertTrue( "No wrong encoding catch", false );
906 }
907 catch ( MojoExecutionException e )
908 {
909 assertTrue( "No wrong encoding catch", e.getMessage().contains( "Unsupported option <encoding/>" ) );
910 }
911 testPom = new File( unit, "validate-options-test/wrong-docencoding-test-plugin-config.xml" );
912 mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
913 try
914 {
915 mojo.execute();
916 assertTrue( "No wrong docencoding catch", false );
917 }
918 catch ( MojoExecutionException e )
919 {
920 assertTrue( "No wrong docencoding catch", e.getMessage().contains( "Unsupported option <docencoding/>" ) );
921 }
922 testPom = new File( unit, "validate-options-test/wrong-charset-test-plugin-config.xml" );
923 mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
924 try
925 {
926 mojo.execute();
927 assertTrue( "No wrong charset catch", false );
928 }
929 catch ( MojoExecutionException e )
930 {
931 assertTrue( "No wrong charset catch", e.getMessage().contains( "Unsupported option <charset/>" ) );
932 }
933
934
935 testPom = new File( unit, "validate-options-test/wrong-locale-test-plugin-config.xml" );
936 mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
937 try
938 {
939 mojo.execute();
940 assertTrue( "No wrong locale catch", false );
941 }
942 catch ( MojoExecutionException e )
943 {
944 assertTrue( "No wrong locale catch", e.getMessage().contains( "Unsupported option <locale/>" ) );
945 }
946 testPom = new File( unit, "validate-options-test/wrong-locale-with-variant-test-plugin-config.xml" );
947 mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
948 mojo.execute();
949 assertTrue( "No wrong locale catch", true );
950
951
952 testPom = new File( unit, "validate-options-test/conflict-options-test-plugin-config.xml" );
953 mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
954 try
955 {
956 mojo.execute();
957 assertTrue( "No conflict catch", false );
958 }
959 catch ( MojoExecutionException e )
960 {
961 assertTrue( "No conflict catch", e.getMessage().contains( "Option <nohelp/> conflicts with <helpfile/>" ) );
962 }
963 }
964
965
966
967
968
969
970 public void testTagletArtifacts()
971 throws Exception
972 {
973 File testPom = new File( unit, "tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml" );
974 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
975
976 setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
977
978 mojo.execute();
979
980 File optionsFile = new File( mojo.getOutputDirectory(), "options" );
981 assertTrue( optionsFile.exists() );
982 String options = readFile( optionsFile );
983
984 assertEquals( 20, StringUtils.countMatches( options, LINE_SEPARATOR + "-taglet" + LINE_SEPARATOR ) );
985 assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet" ) );
986 assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet" ) );
987 assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet" ) );
988 assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet" ) );
989 assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet" ) );
990 assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet" ) );
991 assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet" ) );
992 assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet" ) );
993 assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet" ) );
994 assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet" ) );
995 assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet" ) );
996 assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet" ) );
997 assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet" ) );
998 assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet" ) );
999 assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet" ) );
1000 assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet" ) );
1001 assertTrue( options.contains( "org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet" ) );
1002 assertTrue( options.contains( "org.codehaus.plexus.javadoc.PlexusConfigurationTaglet" ) );
1003 assertTrue( options.contains( "org.codehaus.plexus.javadoc.PlexusRequirementTaglet" ) );
1004 assertTrue( options.contains( "org.codehaus.plexus.javadoc.PlexusComponentTaglet" ) );
1005 }
1006
1007
1008
1009
1010
1011
1012 public void testStylesheetfile()
1013 throws Exception
1014 {
1015 File testPom = new File( unit, "stylesheetfile-test/pom.xml" );
1016
1017 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
1018 assertNotNull( mojo );
1019
1020 setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
1021
1022 File apidocs = new File( getBasedir(), "target/test/unit/stylesheetfile-test/target/site/apidocs" );
1023
1024 File stylesheetfile = new File( apidocs, "stylesheet.css" );
1025 File options = new File( apidocs, "options" );
1026
1027
1028 setVariableValueToObject( mojo, "stylesheet", "javamaven" );
1029
1030 try
1031 {
1032 mojo.execute();
1033 assertTrue( false );
1034 }
1035 catch ( Exception e )
1036 {
1037 assertTrue( true );
1038 }
1039
1040
1041 setVariableValueToObject( mojo, "stylesheet", "java" );
1042 mojo.execute();
1043
1044 String content = readFile( stylesheetfile );
1045 assertTrue( content.contains( "/* Javadoc style sheet */" ) );
1046
1047 String optionsContent = readFile( options );
1048 assertFalse( optionsContent.contains( "-stylesheetfile" ) );
1049
1050
1051 setVariableValueToObject( mojo, "stylesheet", "maven" );
1052 mojo.execute();
1053
1054 content = readFile( stylesheetfile );
1055 assertTrue( content.contains( "/* Javadoc style sheet */" )
1056 && content.contains( "Licensed to the Apache Software Foundation (ASF) under one" ) );
1057
1058 optionsContent = readFile( options );
1059 assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1060 assertTrue( optionsContent.contains( "'" + stylesheetfile.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1061
1062
1063 setVariableValueToObject( mojo, "stylesheet", null );
1064 setVariableValueToObject( mojo, "stylesheetfile", "com/mycompany/app/javadoc/css/stylesheet.css" );
1065 mojo.execute();
1066
1067 content = readFile( stylesheetfile );
1068 assertTrue( content.contains( "/* Custom Javadoc style sheet in project */" ) );
1069
1070 optionsContent = readFile( options );
1071 assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1072 File stylesheetResource =
1073 new File( unit, "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css/stylesheet.css" );
1074 assertTrue( optionsContent.contains( "'" + stylesheetResource.getAbsolutePath().replaceAll( "\\\\", "/" )
1075 + "'" ) );
1076
1077
1078 setVariableValueToObject( mojo, "stylesheetfile", "com/mycompany/app/javadoc/css2/stylesheet.css" );
1079 mojo.execute();
1080
1081 content = readFile( stylesheetfile );
1082 assertTrue( content.contains( "/* Custom Javadoc style sheet in artefact */" ) );
1083
1084 optionsContent = readFile( options );
1085 assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1086 assertTrue( optionsContent.contains( "'" + stylesheetfile.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1087
1088
1089 File css =
1090 new File( unit, "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css" );
1091 setVariableValueToObject( mojo, "stylesheetfile", css.getAbsolutePath() );
1092 mojo.execute();
1093
1094 content = readFile( stylesheetfile );
1095 assertTrue( content.contains( "/* Custom Javadoc style sheet as file */" ) );
1096
1097 optionsContent = readFile( options );
1098 assertTrue( optionsContent.contains( "-stylesheetfile" ) );
1099 stylesheetResource =
1100 new File( unit, "stylesheetfile-test/src/main/resources/com/mycompany/app/javadoc/css3/stylesheet.css" );
1101 assertTrue( optionsContent.contains( "'" + stylesheetResource.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1102 }
1103
1104
1105
1106
1107
1108
1109 public void testHelpfile()
1110 throws Exception
1111 {
1112 File testPom = new File( unit, "helpfile-test/pom.xml" );
1113
1114 JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
1115 assertNotNull( mojo );
1116
1117 setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories() );
1118
1119 File apidocs = new File( getBasedir(), "target/test/unit/helpfile-test/target/site/apidocs" );
1120
1121 File helpfile = new File( apidocs, "help-doc.html" );
1122 File options = new File( apidocs, "options" );
1123
1124
1125 mojo.execute();
1126
1127 String content = readFile( helpfile );
1128 assertTrue( content.contains( "<!-- Generated by javadoc" ) );
1129
1130 String optionsContent = readFile( options );
1131 assertFalse( optionsContent.contains( "-helpfile" ) );
1132
1133
1134 setVariableValueToObject( mojo, "helpfile", "com/mycompany/app/javadoc/helpfile/help-doc.html" );
1135 mojo.execute();
1136
1137 content = readFile( helpfile );
1138 assertTrue( content.contains( "<!-- Help file from artefact -->" ) );
1139
1140 optionsContent = readFile( options );
1141 assertTrue( optionsContent.contains( "-helpfile" ) );
1142 File help = new File( apidocs, "help-doc.html" );
1143 assertTrue( optionsContent.contains( "'" + help.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1144
1145
1146 setVariableValueToObject( mojo, "helpfile", "com/mycompany/app/javadoc/helpfile2/help-doc.html" );
1147 mojo.execute();
1148
1149 content = readFile( helpfile );
1150 assertTrue( content.contains( "<!-- Help file from file -->" ) );
1151
1152 optionsContent = readFile( options );
1153 assertTrue( optionsContent.contains( "-helpfile" ) );
1154 help = new File( unit, "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html" );
1155 assertTrue( optionsContent.contains( "'" + help.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1156
1157
1158 help = new File( unit, "helpfile-test/src/main/resources/com/mycompany/app/javadoc/helpfile2/help-doc.html" );
1159 setVariableValueToObject( mojo, "helpfile", help.getAbsolutePath() );
1160 mojo.execute();
1161
1162 content = readFile( helpfile );
1163 assertTrue( content.contains( "<!-- Help file from file -->" ) );
1164
1165 optionsContent = readFile( options );
1166 assertTrue( optionsContent.contains( "-helpfile" ) );
1167 assertTrue( optionsContent.contains( "'" + help.getAbsolutePath().replaceAll( "\\\\", "/" ) + "'" ) );
1168 }
1169 }