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.awt.Desktop; |
24 import jdk.jpackage.test.Test; |
25 import java.io.IOException; |
|
26 import java.nio.file.Files; |
|
27 import java.nio.file.Path; |
|
28 import java.util.Arrays; |
|
29 import jdk.jpackage.test.HelloApp; |
|
30 import jdk.jpackage.test.PackageTest; |
25 import jdk.jpackage.test.PackageTest; |
31 import jdk.jpackage.test.Test; |
26 import jdk.jpackage.test.FileAssociations; |
32 |
27 |
33 /** |
28 /** |
34 * Test --file-associations parameter. |
29 * Test --file-associations parameter. Output of the test should be |
35 * Output of the test should be fileassociationstest*.* installer. |
30 * fileassociationstest*.* installer. The output installer should provide the |
36 * The output installer should provide the same functionality as the default |
31 * same functionality as the default installer (see description of the default |
37 * installer (see description of the default installer in SimplePackageTest.java) |
32 * installer in SimplePackageTest.java) plus configure file associations. After |
38 * plus configure file associations. |
33 * installation files with ".jptest1" and ".jptest2" suffixes should be |
39 * After installation files with ".jptest1" suffix should be associated with |
34 * associated with the test app. |
40 * the test app. |
|
41 * |
35 * |
42 * Suggested test scenario is to create empty file with ".jptest1" suffix, |
36 * Suggested test scenario is to create empty file with ".jptest1" suffix, |
43 * double click on it and make sure that test application was launched in |
37 * double click on it and make sure that test application was launched in |
44 * response to double click event with the path to test .jptest1 file |
38 * response to double click event with the path to test .jptest1 file on the |
45 * on the commend line. |
39 * commend line. The same applies to ".jptest2" suffix. |
46 * |
40 * |
47 * On Linux use "echo > foo.jptest1" and not "touch foo.jptest1" to create |
41 * On Linux use "echo > foo.jptest1" and not "touch foo.jptest1" to create test |
48 * test file as empty files are always interpreted as plain text and will not |
42 * file as empty files are always interpreted as plain text and will not be |
49 * be opened with the test app. This is a known bug. |
43 * opened with the test app. This is a known bug. |
50 */ |
44 */ |
51 |
45 |
52 /* |
46 /* |
53 * @test |
47 * @test |
54 * @summary jpackage with --file-associations |
48 * @summary jpackage with --file-associations |
55 * @library ../helpers |
49 * @library ../helpers |
56 * @modules jdk.jpackage/jdk.jpackage.internal |
50 * @modules jdk.jpackage/jdk.jpackage.internal |
57 * @run main/othervm/timeout=360 -Xmx512m FileAssociationsTest |
51 * @run main/othervm/timeout=360 -Xmx512m FileAssociationsTest |
58 */ |
52 */ |
59 public class FileAssociationsTest { |
53 public class FileAssociationsTest { |
60 public static void main(String[] args) throws Exception { |
54 public static void main(String[] args) { |
61 new PackageTest().configureHelloApp() |
55 Test.run(args, () -> { |
62 .addInitializer(cmd -> { |
56 PackageTest packageTest = new PackageTest(); |
63 initFaPropsFile(); |
|
64 cmd.addArguments("--file-associations", FA_PROPS_FILE.toString()); |
|
65 }) |
|
66 .addInstallVerifier(cmd -> { |
|
67 Path testFile = null; |
|
68 try { |
|
69 testFile = Test.createTempFile("." + FA_SUFFIX); |
|
70 // Write something in test file. |
|
71 // On Ubuntu and Oracle Linux empty files are considered |
|
72 // plain text. Seems like a system bug. |
|
73 // |
|
74 // [asemenyu@spacewalk ~]$ rm gg.jptest1 |
|
75 // $ touch foo.jptest1 |
|
76 // $ xdg-mime query filetype foo.jptest1 |
|
77 // text/plain |
|
78 // $ echo > foo.jptest1 |
|
79 // $ xdg-mime query filetype foo.jptest1 |
|
80 // application/x-jpackage-jptest1 |
|
81 // |
|
82 Files.write(testFile, Arrays.asList("")); |
|
83 |
57 |
84 final Path appOutput = Path.of(HelloApp.OUTPUT_FILENAME); |
58 applyFileAssociations(packageTest, new FileAssociations("jptest1")); |
85 Files.deleteIfExists(appOutput); |
59 applyFileAssociations(packageTest, |
86 |
60 new FileAssociations("jptest2").setFilename("fa2")); |
87 Test.trace(String.format("Use desktop to open [%s] file", testFile)); |
61 packageTest.run(); |
88 Desktop.getDesktop().open(testFile.toFile()); |
62 }); |
89 Test.waitForFileCreated(appOutput, 7); |
|
90 |
|
91 // Wait a little bit after file has been created to |
|
92 // make sure there are no pending writes into it. |
|
93 Thread.sleep(3000); |
|
94 HelloApp.verifyOutputFile(appOutput, testFile.toString()); |
|
95 } catch (IOException | InterruptedException ex) { |
|
96 throw new RuntimeException(ex); |
|
97 } finally { |
|
98 if (testFile != null) { |
|
99 try { |
|
100 Files.deleteIfExists(testFile); |
|
101 } catch (IOException ex) { |
|
102 throw new RuntimeException(ex); |
|
103 } |
|
104 } |
|
105 } |
|
106 }) |
|
107 .run(); |
|
108 } |
63 } |
109 |
64 |
110 private static void initFaPropsFile() { |
65 private static void applyFileAssociations(PackageTest test, |
111 try { |
66 FileAssociations fa) { |
112 Files.write(FA_PROPS_FILE, Arrays.asList( |
67 test.addInitializer(cmd -> { |
113 "extension=" + FA_SUFFIX, |
68 fa.createFile(); |
114 "mime-type=application/x-jpackage-" + FA_SUFFIX, |
69 cmd.addArguments("--file-associations", fa.getPropertiesFile()); |
115 "description=jpackage test extention")); |
70 }).addHelloAppFileAssociationsVerifier(fa); |
116 } catch (IOException ex) { |
|
117 throw new RuntimeException(ex); |
|
118 } |
|
119 } |
71 } |
120 |
|
121 private final static String FA_SUFFIX = "jptest1"; |
|
122 private final static Path FA_PROPS_FILE = Test.workDir().resolve("fa.properties"); |
|
123 } |
72 } |