1 /*
   2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8154119 8154262 8156077 8157987 8154261 8154817
  27  * @summary Test modules support in javadoc.
  28  * @author bpatel
  29  * @library ../lib
  30  * @modules jdk.javadoc/jdk.javadoc.internal.tool
  31  * @build JavadocTester
  32  * @run main TestModules
  33  */
  34 
  35 public class TestModules extends JavadocTester {
  36 
  37     public static void main(String... args) throws Exception {
  38         TestModules tester = new TestModules();
  39         tester.runTests();
  40     }
  41 
  42     @Test
  43     void test1() {
  44         javadoc("-d", "out", "-use",
  45                 "-modulesourcepath", testSrc,
  46                 "-addmods", "module1,module2",
  47                 "testpkgmdl1", "testpkgmdl2");
  48         checkExit(Exit.OK);
  49         testDescription(true);
  50         testNoDescription(false);
  51         testOverviewSummaryModules();
  52         testModuleLink();
  53         testModuleClickThroughLinks();
  54         testModuleClickThrough(true);
  55     }
  56 
  57     @Test
  58     void test2() {
  59         javadoc("-d", "out-html5", "-html5", "-use",
  60                 "-modulesourcepath", testSrc,
  61                 "-addmods", "module1,module2",
  62                 "testpkgmdl1", "testpkgmdl2");
  63         checkExit(Exit.OK);
  64         testHtml5Description(true);
  65         testHtml5NoDescription(false);
  66         testHtml5OverviewSummaryModules();
  67         testModuleLink();
  68         testModuleClickThroughLinks();
  69         testModuleClickThrough(true);
  70     }
  71 
  72     @Test
  73     void test3() {
  74         javadoc("-d", "out-nocomment", "-nocomment", "-use",
  75                 "-modulesourcepath", testSrc,
  76                 "-addmods", "module1,module2",
  77                 "testpkgmdl1", "testpkgmdl2");
  78         checkExit(Exit.OK);
  79         testDescription(false);
  80         testNoDescription(true);
  81         testModuleLink();
  82     }
  83 
  84     @Test
  85     void test4() {
  86         javadoc("-d", "out-html5-nocomment", "-nocomment", "-html5", "-use",
  87                 "-modulesourcepath", testSrc,
  88                 "-addmods", "module1,module2",
  89                 "testpkgmdl1", "testpkgmdl2");
  90         checkExit(Exit.OK);
  91         testHtml5Description(false);
  92         testHtml5NoDescription(true);
  93         testModuleLink();
  94     }
  95 
  96    @Test
  97     void test5() {
  98         javadoc("-d", "out-nomodule", "-use",
  99                 "-sourcepath", testSrc,
 100                 "testpkgnomodule", "testpkgnomodule1");
 101         checkExit(Exit.OK);
 102         testOverviewSummaryPackages();
 103         testModuleClickThrough(false);
 104     }
 105 
 106    @Test
 107     void test6() {
 108         javadoc("-d", "out-mdltags", "-author", "-version",
 109                 "-tag", "regular:a:Regular Tag:",
 110                 "-tag", "moduletag:s:Module Tag:",
 111                 "-modulesourcepath", testSrc,
 112                 "-addmods", "moduletags,module2",
 113                 "testpkgmdltags", "testpkgmdl2");
 114         checkExit(Exit.OK);
 115         testModuleTags();
 116     }
 117 
 118     @Test
 119     void test7() {
 120         javadoc("-d", "out-moduleSummary", "-use",
 121                 "-modulesourcepath", testSrc,
 122                 "-addmods", "module1,module2",
 123                 "testpkgmdl1", "testpkgmdl2", "testpkg2mdl2");
 124         checkExit(Exit.OK);
 125         testModuleSummary();
 126         testNegatedModuleSummary();
 127     }
 128 
 129    @Test
 130     void test8() {
 131         javadoc("-d", "out-html5-nomodule", "-html5", "-use",
 132                 "-sourcepath", testSrc,
 133                 "testpkgnomodule", "testpkgnomodule1");
 134         checkExit(Exit.OK);
 135         testHtml5OverviewSummaryPackages();
 136     }
 137 
 138     void testDescription(boolean found) {
 139         checkOutput("module1-summary.html", found,
 140                 "<!-- ============ MODULE DESCRIPTION =========== -->\n"
 141                 + "<a name=\"module.description\">\n"
 142                 + "<!--   -->\n"
 143                 + "</a>\n"
 144                 + "<div class=\"block\">This is a test description for the module1 module.</div>");
 145         checkOutput("module2-summary.html", found,
 146                 "<!-- ============ MODULE DESCRIPTION =========== -->\n"
 147                 + "<a name=\"module.description\">\n"
 148                 + "<!--   -->\n"
 149                 + "</a>\n"
 150                 + "<div class=\"block\">This is a test description for the module2 module.</div>");
 151     }
 152 
 153     void testNoDescription(boolean found) {
 154         checkOutput("module1-summary.html", found,
 155                 "<div class=\"contentContainer\">\n"
 156                 + "<ul class=\"blockList\">\n"
 157                 + "<li class=\"blockList\">\n"
 158                 + "<ul class=\"blockList\">\n"
 159                 + "<li class=\"blockList\">\n"
 160                 + "<!-- ============ MODULES SUMMARY =========== -->");
 161         checkOutput("module2-summary.html", found,
 162                 "<div class=\"contentContainer\">\n"
 163                 + "<ul class=\"blockList\">\n"
 164                 + "<li class=\"blockList\">\n"
 165                 + "<ul class=\"blockList\">\n"
 166                 + "<li class=\"blockList\">\n"
 167                 + "<!-- ============ MODULES SUMMARY =========== -->");
 168     }
 169 
 170     void testHtml5Description(boolean found) {
 171         checkOutput("module1-summary.html", found,
 172                 "<section role=\"region\">\n"
 173                 + "<!-- ============ MODULE DESCRIPTION =========== -->\n"
 174                 + "<a id=\"module.description\">\n"
 175                 + "<!--   -->\n"
 176                 + "</a>\n"
 177                 + "<div class=\"block\">This is a test description for the module1 module.</div>\n"
 178                 + "</section>");
 179         checkOutput("module2-summary.html", found,
 180                 "<section role=\"region\">\n"
 181                 + "<!-- ============ MODULE DESCRIPTION =========== -->\n"
 182                 + "<a id=\"module.description\">\n"
 183                 + "<!--   -->\n"
 184                 + "</a>\n"
 185                 + "<div class=\"block\">This is a test description for the module2 module.</div>\n"
 186                 + "</section>");
 187     }
 188 
 189     void testHtml5NoDescription(boolean found) {
 190         checkOutput("module1-summary.html", found,
 191                 "<div class=\"contentContainer\">\n"
 192                 + "<ul class=\"blockList\">\n"
 193                 + "<li class=\"blockList\">\n"
 194                 + "<ul class=\"blockList\">\n"
 195                 + "<li class=\"blockList\">\n"
 196                 + "<!-- ============ MODULES SUMMARY =========== -->");
 197         checkOutput("module2-summary.html", found,
 198                 "<div class=\"contentContainer\">\n"
 199                 + "<ul class=\"blockList\">\n"
 200                 + "<li class=\"blockList\">\n"
 201                 + "<ul class=\"blockList\">\n"
 202                 + "<li class=\"blockList\">\n"
 203                 + "<!-- ============ MODULES SUMMARY =========== -->");
 204     }
 205 
 206     void testModuleLink() {
 207         checkOutput("overview-summary.html", true,
 208                 "<li>Module</li>");
 209         checkOutput("module1-summary.html", true,
 210                 "<li class=\"navBarCell1Rev\">Module</li>");
 211         checkOutput("module2-summary.html", true,
 212                 "<li class=\"navBarCell1Rev\">Module</li>");
 213         checkOutput("testpkgmdl1/package-summary.html", true,
 214                 "<li><a href=\"../module1-summary.html\">Module</a></li>");
 215         checkOutput("testpkgmdl1/TestClassInModule1.html", true,
 216                 "<li><a href=\"../module1-summary.html\">Module</a></li>");
 217         checkOutput("testpkgmdl1/class-use/TestClassInModule1.html", true,
 218                 "<li><a href=\"../../module1-summary.html\">Module</a></li>");
 219         checkOutput("testpkgmdl2/package-summary.html", true,
 220                 "<li><a href=\"../module2-summary.html\">Module</a></li>");
 221         checkOutput("testpkgmdl2/TestClassInModule2.html", true,
 222                 "<li><a href=\"../module2-summary.html\">Module</a></li>");
 223         checkOutput("testpkgmdl2/class-use/TestClassInModule2.html", true,
 224                 "<li><a href=\"../../module2-summary.html\">Module</a></li>");
 225     }
 226 
 227     void testNoModuleLink() {
 228         checkOutput("testpkgnomodule/package-summary.html", true,
 229                 "<ul class=\"navList\" title=\"Navigation\">\n"
 230                 + "<li><a href=\"../testpkgnomodule/package-summary.html\">Package</a></li>");
 231         checkOutput("testpkgnomodule/TestClassNoModule.html", true,
 232                 "<ul class=\"navList\" title=\"Navigation\">\n"
 233                 + "<li><a href=\"../testpkgnomodule/package-summary.html\">Package</a></li>");
 234         checkOutput("testpkgnomodule/class-use/TestClassNoModule.html", true,
 235                 "<ul class=\"navList\" title=\"Navigation\">\n"
 236                 + "<li><a href=\"../../testpkgnomodule/package-summary.html\">Package</a></li>");
 237     }
 238 
 239     void testModuleTags() {
 240         checkOutput("moduletags-summary.html", true,
 241                 "Type Link: <a href=\"testpkgmdltags/TestClassInModuleTags.html\" title=\"class in "
 242                 + "testpkgmdltags\"><code>TestClassInModuleTags</code></a>.");
 243         checkOutput("moduletags-summary.html", true,
 244                 "Member Link: <a href=\"testpkgmdltags/TestClassInModuleTags.html#"
 245                 + "testMethod-java.lang.String-\"><code>testMethod(String)</code></a>.");
 246         checkOutput("moduletags-summary.html", true,
 247                 "Package Link: <a href=\"testpkgmdltags/package-summary.html\"><code>testpkgmdltags</code></a>.");
 248         checkOutput("moduletags-summary.html", true,
 249                 "<dt><span class=\"simpleTagLabel\">Since:</span></dt>\n"
 250                 + "<dd>JDK 9</dd>");
 251         checkOutput("moduletags-summary.html", true,
 252                 "<dt><span class=\"seeLabel\">See Also:</span></dt>\n"
 253                 + "<dd>\"Test see tag\", \n"
 254                 + "<a href=\"testpkgmdltags/TestClassInModuleTags.html\" title=\"class in testpkgmdltags\"><code>"
 255                 + "TestClassInModuleTags</code></a></dd>");
 256         checkOutput("moduletags-summary.html", true,
 257                 "<dt><span class=\"simpleTagLabel\">Regular Tag:</span></dt>\n"
 258                 + "<dd>Just a regular simple tag.</dd>");
 259         checkOutput("moduletags-summary.html", true,
 260                 "<dt><span class=\"simpleTagLabel\">Module Tag:</span></dt>\n"
 261                 + "<dd>Just a simple module tag.</dd>");
 262         checkOutput("moduletags-summary.html", true,
 263                 "<dt><span class=\"simpleTagLabel\">Version:</span></dt>\n"
 264                 + "<dd>1.0</dd>");
 265         checkOutput("moduletags-summary.html", true,
 266                 "<dt><span class=\"simpleTagLabel\">Author:</span></dt>\n"
 267                 + "<dd>Bhavesh Patel</dd>");
 268         checkOutput("testpkgmdltags/TestClassInModuleTags.html", false,
 269                 "<dt><span class=\"simpleTagLabel\">Module Tag:</span></dt>\n"
 270                 + "<dd>Just a simple module tag.</dd>");
 271     }
 272 
 273     void testOverviewSummaryModules() {
 274         checkOutput("overview-summary.html", true,
 275                 "<table class=\"overviewSummary\" summary=\"Module Summary table, listing modules, and an explanation\">\n"
 276                 + "<caption><span>Modules</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
 277                 + "<tr>\n"
 278                 + "<th class=\"colFirst\" scope=\"col\">Module</th>\n"
 279                 + "<th class=\"colLast\" scope=\"col\">Description</th>\n"
 280                 + "</tr>");
 281         checkOutput("overview-summary.html", false,
 282                 "<table class=\"overviewSummary\" summary=\"Packages table, listing packages, and an explanation\">\n"
 283                 + "<caption><span>Packages</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
 284                 + "<tr>\n"
 285                 + "<th class=\"colFirst\" scope=\"col\">Package</th>\n"
 286                 + "<th class=\"colLast\" scope=\"col\">Description</th>\n"
 287                 + "</tr>");
 288     }
 289 
 290     void testOverviewSummaryPackages() {
 291         checkOutput("overview-summary.html", false,
 292                 "<table class=\"overviewSummary\" summary=\"Module Summary table, listing modules, and an explanation\">\n"
 293                 + "<caption><span>Modules</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
 294                 + "<tr>\n"
 295                 + "<th class=\"colFirst\" scope=\"col\">Module</th>\n"
 296                 + "<th class=\"colLast\" scope=\"col\">Description</th>\n"
 297                 + "</tr>");
 298         checkOutput("overview-summary.html", true,
 299                 "<table class=\"overviewSummary\" summary=\"Packages table, listing packages, and an explanation\">\n"
 300                 + "<caption><span>Packages</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
 301                 + "<tr>\n"
 302                 + "<th class=\"colFirst\" scope=\"col\">Package</th>\n"
 303                 + "<th class=\"colLast\" scope=\"col\">Description</th>\n"
 304                 + "</tr>");
 305     }
 306 
 307     void testHtml5OverviewSummaryModules() {
 308         checkOutput("overview-summary.html", true,
 309                 "<table class=\"overviewSummary\">\n"
 310                 + "<caption><span>Modules</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
 311                 + "<tr>\n"
 312                 + "<th class=\"colFirst\" scope=\"col\">Module</th>\n"
 313                 + "<th class=\"colLast\" scope=\"col\">Description</th>\n"
 314                 + "</tr>");
 315         checkOutput("overview-summary.html", false,
 316                 "<table class=\"overviewSummary\">\n"
 317                 + "<caption><span>Packages</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
 318                 + "<tr>\n"
 319                 + "<th class=\"colFirst\" scope=\"col\">Package</th>\n"
 320                 + "<th class=\"colLast\" scope=\"col\">Description</th>\n"
 321                 + "</tr>");
 322     }
 323 
 324     void testHtml5OverviewSummaryPackages() {
 325         checkOutput("overview-summary.html", false,
 326                 "<table class=\"overviewSummary\">\n"
 327                 + "<caption><span>Modules</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
 328                 + "<tr>\n"
 329                 + "<th class=\"colFirst\" scope=\"col\">Module</th>\n"
 330                 + "<th class=\"colLast\" scope=\"col\">Description</th>\n"
 331                 + "</tr>");
 332         checkOutput("overview-summary.html", true,
 333                 "<table class=\"overviewSummary\">\n"
 334                 + "<caption><span>Packages</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
 335                 + "<tr>\n"
 336                 + "<th class=\"colFirst\" scope=\"col\">Package</th>\n"
 337                 + "<th class=\"colLast\" scope=\"col\">Description</th>\n"
 338                 + "</tr>");
 339     }
 340 
 341     void testModuleSummary() {
 342         checkOutput("module1-summary.html", true,
 343                 "<ul class=\"subNavList\">\n"
 344                 + "<li>Module:&nbsp;</li>\n"
 345                 + "<li><a href=\"#module.description\">Description</a>&nbsp;|&nbsp;<a "
 346                 + "href=\"#modules.summary\">Modules</a>&nbsp;|&nbsp;<a href=\"#packages.summary\">"
 347                 + "Packages</a>&nbsp;|&nbsp;Services</li>\n"
 348                 + "</ul>");
 349         checkOutput("module1-summary.html", true,
 350                 "<!-- ============ MODULES SUMMARY =========== -->\n"
 351                 + "<a name=\"modules.summary\">\n"
 352                 + "<!--   -->\n"
 353                 + "</a>");
 354         checkOutput("module1-summary.html", true,
 355                 "<tr class=\"altColor\">\n"
 356                 + "<td class=\"colFirst\"><a href=\"testpkgmdl1/package-summary.html\">testpkgmdl1</a></td>\n"
 357                 + "<td class=\"colSecond\">All Modules</td>\n"
 358                 + "<td class=\"colLast\">&nbsp;</td>\n"
 359                 + "</tr>");
 360         checkOutput("module1-summary.html", true,
 361                 "<!-- ============ PACKAGES SUMMARY =========== -->\n"
 362                 + "<a name=\"packages.summary\">\n"
 363                 + "<!--   -->\n"
 364                 + "</a>");
 365         checkOutput("module1-summary.html", true,
 366                 "<tr class=\"rowColor\">\n"
 367                 + "<td class=\"colFirst\"><a href=\"module2-summary.html\">module2</a></td>\n"
 368                 + "<td class=\"colLast\">\n"
 369                 + "<div class=\"block\">This is a test description for the module2 module.</div>\n"
 370                 + "</td>\n"
 371                 + "</tr>");
 372         checkOutput("module2-summary.html", true,
 373                 "<li><a href=\"#module.description\">Description</a>&nbsp;|&nbsp;<a "
 374                 + "href=\"#modules.summary\">Modules</a>&nbsp;|&nbsp;<a href=\"#packages.summary\">"
 375                 + "Packages</a>&nbsp;|&nbsp;<a href=\"#services.summary\">Services</a></li>");
 376         checkOutput("module2-summary.html", true,
 377                 "<!-- ============ MODULES SUMMARY =========== -->\n"
 378                 + "<a name=\"modules.summary\">\n"
 379                 + "<!--   -->\n"
 380                 + "</a>");
 381         checkOutput("module2-summary.html", true,
 382                 "<tr class=\"rowColor\">\n"
 383                 + "<td class=\"colFirst\">testpkg2mdl2</td>\n"
 384                 + "<td class=\"colSecond\">module1</td>\n"
 385                 + "<td class=\"colLast\">&nbsp;</td>\n"
 386                 + "</tr>");
 387         checkOutput("module2-summary.html", true,
 388                 "<!-- ============ PACKAGES SUMMARY =========== -->\n"
 389                 + "<a name=\"packages.summary\">\n"
 390                 + "<!--   -->\n"
 391                 + "</a>");
 392         checkOutput("module2-summary.html", true,
 393                 "<tr class=\"altColor\">\n"
 394                 + "<td class=\"colFirst\"><a href=\"java.base-summary.html\">java.base</a></td>\n"
 395                 + "<td class=\"colLast\">&nbsp;</td>\n"
 396                 + "</tr>");
 397         checkOutput("module2-summary.html", true,
 398                 "<!-- ============ SERVICES SUMMARY =========== -->\n"
 399                 + "<a name=\"services.summary\">\n"
 400                 + "<!--   -->\n"
 401                 + "</a>");
 402         checkOutput("module2-summary.html", true,
 403                 "<tr class=\"altColor\">\n"
 404                 + "<td class=\"colFirst\"><a href=\"testpkgmdl2/TestClassInModule2.html\" "
 405                 + "title=\"class in testpkgmdl2\">TestClassInModule2</a></td>\n"
 406                 + "<td class=\"colLast\">&nbsp;</td>\n"
 407                 + "</tr>");
 408         checkOutput("module2-summary.html", true,
 409                 "<tr class=\"altColor\">\n"
 410                 + "<td class=\"colFirst\">testpkg2mdl2.TestInterfaceInModule2<br>(<span "
 411                 + "class=\"implementationLabel\">Implementation:</span>&nbsp;<a "
 412                 + "href=\"testpkgmdl2/TestClassInModule2.html\" title=\"class in testpkgmdl2\">"
 413                 + "TestClassInModule2</a>)</td>\n"
 414                 + "<td class=\"colLast\">&nbsp;</td>\n"
 415                 + "</tr");
 416         checkOutput("module2-summary.html", true,
 417                 "<caption><span>Exported Packages</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
 418                 + "<tr>\n"
 419                 + "<th class=\"colFirst\" scope=\"col\">Package</th>\n"
 420                 + "<th scope=\"col\">Module</th>\n"
 421                 + "<th class=\"colLast\" scope=\"col\">Description</th>\n"
 422                 + "</tr>");
 423         checkOutput("module2-summary.html", true,
 424                 "<caption><span>Requires</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
 425                 + "<tr>\n"
 426                 + "<th class=\"colFirst\" scope=\"col\">Module</th>\n"
 427                 + "<th class=\"colLast\" scope=\"col\">Description</th>\n"
 428                 + "</tr>");
 429         checkOutput("module2-summary.html", true,
 430                 "<caption><span>Uses</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
 431                 + "<tr>\n"
 432                 + "<th class=\"colFirst\" scope=\"col\">Type</th>\n"
 433                 + "<th class=\"colLast\" scope=\"col\">Description</th>\n"
 434                 + "</tr>");
 435         checkOutput("module2-summary.html", true,
 436                 "<caption><span>Provides</span><span class=\"tabEnd\">&nbsp;</span></caption>\n"
 437                 + "<tr>\n"
 438                 + "<th class=\"colFirst\" scope=\"col\">Type</th>\n"
 439                 + "<th class=\"colLast\" scope=\"col\">Description</th>\n"
 440                 + "</tr>");
 441     }
 442 
 443     void testNegatedModuleSummary() {
 444         checkOutput("module1-summary.html", false,
 445                 "<!-- ============ SERVICES SUMMARY =========== -->\n"
 446                 + "<a name=\"services.summary\">\n"
 447                 + "<!--   -->\n"
 448                 + "</a>");
 449     }
 450 
 451      void testModuleClickThroughLinks() {
 452         checkOutput("module-overview-frame.html", true,
 453                 "<li><a href=\"module1-frame.html\" target=\"packageListFrame\" "
 454                 + "onclick=\"updateModuleFrame('module1-type-frame.html','module1-summary.html');"
 455                 + "\">module1</a></li>");
 456         checkOutput("module-overview-frame.html", true,
 457                 "<li><a href=\"module2-frame.html\" target=\"packageListFrame\" "
 458                 + "onclick=\"updateModuleFrame('module2-type-frame.html','module2-summary.html');"
 459                 + "\">module2</a></li>");
 460         checkOutput("script.js", true,
 461                  "function updateModuleFrame(pFrame, cFrame)\n"
 462                  + "{\n"
 463                  + "    top.packageFrame.location = pFrame;\n"
 464                  + "    top.classFrame.location = cFrame;\n"
 465                  + "}");
 466 }
 467 
 468      void testModuleClickThrough(boolean found) {
 469         checkFiles(found,
 470                 "module1-type-frame.html",
 471                 "module2-type-frame.html");
 472      }
 473 }