< prev index next >

test/jdk/tools/jpackage/windows/WinUpgradeUUIDTest.java

Print this page




   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.TKit;





  25 import jdk.jpackage.test.PackageTest;
  26 import jdk.jpackage.test.PackageType;


  27 
  28 /**
  29  * Test both --win-upgrade-uuid and --app-version parameters. Output of the test
  30  * should be WinUpgradeUUIDTest-1.0.exe and WinUpgradeUUIDTest-2.0.exe
  31  * installers. Both output installers should provide the same functionality as
  32  * the default installer (see description of the default installer in
  33  * SimplePackageTest.java) but have the same product code and different
  34  * versions. Running WinUpgradeUUIDTest-2.0.exe installer should automatically
  35  * uninstall older version of the test application previously installed with
  36  * WinUpgradeUUIDTest-1.0.exe installer.
  37  */
  38 
  39 /*
  40  * @test
  41  * @summary jpackage with --win-upgrade-uuid and --app-version
  42  * @library ../helpers
  43  * @key jpackagePlatformPackage

  44  * @build jdk.jpackage.test.*
  45  * @requires (os.family == "windows")
  46  * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal
  47  * @run main/othervm/timeout=360 -Xmx512m WinUpgradeUUIDTest
















  48  */
  49 
  50 public class WinUpgradeUUIDTest {
  51     public static void main(String[] args) {
  52         TKit.run(args, () -> {
  53             PackageTest test = init();
  54             if (test.getAction() != PackageTest.Action.VERIFY_INSTALL) {
  55                 test.run();













  56             }









  57 
  58             test = init();
  59             test.addInitializer(cmd -> {
  60                 cmd.setArgumentValue("--app-version", "2.0");
  61                 cmd.setArgumentValue("--arguments", "bar");
  62             });
  63             test.run();
  64         });
  65     }
  66 
  67     private static PackageTest init() {






  68         return new PackageTest()
  69             .forTypes(PackageType.WINDOWS)
  70             .configureHelloApp()
  71             .addInitializer(cmd -> cmd.addArguments("--win-upgrade-uuid",
  72                     "F0B18E75-52AD-41A2-BC86-6BE4FCD50BEB"));













































































  73     }
  74 }


   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 java.util.HashMap;
  25 import java.util.List;
  26 import java.util.Map;
  27 import java.util.UUID;
  28 import java.util.function.Supplier;
  29 import jdk.jpackage.test.Annotations.Test;
  30 import jdk.jpackage.test.PackageTest;
  31 import jdk.jpackage.test.PackageType;
  32 import jdk.jpackage.test.WindowsHelper;
  33 import jdk.jpackage.test.TKit;
  34 
  35 /**
  36  * Test both --win-upgrade-uuid and --app-version parameters. Output of the test
  37  * should be WinUpgradeUUIDTest-1.0.exe and WinUpgradeUUIDTest-2.0.exe
  38  * installers. Both output installers should provide the same functionality as
  39  * the default installer (see description of the default installer in
  40  * SimplePackageTest.java) but have the same product code and different
  41  * versions. Running WinUpgradeUUIDTest-2.0.exe installer should automatically
  42  * uninstall older version of the test application previously installed with
  43  * WinUpgradeUUIDTest-1.0.exe installer.
  44  */
  45 
  46 /*
  47  * @test
  48  * @summary jpackage with --win-upgrade-uuid and --app-version
  49  * @library ../helpers
  50  * @key jpackagePlatformPackage
  51  * @requires (jpackage.test.SQETest != null)
  52  * @build jdk.jpackage.test.*
  53  * @requires (os.family == "windows")
  54  * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal
  55  * @compile WinUpgradeUUIDTest.java
  56  * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
  57  *  --jpt-run=WinUpgradeUUIDTest.test
  58  */
  59 
  60 /*
  61  * @test
  62  * @summary jpackage with --win-upgrade-uuid and --app-version
  63  * @library ../helpers
  64  * @key jpackagePlatformPackage
  65  * @requires (jpackage.test.SQETest == null)
  66  * @build jdk.jpackage.test.*
  67  * @requires (os.family == "windows")
  68  * @modules jdk.jpackage/jdk.jpackage.internal
  69  * @compile WinUpgradeUUIDTest.java
  70  * @run main/othervm/timeout=540 -Xmx512m jdk.jpackage.test.Main
  71  *  --jpt-run=WinUpgradeUUIDTest
  72  */
  73 
  74 public class WinUpgradeUUIDTest {
  75 
  76     @Test
  77     public static void test() {
  78         Supplier<PackageTest> init = () -> {
  79             final UUID upgradeCode = UUID.fromString(
  80                     "F0B18E75-52AD-41A2-BC86-6BE4FCD50BEB");
  81             return new PackageTest()
  82                 .forTypes(PackageType.WINDOWS)
  83                 .configureHelloApp()
  84                 .addInitializer(cmd -> cmd.addArguments("--win-upgrade-uuid",
  85                         upgradeCode.toString()))
  86                 .forTypes(PackageType.WIN_MSI)
  87                 .addBundlePropertyVerifier("UpgradeCode", value -> {
  88                     if (value.startsWith("{")) {
  89                         value = value.substring(1);
  90                     }
  91                     if (value.endsWith("}")) {
  92                         value = value.substring(0, value.length() - 1);
  93                     }
  94                     return UUID.fromString(value).equals(upgradeCode);
  95                 }, "is a match with");
  96         };
  97 
  98         // Replace real uninstall command for the first package with nop action.
  99         // It will be uninstalled automatically when the second
 100         // package will be installed.
 101         // However uninstall verification for the first package will be executed.
 102         PackageTest test1 = init.get().setPackageUninstaller(cmd -> {});
 103 
 104         PackageTest test2 = init.get().addInitializer(cmd -> {

 105             cmd.setArgumentValue("--app-version", "2.0");
 106             cmd.setArgumentValue("--arguments", "bar");
 107         });
 108 
 109         new PackageTest.Group(test1, test2).run();
 110     }
 111 
 112     /**
 113      * Running jpackage multiple times with the same parameters should produce
 114      * MSI packages with the same UpgradeCode and ProductCode values.
 115      */
 116     @Test
 117     public static void testUUIDs() {
 118         Supplier<PackageTest> init = () -> {
 119             return new PackageTest()
 120             .forTypes(PackageType.WIN_MSI)
 121             .configureHelloApp()
 122             .addInitializer(cmd -> {
 123                 cmd.setFakeRuntime();
 124                 cmd.setArgumentValue("--dest", TKit.createTempDirectory("output"));
 125             });
 126         };
 127 
 128         PackageTest test1 = init.get();
 129         PackageTest test2 = init.get();
 130         PackageTest test3 = init.get().addInitializer(cmd -> {
 131             cmd.addArguments("--app-version", "2.0");
 132         });
 133         PackageTest test4 = init.get().addInitializer(cmd -> {
 134             cmd.addArguments("--app-version", "2.0");
 135             cmd.addArguments("--vendor", "Foo Inc.");
 136         });
 137 
 138         PackageTest[] tests = new PackageTest[] { test1, test2, test3, test4 };
 139 
 140         var productCodeVerifier = createPropertyVerifier("ProductCode", tests);
 141         var upgradeCodeVerifier = createPropertyVerifier("UpgradeCode", tests);
 142 
 143         List.of(tests).forEach(test -> {
 144             test.run(PackageTest.Action.CREATE);
 145         });
 146 
 147         productCodeVerifier.assertEquals(test1, test2);
 148         productCodeVerifier.assertNotEquals(test1, test3);
 149         productCodeVerifier.assertNotEquals(test1, test4);
 150         productCodeVerifier.assertNotEquals(test3, test4);
 151 
 152         upgradeCodeVerifier.assertEquals(test1, test2);
 153         upgradeCodeVerifier.assertEquals(test1, test3);
 154         upgradeCodeVerifier.assertNotEquals(test1, test4);
 155     }
 156 
 157     private static PropertyVerifier createPropertyVerifier(String propertyName,
 158             PackageTest... tests) {
 159         Map<PackageTest, Map.Entry<String, String>> properties = new HashMap<>();
 160         List.of(tests).forEach(test -> {
 161             test.addBundleVerifier(cmd -> {
 162                 properties.put(test, Map.entry(cmd.getPrintableCommandLine(),
 163                         WindowsHelper.getMsiProperty(cmd, propertyName)));
 164             });
 165         });
 166 
 167         return new PropertyVerifier() {
 168             @Override
 169             protected String propertyName() {
 170                 return propertyName;
 171             }
 172 
 173             @Override
 174             protected Map<PackageTest, Map.Entry<String, String>> propertyValues() {
 175                 return properties;
 176             }
 177         };
 178     }
 179 
 180     static abstract class PropertyVerifier {
 181         void assertEquals(PackageTest x, PackageTest y) {
 182             var entryX = propertyValues().get(x);
 183             var entryY = propertyValues().get(y);
 184             TKit.assertEquals(entryX.getValue(), entryY.getValue(),
 185                     String.format(
 186                             "Check %s is the same for %s and %s command lines",
 187                             propertyName(), entryX.getKey(), entryY.getKey()));
 188         }
 189 
 190         void assertNotEquals(PackageTest x, PackageTest y) {
 191             var entryX = propertyValues().get(x);
 192             var entryY = propertyValues().get(y);
 193             TKit.assertNotEquals(entryX.getValue(), entryY.getValue(),
 194                     String.format(
 195                             "Check %s is different for %s and %s command lines",
 196                             propertyName(), entryX.getKey(), entryY.getKey()));
 197         }
 198 
 199         protected abstract String propertyName();
 200         protected abstract Map<PackageTest, Map.Entry<String, String>> propertyValues();
 201     }
 202 }
< prev index next >