< prev index next >

test/jdk/tools/jpackage/share/FileAssociationsTest.java

Print this page




   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.awt.Desktop;
  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;
  31 import jdk.jpackage.test.Test;


  32 
  33 /**
  34  * Test --file-associations parameter.
  35  * Output of the test should be fileassociationstest*.* installer.
  36  * The output installer should provide the same functionality as the default
  37  * installer (see description of the default installer in SimplePackageTest.java)
  38  * plus configure file associations.
  39  * After installation files with ".jptest1" suffix should be associated with
  40  * the test app.
  41  *
  42  * 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
  44  * response to double click event with the path to test .jptest1 file
  45  * on the commend line.
  46  *
  47  * On Linux use "echo > foo.jptest1" and not "touch foo.jptest1" to create
  48  * test file as empty files are always interpreted as plain text and will not
  49  * be opened with the test app. This is a known bug.
  50  */
  51 
  52 /*
  53  * @test
  54  * @summary jpackage with --file-associations
  55  * @library ../helpers
  56  * @modules jdk.jpackage/jdk.jpackage.internal
  57  * @run main/othervm/timeout=360 -Xmx512m FileAssociationsTest
  58  */
  59 public class FileAssociationsTest {
  60     public static void main(String[] args) throws Exception {
  61         new PackageTest().configureHelloApp()
  62         .addInitializer(cmd -> {
  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 
  84                 final Path appOutput = Path.of(HelloApp.OUTPUT_FILENAME);
  85                 Files.deleteIfExists(appOutput);
  86 
  87                 Test.trace(String.format("Use desktop to open [%s] file", testFile));
  88                 Desktop.getDesktop().open(testFile.toFile());
  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     }
 109 
 110     private static void initFaPropsFile() {
 111         try {
 112             Files.write(FA_PROPS_FILE, Arrays.asList(
 113                 "extension=" + FA_SUFFIX,
 114                 "mime-type=application/x-jpackage-" + FA_SUFFIX,
 115                 "description=jpackage test extention"));
 116         } catch (IOException ex) {
 117             throw new RuntimeException(ex);
 118         }
 119     }
 120 
 121     private final static String FA_SUFFIX = "jptest1";
 122     private final static Path FA_PROPS_FILE = Test.workDir().resolve("fa.properties");
 123 }


   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 jdk.jpackage.test.Test;
  25 import jdk.jpackage.test.PackageTest;
  26 import jdk.jpackage.test.FileAssociations;
  27 
  28 /**
  29  * Test --file-associations parameter. Output of the test should be
  30  * fileassociationstest*.* installer. The output installer should provide the
  31  * same functionality as the default installer (see description of the default
  32  * installer in SimplePackageTest.java) plus configure file associations. After
  33  * installation files with ".jptest1" and ".jptest2" suffixes should be
  34  * associated with the test app.

  35  *
  36  * Suggested test scenario is to create empty file with ".jptest1" suffix,
  37  * double click on it and make sure that test application was launched in
  38  * response to double click event with the path to test .jptest1 file on the
  39  * commend line. The same applies to ".jptest2" suffix.
  40  *
  41  * On Linux use "echo > foo.jptest1" and not "touch foo.jptest1" to create test
  42  * file as empty files are always interpreted as plain text and will not be
  43  * opened with the test app. This is a known bug.
  44  */
  45 
  46 /*
  47  * @test
  48  * @summary jpackage with --file-associations
  49  * @library ../helpers
  50  * @modules jdk.jpackage/jdk.jpackage.internal
  51  * @run main/othervm/timeout=360 -Xmx512m FileAssociationsTest
  52  */
  53 public class FileAssociationsTest {
  54     public static void main(String[] args) {
  55         Test.run(args, () -> {
  56             PackageTest packageTest = new PackageTest();
  57 
  58             applyFileAssociations(packageTest, new FileAssociations("jptest1"));
  59             applyFileAssociations(packageTest,
  60                     new FileAssociations("jptest2").setFilename("fa2"));
  61             packageTest.run();
  62         });
  63     }
  64 
  65     private static void applyFileAssociations(PackageTest test,
  66             FileAssociations fa) {
  67         test.addInitializer(cmd -> {
  68             fa.createFile();
  69             cmd.addArguments("--file-associations", fa.getPropertiesFile());
  70         }).addHelloAppFileAssociationsVerifier(fa);



























  71     }


















  72 }
< prev index next >