Path: blob/master/test/jdk/tools/jpackage/share/FileAssociationsTest.java
41152 views
/*1* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.nio.file.Path;24import java.util.Map;25import java.util.List;26import jdk.jpackage.test.TKit;27import jdk.jpackage.test.PackageTest;28import jdk.jpackage.test.PackageType;29import jdk.jpackage.test.FileAssociations;30import jdk.jpackage.test.Annotations.Test;31import jdk.jpackage.test.Annotations.Parameter;3233/**34* Test --file-associations parameter. Output of the test should be35* fileassociationstest*.* installer. The output installer should provide the36* same functionality as the default installer (see description of the default37* installer in SimplePackageTest.java) plus configure file associations. After38* installation files with ".jptest1" and ".jptest2" suffixes should be39* associated with the test app.40*41* Suggested test scenario is to create empty file with ".jptest1" suffix,42* double click on it and make sure that test application was launched in43* response to double click event with the path to test .jptest1 file on the44* commend line. The same applies to ".jptest2" suffix.45*46* On Linux use "echo > foo.jptest1" and not "touch foo.jptest1" to create test47* file as empty files are always interpreted as plain text and will not be48* opened with the test app. This is a known bug.49*50* Icon associated with the main launcher should be associated with files with51* ".jptest1" suffix. Different icon should be associated with files with with52* ".jptest2" suffix. Icon for files with ".jptest1" suffix is platform specific53* and is one of 'icon.*' files in test/jdk/tools/jpackage/resources directory.54*/5556/*57* @test58* @summary jpackage with --file-associations59* @library ../helpers60* @key jpackagePlatformPackage61* @requires jpackage.test.SQETest == null62* @build jdk.jpackage.test.*63* @modules jdk.jpackage/jdk.jpackage.internal64* @compile FileAssociationsTest.java65* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main66* --jpt-run=FileAssociationsTest67*/6869/*70* @test71* @summary jpackage with --file-associations72* @library ../helpers73* @key jpackagePlatformPackage74* @requires jpackage.test.SQETest != null75* @build jdk.jpackage.test.*76* @modules jdk.jpackage/jdk.jpackage.internal77* @compile FileAssociationsTest.java78* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main79* --jpt-run=FileAssociationsTest.test80*/8182public class FileAssociationsTest {83@Test84@Parameter("true")85@Parameter("false")86public static void test(boolean includeDescription) {87PackageTest packageTest = new PackageTest();8889// Not supported90packageTest.excludeTypes(PackageType.MAC_DMG);9192FileAssociations fa = new FileAssociations("jptest1");93if (!includeDescription) {94fa.setDescription(null);95}96fa.applyTo(packageTest);9798Path icon = TKit.TEST_SRC_ROOT.resolve(Path.of("resources", "icon"99+ TKit.ICON_SUFFIX));100101icon = TKit.createRelativePathCopy(icon);102103new FileAssociations("jptest2")104.setFilename("fa2")105.setIcon(icon)106.applyTo(packageTest);107108packageTest.run();109}110111@Test112public static void testNoMime() {113final Path propFile = TKit.workDir().resolve("fa.properties");114115PackageTest packageTest = new PackageTest().excludeTypes(PackageType.MAC);116117packageTest.configureHelloApp().addRunOnceInitializer(() -> {118TKit.createPropertiesFile(propFile, Map.of(119"extension", "foo",120"description", "bar"121));122}).addInitializer(cmd -> {123cmd.addArguments("--file-associations", propFile).saveConsoleOutput(true);124}).setExpectedExitCode(1).addBundleVerifier((cmd, result) -> {125TKit.assertTextStream(126"No MIME types were specified for File Association number 1")127.apply(result.getOutput().stream());128TKit.assertTextStream(129"Advice to fix: Specify MIME type for File Association number 1")130.apply(result.getOutput().stream());131}).run();132}133134@Test135public static void testTooManyMimes() {136final Path propFile = TKit.workDir().resolve("fa.properties");137138PackageTest packageTest = new PackageTest().excludeTypes(PackageType.MAC);139140packageTest.configureHelloApp().addRunOnceInitializer(() -> {141TKit.createPropertiesFile(propFile, Map.of(142"mime-type", "application/x-jpackage-foo, application/x-jpackage-bar",143"extension", "foo",144"description", "bar"145));146}).addInitializer(cmd -> {147cmd.addArguments("--file-associations", propFile).saveConsoleOutput(true);148}).setExpectedExitCode(1).addBundleVerifier((cmd, result) -> {149TKit.assertTextStream(150"More than one MIME types was specified for File Association number 1")151.apply(result.getOutput().stream());152TKit.assertTextStream(153"Advice to fix: Specify only one MIME type for File Association number 1")154.apply(result.getOutput().stream());155}).run();156}157}158159160