test/jdk/tools/jpackager/createimage/JPackagerCreateImageVersionTest.java
author herrick
Wed, 21 Nov 2018 13:20:52 -0500
branchJDK-8200758-branch
changeset 57031 ea4755429ed8
permissions -rw-r--r--
8214021: Create additional automated tests for jpackager Submitten-by: almatvee Reviewed-by: herrick. kcr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     1
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     2
import java.io.File;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     3
import java.nio.file.Files;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     4
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     5
/*
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     6
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     7
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     8
 *
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     9
 * This code is free software; you can redistribute it and/or modify it
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    10
 * under the terms of the GNU General Public License version 2 only, as
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    11
 * published by the Free Software Foundation.
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    12
 *
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    13
 * This code is distributed in the hope that it will be useful, but WITHOUT
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    15
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    16
 * version 2 for more details (a copy is included in the LICENSE file that
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    17
 * accompanied this code).
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    18
 *
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    19
 * You should have received a copy of the GNU General Public License version
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    20
 * 2 along with this work; if not, write to the Free Software Foundation,
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    21
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    22
 *
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    23
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    24
 * or visit www.oracle.com if you need additional information or have any
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    25
 * questions.
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    26
 */
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    27
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    28
/*
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    29
 * @test
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    30
 * @summary jpackager create image --version test
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    31
 * @library ../helpers
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    32
 * @build JPackagerHelper
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    33
 * @build JPackagerPath
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    34
 * @modules jdk.jpackager
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    35
 * @run main/othervm -Xmx512m JPackagerCreateImageVersionTest
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    36
 */
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    37
public class JPackagerCreateImageVersionTest {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    38
    private static final String appCfg = JPackagerPath.getAppCfg();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    39
    private static final String VERSION = "2.3";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    40
    private static final String VERSION_DEFAULT = "1.0";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    41
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    42
    private static final String[] CMD = {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    43
        "create-image",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    44
        "--input", "input",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    45
        "--output", "output",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    46
        "--name", "test",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    47
        "--main-jar", "hello.jar",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    48
        "--class", "Hello",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    49
        "--force",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    50
        "--files", "hello.jar"};
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    51
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    52
    private static final String[] CMD_VERSION = {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    53
        "create-image",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    54
        "--input", "input",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    55
        "--output", "output",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    56
        "--name", "test",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    57
        "--main-jar", "hello.jar",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    58
        "--class", "Hello",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    59
        "--files", "hello.jar",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    60
        "--force",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    61
        "--version", VERSION};
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    62
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    63
    private static void validate(String version)
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    64
            throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    65
        File outfile = new File(appCfg);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    66
        if (!outfile.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    67
            throw new AssertionError(appCfg + " was not created");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    68
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    69
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    70
        String output = Files.readString(outfile.toPath());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    71
        if (version == null) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    72
            version = VERSION_DEFAULT;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    73
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    74
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    75
        String expected = "app.version=" + version;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    76
        if (!output.contains(expected)) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    77
            System.err.println("Expected: " + expected);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    78
            throw new AssertionError("Cannot find expected entry in config file");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    79
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    80
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    81
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    82
    private static void testVersion() throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    83
        JPackagerHelper.executeCLI(true, CMD);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    84
        validate(null);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    85
        JPackagerHelper.executeCLI(true, CMD_VERSION);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    86
        validate(VERSION);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    87
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    88
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    89
    private static void testVersionToolProvider() throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    90
        JPackagerHelper.executeToolProvider(true, CMD);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    91
        validate(null);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    92
        JPackagerHelper.executeToolProvider(true, CMD_VERSION);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    93
        validate(VERSION);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    94
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    95
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    96
    public static void main(String[] args) throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    97
        JPackagerHelper.createHelloJar();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    98
        testVersion();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    99
        testVersionToolProvider();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   100
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   101
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   102
}