test/jdk/tools/jpackage/linux/ShortcutHintTest.java
branchJDK-8200758-branch
changeset 58762 0fe62353385b
parent 58761 88e2753a2334
child 58888 d802578912f3
equal deleted inserted replaced
58761:88e2753a2334 58762:0fe62353385b
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    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
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
       
    24 import java.nio.charset.StandardCharsets;
       
    25 import java.nio.file.Files;
    24 import java.util.Map;
    26 import java.util.Map;
    25 import java.nio.file.Path;
    27 import java.nio.file.Path;
       
    28 import java.util.List;
       
    29 import java.util.stream.Collectors;
    26 import jdk.jpackage.test.FileAssociations;
    30 import jdk.jpackage.test.FileAssociations;
    27 import jdk.jpackage.test.PackageType;
    31 import jdk.jpackage.test.PackageType;
    28 import jdk.jpackage.test.PackageTest;
    32 import jdk.jpackage.test.PackageTest;
    29 import jdk.jpackage.test.TKit;
    33 import jdk.jpackage.test.TKit;
    30 import jdk.jpackage.test.Annotations.Test;
    34 import jdk.jpackage.test.Annotations.Test;
       
    35 import jdk.jpackage.test.*;
    31 
    36 
    32 /**
    37 /**
    33  * Test --linux-shortcut parameter. Output of the test should be
    38  * Test --linux-shortcut parameter. Output of the test should be
    34  * shortcuthinttest_1.0-1_amd64.deb or shortcuthinttest-1.0-1.amd64.rpm package
    39  * shortcuthinttest_1.0-1_amd64.deb or shortcuthinttest-1.0-1.amd64.rpm package
    35  * bundle. The output package should provide the same functionality as the
    40  * bundle. The output package should provide the same functionality as the
   137 
   142 
   138             TKit.createPropertiesFile(propsFile, Map.entry("icon",
   143             TKit.createPropertiesFile(propsFile, Map.entry("icon",
   139                     TKit.TEST_SRC_ROOT.resolve("apps/dukeplug.png").toString()));
   144                     TKit.TEST_SRC_ROOT.resolve("apps/dukeplug.png").toString()));
   140         }).run();
   145         }).run();
   141     }
   146     }
       
   147 
       
   148     /**
       
   149      * .desktop file from resource dir.
       
   150      */
       
   151     @Test
       
   152     public static void testDesktopFileFromResourceDir() {
       
   153         final String expectedVersionString = "Version=12345678";
       
   154         TKit.withTempDirectory("resources", tempDir -> {
       
   155             createTest().addInitializer(cmd -> {
       
   156                 cmd.setFakeRuntime();
       
   157 
       
   158                 cmd.addArgument("--linux-shortcut");
       
   159                 cmd.addArguments("--resource-dir", tempDir);
       
   160 
       
   161                 // Create custom .desktop file in resource directory
       
   162                 TKit.createTextFile(tempDir.resolve(cmd.name() + ".desktop"),
       
   163                         List.of(
       
   164                                 "[Desktop Entry]",
       
   165                                 "Name=APPLICATION_NAME",
       
   166                                 "Exec=APPLICATION_LAUNCHER",
       
   167                                 "Terminal=false",
       
   168                                 "Type=Application",
       
   169                                 "Categories=DEPLOY_BUNDLE_CATEGORY",
       
   170                                 expectedVersionString
       
   171                         ));
       
   172             })
       
   173             .addInstallVerifier(cmd -> {
       
   174                 Path desktopFile = cmd.appLayout().destktopIntegrationDirectory().resolve(
       
   175                         String.format("%s-%s.desktop",
       
   176                                 LinuxHelper.getPackageName(cmd), cmd.name()));
       
   177                 TKit.assertFileExists(desktopFile);
       
   178                 TKit.assertTextStream(expectedVersionString)
       
   179                         .label(String.format("[%s] file", desktopFile))
       
   180                         .predicate(String::equals)
       
   181                         .apply(Files.readAllLines(desktopFile).stream());
       
   182             }).run();
       
   183         });
       
   184     }
   142 }
   185 }