Path: blob/master/test/jdk/tools/jpackage/windows/WinInstallerUiTest.java
41149 views
/*1* Copyright (c) 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.ArrayList;25import jdk.jpackage.test.PackageTest;26import jdk.jpackage.test.JPackageCommand;27import jdk.jpackage.test.Annotations.Test;28import jdk.jpackage.test.Annotations.Parameters;29import java.util.List;30import jdk.jpackage.test.PackageType;31import jdk.jpackage.test.TKit;3233/**34* Test all possible combinations of --win-dir-chooser, --win-shortcut-prompt35* and --license parameters.36*/3738/*39* @test40* @summary jpackage with --win-dir-chooser, --win-shortcut-prompt and --license parameters41* @library ../helpers42* @key jpackagePlatformPackage43* @build jdk.jpackage.test.*44* @build WinInstallerUiTest45* @requires (os.family == "windows")46* @modules jdk.jpackage/jdk.jpackage.internal47* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main48* --jpt-run=WinInstallerUiTest49*/50public class WinInstallerUiTest {5152public WinInstallerUiTest(Boolean withDirChooser, Boolean withLicense,53Boolean withShortcutPrompt) {54this.withShortcutPrompt = withShortcutPrompt;55this.withDirChooser = withDirChooser;56this.withLicense = withLicense;57}5859@Parameters60public static List<Object[]> data() {61List<Object[]> data = new ArrayList<>();62for (var withDirChooser : List.of(Boolean.TRUE, Boolean.FALSE)) {63for (var withLicense : List.of(Boolean.TRUE, Boolean.FALSE)) {64for (var withShortcutPrompt : List.of(Boolean.TRUE, Boolean.FALSE)) {65if (!withDirChooser && !withLicense && !withShortcutPrompt) {66// Duplicates SimplePackageTest67continue;68}6970if (withDirChooser && !withLicense && !withShortcutPrompt) {71// Duplicates WinDirChooserTest72continue;73}7475if (!withDirChooser && withLicense && !withShortcutPrompt) {76// Duplicates LicenseTest77continue;78}7980data.add(new Object[]{withDirChooser, withLicense,81withShortcutPrompt});82}83}84}8586return data;87}8889@Test90public void test() {91PackageTest test = new PackageTest()92.forTypes(PackageType.WINDOWS)93.configureHelloApp();9495test.addInitializer(JPackageCommand::setFakeRuntime);96test.addInitializer(this::setPackageName);9798if (withDirChooser) {99test.addInitializer(cmd -> cmd.addArgument("--win-dir-chooser"));100}101102if (withShortcutPrompt) {103test.addInitializer(cmd -> {104cmd.addArgument("--win-shortcut-prompt");105cmd.addArgument("--win-menu");106cmd.addArgument("--win-shortcut");107});108}109110if (withLicense) {111test.addInitializer(cmd -> {112cmd.addArguments("--license-file", TKit.createRelativePathCopy(113TKit.TEST_SRC_ROOT.resolve(Path.of("resources",114"license.txt"))));115});116}117118test.run();119}120121private void setPackageName(JPackageCommand cmd) {122StringBuilder sb = new StringBuilder(cmd.name());123sb.append("With");124if (withDirChooser) {125sb.append("DirChooser");126}127if (withShortcutPrompt) {128sb.append("ShortcutPrompt");129}130if (withLicense) {131sb.append("License");132}133cmd.setArgumentValue("--name", sb.toString());134}135136private final boolean withDirChooser;137private final boolean withLicense;138private final boolean withShortcutPrompt;139}140141142