test/jdk/tools/jpackage/linux/ShortcutHintTest.java
branchJDK-8200758-branch
changeset 58301 e0efb29609bd
child 58416 f09bf58c1f17
equal deleted inserted replaced
58172:bf06a1d3aef6 58301:e0efb29609bd
       
     1 /*
       
     2  * Copyright (c) 2019, 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 import java.util.Map;
       
    25 import java.nio.file.Path;
       
    26 import jdk.jpackage.test.FileAssociations;
       
    27 import jdk.jpackage.test.PackageType;
       
    28 import jdk.jpackage.test.PackageTest;
       
    29 import jdk.jpackage.test.Test;
       
    30 
       
    31 /**
       
    32  * Test --linux-shortcut parameter. Output of the test should be
       
    33  * shortcuthinttest_1.0-1_amd64.deb or shortcuthinttest-1.0-1.amd64.rpm package
       
    34  * bundle. The output package should provide the same functionality as the
       
    35  * default package and also create a desktop shortcut.
       
    36  *
       
    37  * Finding a shortcut of the application launcher through GUI depends on desktop
       
    38  * environment.
       
    39  *
       
    40  * deb:
       
    41  * Search online for `Ways To Open A Ubuntu Application` for instructions.
       
    42  *
       
    43  * rpm:
       
    44  *
       
    45  */
       
    46 
       
    47 /*
       
    48  * @test
       
    49  * @summary jpackage with --linux-shortcut
       
    50  * @library ../helpers
       
    51  * @requires (os.family == "linux")
       
    52  * @modules jdk.jpackage/jdk.jpackage.internal
       
    53  * @run main/othervm/timeout=360 -Xmx512m ShortcutHintTest
       
    54  * @run main/othervm/timeout=360 -Xmx512m ShortcutHintTest testCustomIcon
       
    55  * @run main/othervm/timeout=360 -Xmx512m ShortcutHintTest testFileAssociations
       
    56  * @run main/othervm/timeout=360 -Xmx512m ShortcutHintTest testAdditionaltLaunchers
       
    57  */
       
    58 public class ShortcutHintTest {
       
    59 
       
    60     public static void main(String[] args) {
       
    61         Test.run(args, () -> {
       
    62             if (args.length != 0) {
       
    63                 Test.getTestClass().getDeclaredMethod(args[0]).invoke(null);
       
    64                 return;
       
    65             }
       
    66 
       
    67             createTest(null).addInitializer(cmd -> {
       
    68                 cmd.addArgument("--linux-shortcut");
       
    69             }).run();
       
    70         });
       
    71     }
       
    72 
       
    73     private static PackageTest createTest(String name) {
       
    74         PackageTest reply = new PackageTest()
       
    75                 .forTypes(PackageType.LINUX)
       
    76                 .configureHelloApp()
       
    77                 .addBundleDesktopIntegrationVerifier(true);
       
    78         if (name != null) {
       
    79             reply.addInitializer(cmd -> cmd.setArgumentValue("--name",
       
    80                     String.format("%s8%s", Test.getTestClass().getSimpleName(),
       
    81                             name)));
       
    82         }
       
    83         return reply;
       
    84     }
       
    85 
       
    86     /**
       
    87      * Adding `--icon` to jpackage command line should create desktop shortcut
       
    88      * even though `--linux-shortcut` is omitted.
       
    89      */
       
    90     static void testCustomIcon() {
       
    91         createTest(new Object() {
       
    92         }.getClass().getEnclosingMethod().getName()).addInitializer(cmd -> {
       
    93             cmd.setFakeRuntime();
       
    94             cmd.addArguments("--icon", Test.TEST_SRC_ROOT.resolve(
       
    95                     "apps/dukeplug.png"));
       
    96         }).run();
       
    97     }
       
    98 
       
    99     /**
       
   100      * Adding `--file-associations` to jpackage command line should create
       
   101      * desktop shortcut even though `--linux-shortcut` is omitted.
       
   102      */
       
   103     static void testFileAssociations() {
       
   104         createTest(new Object() {
       
   105         }.getClass().getEnclosingMethod().getName()).addInitializer(cmd -> {
       
   106             cmd.setFakeRuntime();
       
   107 
       
   108             FileAssociations fa = new FileAssociations(
       
   109                     "ShortcutHintTest_testFileAssociations");
       
   110             fa.createFile();
       
   111             cmd.addArguments("--file-associations", fa.getPropertiesFile());
       
   112         }).run();
       
   113     }
       
   114 
       
   115     /**
       
   116      * Additional launcher with icon should create desktop shortcut even though
       
   117      * `--linux-shortcut` is omitted.
       
   118      */
       
   119     static void testAdditionaltLaunchers() {
       
   120         createTest(new Object() {
       
   121         }.getClass().getEnclosingMethod().getName()).addInitializer(cmd -> {
       
   122             cmd.setFakeRuntime();
       
   123 
       
   124             final String launcherName = "Foo";
       
   125             final Path propsFile = Test.workDir().resolve(
       
   126                     launcherName + ".properties");
       
   127 
       
   128             cmd.addArguments("--add-launcher", String.format("%s=%s",
       
   129                     launcherName, propsFile));
       
   130 
       
   131             Test.createPropertiesFile(propsFile, Map.entry("icon",
       
   132                     Test.TEST_SRC_ROOT.resolve("apps/dukeplug.png").toString()));
       
   133         }).run();
       
   134     }
       
   135 }