test/jdk/tools/jpackage/share/AppVersionTest.java
branchJDK-8200758-branch
changeset 58648 3bf53ffa9ae7
parent 58647 2c43b89b1679
child 58670 6fb9e12d5595
equal deleted inserted replaced
58647:2c43b89b1679 58648:3bf53ffa9ae7
     1 /*
       
     2  * Copyright (c) 2018, 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 import java.io.File;
       
    25 import java.nio.file.Files;
       
    26 
       
    27 /*
       
    28  * @test
       
    29  * @summary jpackage create image --app-version test
       
    30  * @library ../helpers
       
    31  * @build JPackageHelper
       
    32  * @build JPackagePath
       
    33  * @modules jdk.jpackage
       
    34  * @run main/othervm -Xmx512m AppVersionTest
       
    35  */
       
    36 public class AppVersionTest {
       
    37     private static final String OUTPUT = "output";
       
    38     private static final String appCfg = JPackagePath.getAppCfg();
       
    39     private static final String VERSION = "2.3";
       
    40     private static final String VERSION_DEFAULT = "1.0";
       
    41 
       
    42     private static final String[] CMD = {
       
    43         "--package-type", "app-image",
       
    44         "--input", "input",
       
    45         "--dest", OUTPUT,
       
    46         "--name", "test",
       
    47         "--main-jar", "hello.jar",
       
    48         "--main-class", "Hello",
       
    49    };
       
    50 
       
    51     private static final String[] CMD_VERSION = {
       
    52         "--package-type", "app-image",
       
    53         "--input", "input",
       
    54         "--dest", OUTPUT,
       
    55         "--name", "test",
       
    56         "--main-jar", "hello.jar",
       
    57         "--main-class", "Hello",
       
    58         "--app-version", VERSION};
       
    59 
       
    60     private static void validate(String version)
       
    61             throws Exception {
       
    62         File outfile = new File(appCfg);
       
    63         if (!outfile.exists()) {
       
    64             throw new AssertionError(appCfg + " was not created");
       
    65         }
       
    66 
       
    67         String output = Files.readString(outfile.toPath());
       
    68         if (version == null) {
       
    69             version = VERSION_DEFAULT;
       
    70         }
       
    71 
       
    72         String expected = "app.version=" + version;
       
    73         if (!output.contains(expected)) {
       
    74             System.err.println("Expected: " + expected);
       
    75             throw new AssertionError("Cannot find expected entry in config file");
       
    76         }
       
    77     }
       
    78 
       
    79     private static void testVersion() throws Exception {
       
    80         JPackageHelper.executeCLI(true, CMD);
       
    81         validate(null);
       
    82         JPackageHelper.deleteOutputFolder(OUTPUT);
       
    83         JPackageHelper.executeCLI(true, CMD_VERSION);
       
    84         validate(VERSION);
       
    85     }
       
    86 
       
    87     private static void testVersionToolProvider() throws Exception {
       
    88         JPackageHelper.deleteOutputFolder(OUTPUT);
       
    89         JPackageHelper.executeToolProvider(true, CMD);
       
    90         validate(null);
       
    91         JPackageHelper.deleteOutputFolder(OUTPUT);
       
    92         JPackageHelper.executeToolProvider(true, CMD_VERSION);
       
    93         validate(VERSION);
       
    94     }
       
    95 
       
    96     public static void main(String[] args) throws Exception {
       
    97         JPackageHelper.createHelloImageJar();
       
    98         testVersion();
       
    99         testVersionToolProvider();
       
   100     }
       
   101 
       
   102 }