Path: blob/master/test/jdk/tools/jpackage/windows/WinUpgradeUUIDTest.java
41149 views
/*1* Copyright (c) 2019, 2020, 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.util.HashMap;24import java.util.List;25import java.util.Map;26import java.util.UUID;27import java.util.function.Supplier;28import jdk.jpackage.test.Annotations.Test;29import jdk.jpackage.test.PackageTest;30import jdk.jpackage.test.PackageType;31import jdk.jpackage.test.WindowsHelper;32import jdk.jpackage.test.TKit;3334/**35* Test both --win-upgrade-uuid and --app-version parameters. Output of the test36* should be WinUpgradeUUIDTest-1.0.exe and WinUpgradeUUIDTest-2.0.exe37* installers. Both output installers should provide the same functionality as38* the default installer (see description of the default installer in39* SimplePackageTest.java) but have the same product code and different40* versions. Running WinUpgradeUUIDTest-2.0.exe installer should automatically41* uninstall older version of the test application previously installed with42* WinUpgradeUUIDTest-1.0.exe installer.43*/4445/*46* @test47* @summary jpackage with --win-upgrade-uuid and --app-version48* @library ../helpers49* @key jpackagePlatformPackage50* @requires (jpackage.test.SQETest != null)51* @build jdk.jpackage.test.*52* @requires (os.family == "windows")53* @modules jdk.jpackage/jdk.jpackage.internal54* @compile WinUpgradeUUIDTest.java55* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main56* --jpt-run=WinUpgradeUUIDTest.test57*/5859/*60* @test61* @summary jpackage with --win-upgrade-uuid and --app-version62* @library ../helpers63* @key jpackagePlatformPackage64* @requires (jpackage.test.SQETest == null)65* @build jdk.jpackage.test.*66* @requires (os.family == "windows")67* @modules jdk.jpackage/jdk.jpackage.internal68* @compile WinUpgradeUUIDTest.java69* @run main/othervm/timeout=540 -Xmx512m jdk.jpackage.test.Main70* --jpt-run=WinUpgradeUUIDTest71*/7273public class WinUpgradeUUIDTest {7475@Test76public static void test() {77Supplier<PackageTest> init = () -> {78final UUID upgradeCode = UUID.fromString(79"F0B18E75-52AD-41A2-BC86-6BE4FCD50BEB");80return new PackageTest()81.forTypes(PackageType.WIN_MSI)82.addBundlePropertyVerifier("UpgradeCode", value -> {83if (value.startsWith("{")) {84value = value.substring(1);85}86if (value.endsWith("}")) {87value = value.substring(0, value.length() - 1);88}89return UUID.fromString(value).equals(upgradeCode);90}, "is a match with")91.forTypes(PackageType.WINDOWS)92.configureHelloApp()93.addInitializer(cmd -> cmd.addArguments("--win-upgrade-uuid",94upgradeCode.toString())) ;9596};9798// Replace real uninstall command for the first package with nop action.99// It will be uninstalled automatically when the second100// package will be installed.101// However uninstall verification for the first package will be executed.102PackageTest test1 = init.get().setPackageUninstaller(cmd -> {});103104PackageTest test2 = init.get().addInitializer(cmd -> {105cmd.setArgumentValue("--app-version", "2.0");106cmd.setArgumentValue("--arguments", "bar");107});108109new PackageTest.Group(test1, test2).run();110}111112/**113* Running jpackage multiple times with the same parameters should produce114* MSI packages with the same UpgradeCode and ProductCode values.115*/116@Test117public static void testUUIDs() {118Supplier<PackageTest> init = () -> {119return new PackageTest()120.forTypes(PackageType.WIN_MSI)121.configureHelloApp()122.addInitializer(cmd -> {123cmd.setFakeRuntime();124cmd.setArgumentValue("--dest", TKit.createTempDirectory("output"));125});126};127128PackageTest test1 = init.get();129PackageTest test2 = init.get();130PackageTest test3 = init.get().addInitializer(cmd -> {131cmd.addArguments("--app-version", "2.0");132});133PackageTest test4 = init.get().addInitializer(cmd -> {134cmd.addArguments("--app-version", "2.0");135cmd.addArguments("--vendor", "Foo Inc.");136});137138PackageTest[] tests = new PackageTest[] { test1, test2, test3, test4 };139140var productCodeVerifier = createPropertyVerifier("ProductCode", tests);141var upgradeCodeVerifier = createPropertyVerifier("UpgradeCode", tests);142143List.of(tests).forEach(test -> {144test.run(PackageTest.Action.CREATE);145});146147productCodeVerifier.assertEquals(test1, test2);148productCodeVerifier.assertNotEquals(test1, test3);149productCodeVerifier.assertNotEquals(test1, test4);150productCodeVerifier.assertNotEquals(test3, test4);151152upgradeCodeVerifier.assertEquals(test1, test2);153upgradeCodeVerifier.assertEquals(test1, test3);154upgradeCodeVerifier.assertNotEquals(test1, test4);155}156157private static PropertyVerifier createPropertyVerifier(String propertyName,158PackageTest... tests) {159Map<PackageTest, Map.Entry<String, String>> properties = new HashMap<>();160List.of(tests).forEach(test -> {161test.addBundleVerifier(cmd -> {162properties.put(test, Map.entry(cmd.getPrintableCommandLine(),163WindowsHelper.getMsiProperty(cmd, propertyName)));164});165});166167return new PropertyVerifier() {168@Override169protected String propertyName() {170return propertyName;171}172173@Override174protected Map<PackageTest, Map.Entry<String, String>> propertyValues() {175return properties;176}177};178}179180static abstract class PropertyVerifier {181void assertEquals(PackageTest x, PackageTest y) {182var entryX = propertyValues().get(x);183var entryY = propertyValues().get(y);184// if MsiBundler is not supported, these will be null185if (entryX != null && entryY != null) {186TKit.assertEquals(entryX.getValue(), entryY.getValue(),187String.format(188"Check %s is the same for %s and %s command lines",189propertyName(), entryX.getKey(), entryY.getKey()));190}191}192193void assertNotEquals(PackageTest x, PackageTest y) {194var entryX = propertyValues().get(x);195var entryY = propertyValues().get(y);196// if MsiBundler is not supported, these will be null197if (entryX != null && entryY != null) {198TKit.assertNotEquals(entryX.getValue(), entryY.getValue(),199String.format(200"Check %s is different for %s and %s command lines",201propertyName(), entryX.getKey(), entryY.getKey()));202}203}204205protected abstract String propertyName();206protected abstract Map<PackageTest, Map.Entry<String, String>> propertyValues();207}208}209210211