1 /*
   2  * Copyright (c) 2018, 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 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 }