Path: blob/master/test/jdk/tools/jpackage/macosx/MacFileAssociationsTest.java
41149 views
/*1* Copyright (c) 2020, 2021, 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.List;25import java.util.Map;26import static java.util.Map.entry;27import jdk.jpackage.test.JPackageCommand;28import jdk.jpackage.test.TKit;29import jdk.jpackage.test.MacHelper;30import jdk.jpackage.test.MacHelper.PListWrapper;31import jdk.jpackage.test.Annotations.Test;3233/**34* Tests generation of app image with --file-associations and mac additional file35* association arguments. Test will verify that arguments correctly propagated to36* Info.plist.37*/3839/*40* @test41* @summary jpackage with --file-associations and mac specific file association args42* @library ../helpers43* @build jdk.jpackage.test.*44* @build MacFileAssociationsTest45* @modules jdk.jpackage/jdk.jpackage.internal46* @requires (os.family == "mac")47* @run main/othervm -Xmx512m jdk.jpackage.test.Main48* --jpt-run=MacFileAssociationsTest49*/50public class MacFileAssociationsTest {5152@Test53public static void test() throws Exception {54final Path propFile = TKit.workDir().resolve("fa.properties");55Map<String, String> map = Map.ofEntries(56entry("mime-type", "application/x-jpackage-foo"),57entry("extension", "foo"),58entry("description", "bar"),59entry("mac.CFBundleTypeRole", "Viewer"),60entry("mac.LSHandlerRank", "Default"),61entry("mac.NSDocumentClass", "SomeClass"),62entry("mac.LSTypeIsPackage", "true"),63entry("mac.LSSupportsOpeningDocumentsInPlace", "false"),64entry("mac.UISupportsDocumentBrowser", "false"),65entry("mac.NSExportableTypes", "public.png, public.jpg"),66entry("mac.UTTypeConformsTo", "public.image, public.data"));67TKit.createPropertiesFile(propFile, map);6869JPackageCommand cmd = JPackageCommand.helloAppImage();70cmd.addArguments("--file-associations", propFile);71cmd.executeAndAssertHelloAppImageCreated();7273Path appImage = cmd.outputBundle();74verifyPList(appImage);75}7677private static void checkStringValue(PListWrapper plist, String key, String value) {78String result = plist.queryValue(key);79TKit.assertEquals(value, result, String.format(80"Check value of %s plist key", key));81}8283private static void checkBoolValue(PListWrapper plist, String key, Boolean value) {84Boolean result = plist.queryBoolValue(key);85TKit.assertEquals(value.toString(), result.toString(), String.format(86"Check value of %s plist key", key));87}8889private static void checkArrayValue(PListWrapper plist, String key,90List<String> values) {91List<String> result = plist.queryArrayValue(key);92TKit.assertStringListEquals(values, result, String.format(93"Check value of %s plist key", key));94}9596private static void verifyPList(Path appImage) throws Exception {97PListWrapper plist = MacHelper.readPListFromAppImage(appImage);98checkStringValue(plist, "CFBundleTypeRole", "Viewer");99checkStringValue(plist, "LSHandlerRank", "Default");100checkStringValue(plist, "NSDocumentClass", "SomeClass");101102checkBoolValue(plist, "LSTypeIsPackage", true);103checkBoolValue(plist, "LSSupportsOpeningDocumentsInPlace", false);104checkBoolValue(plist, "UISupportsDocumentBrowser", false);105106checkArrayValue(plist, "NSExportableTypes", List.of("public.png",107"public.jpg"));108109checkArrayValue(plist, "UTTypeConformsTo", List.of("public.image",110"public.data"));111}112}113114115