1 /*
   2  * Copyright (c) 2017, 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 8185151
  27  * @summary test that navigation summary links are not linked when there are no dependencies
  28  * @modules jdk.compiler/com.sun.tools.javac.api
  29  *          jdk.compiler/com.sun.tools.javac.main
  30  *          jdk.javadoc/jdk.javadoc.internal.api
  31  *          jdk.javadoc/jdk.javadoc.internal.tool
  32  * @library ../lib /tools/lib
  33  * @build toolbox.ToolBox toolbox.ModuleBuilder JavadocTester
  34  * @run main TestModuleServicesLink
  35  */
  36 
  37 import java.nio.file.Path;
  38 import java.nio.file.Paths;
  39 
  40 import toolbox.*;
  41 
  42 public class TestModuleServicesLink extends JavadocTester {
  43 
  44     public final ToolBox tb;
  45     public static void main(String... args) throws Exception {
  46         TestModuleServicesLink  tester = new TestModuleServicesLink ();
  47         tester.runTests(m -> new Object[] { Paths.get(m.getName()) });
  48     }
  49 
  50     public TestModuleServicesLink () {
  51         tb = new ToolBox();
  52     }
  53 
  54     @Test
  55     public void checkNavbarWithServices1(Path base) throws Exception {
  56         ModuleBuilder mb = new ModuleBuilder(tb, "m")
  57                 .comment("module m.\n@uses p1.A")
  58                 .uses("p1.A")
  59                 .uses("p1.B")
  60                 .exports("p1")
  61                 .classes("package p1; public class A {}")
  62                 .classes("package p1; public class B {}");
  63         mb.write(base);
  64 
  65         javadoc("-d", base.toString() + "/out",
  66                 "-quiet",
  67                 "--module-source-path", base.toString(),
  68                 "--module", "m");
  69         checkExit(Exit.OK);
  70 
  71         checkOutput("m-summary.html", true,
  72                 "<a href=\"#module.description\">Description</a>&nbsp;|"
  73                 + "&nbsp;Modules&nbsp;|"
  74                 + "&nbsp;<a href=\"#packages.summary\">Packages</a>&nbsp;|"
  75                 + "&nbsp;<a href=\"#services.summary\">Services</a>");
  76 
  77     }
  78 
  79     @Test
  80     public void checkNavbarWithServices2(Path base) throws Exception {
  81         ModuleBuilder mb = new ModuleBuilder(tb, "m")
  82                         .comment("module m.\n@provides p1.A")
  83                         .provides("p1.A", "p1.B")
  84                         .exports("p1")
  85                         .classes("package p1; public interface A {}")
  86                         .classes("package p1; public class B implements A {}");
  87         mb.write(base);
  88 
  89         javadoc("-d", base.toString() + "/out",
  90                 "-quiet",
  91                 "--module-source-path", base.toString(),
  92                 "--module", "m");
  93         checkExit(Exit.OK);
  94 
  95         checkOutput("m-summary.html", true,
  96                 "<a href=\"#module.description\">Description</a>&nbsp;|"
  97                 + "&nbsp;Modules&nbsp;|"
  98                 + "&nbsp;<a href=\"#packages.summary\">Packages</a>&nbsp;|"
  99                 + "&nbsp;<a href=\"#services.summary\">Services</a>");
 100 
 101     }
 102 
 103     @Test
 104     public void checkNavbarWithoutServices(Path base) throws Exception {
 105         ModuleBuilder mb = new ModuleBuilder(tb, "m")
 106                 .exports("p1")
 107                 .classes("package p1; public class A {}")
 108                 .classes("package p1; public class B {}");
 109         mb.write(base);
 110 
 111         javadoc("-d", base.toString() + "/out",
 112                 "-quiet",
 113                 "--module-source-path", base.toString(),
 114                 "--module", "m");
 115         checkExit(Exit.OK);
 116 
 117         checkOutput("m-summary.html", true,
 118                 "Description&nbsp;|&nbsp;Modules&nbsp;|"
 119                 + "&nbsp;<a href=\"#packages.summary\">Packages</a>&nbsp;|"
 120                 + "&nbsp;Services");
 121     }
 122 
 123 }