1 /*
   2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   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 package jdk.jpackage.tests;
  25 
  26 import java.util.Collection;
  27 import java.util.List;
  28 import jdk.jpackage.test.Annotations.Parameters;
  29 import jdk.jpackage.test.Annotations.Test;
  30 import jdk.jpackage.test.JPackageCommand;
  31 import jdk.jpackage.test.TKit;
  32 
  33 /*
  34  * @test
  35  * @summary jpackage application version testing
  36  * @library ../../../../helpers
  37  * @build jdk.jpackage.test.*
  38  * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal
  39  * @compile AppVersionTest.java
  40  * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
  41  *  --jpt-run=jdk.jpackage.tests.AppVersionTest
  42  */
  43 
  44 public final class AppVersionTest {
  45 
  46     @Parameters
  47     public static Collection input() {
  48         return List.of(new Object[][]{
  49             // Default jpackage version
  50             {"1.0", "Hello", null},
  51             {"1.0", "com.other/com.other.Hello", null},
  52             // Version should be picked from --app-version
  53             {"3.1", "Hello", new String[]{"--app-version", "3.1"}},
  54             {"3.2", "com.other/com.other.Hello", new String[]{"--app-version",
  55                 "3.2"}},
  56             // Version should be picked from the last --app-version
  57             {"3.3", "Hello", new String[]{"--app-version", "4", "--app-version",
  58                 "3.3"}},
  59             {"7.8", "com.other/com.other.Hello", new String[]{"--app-version",
  60                 "4", "--app-version", "7.8"}},
  61             // Pick version from jar
  62             {"3.10.17", "com.other/com.other.Hello@3.10.17", null},
  63             // Ignore version in jar if --app-version given
  64             {"7.5.81", "com.other/com.other.Hello@3.10.17", new String[]{
  65                 "--app-version", "7.5.81"}}
  66         });
  67     }
  68 
  69     public AppVersionTest(String expectedVersion, String javaAppDesc,
  70             String[] jpackageArgs) {
  71         this.expectedVersion = expectedVersion;
  72 
  73         cmd = JPackageCommand.helloAppImage(javaAppDesc);
  74         if (jpackageArgs != null) {
  75             cmd.addArguments(jpackageArgs);
  76         }
  77     }
  78 
  79     @Test
  80     public void test() {
  81         cmd.executeAndAssertHelloAppImageCreated();
  82         String actualVersion = cmd.readLaunherCfgFile().getValue("Application",
  83                 "app.version");
  84         TKit.assertEquals(expectedVersion, actualVersion,
  85                 "Check application version");
  86     }
  87 
  88     private final String expectedVersion;
  89     private final JPackageCommand cmd;
  90 }