test/jdk/tools/jpackage/createimage/JPackageCreateImageMainClassAttributeTest.java
author kcr
Thu, 10 Jan 2019 11:30:09 -0800
branchJDK-8200758-branch
changeset 57106 ea870b9ce89a
parent 57079 c53a2eca0f57
child 57150 fa68c2ab636d
permissions -rw-r--r--
8216492: Update copyright of all new jpackage fils to 2019 Reviewed-by: herrick
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     1
/*
57106
ea870b9ce89a 8216492: Update copyright of all new jpackage fils to 2019
kcr
parents: 57079
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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
 * 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
     6
 * 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
     7
 * published by the Free Software Foundation.
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 distributed in the hope that it will be useful, but WITHOUT
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    12
 * 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
    13
 * accompanied this code).
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    14
 *
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    15
 * 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
    16
 * 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
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
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
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    20
 * 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
    21
 * questions.
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
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    24
import java.io.File;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    25
import java.nio.file.Files;
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
 * @test
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    29
 * @summary jpackage create image with no main class arguments and with main-class attribute
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    30
 * @library ../helpers
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    31
 * @build JPackageHelper
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    32
 * @build JPackagePath
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    33
 * @modules jdk.jpackage
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    34
 * @run main/othervm -Xmx512m JPackageCreateImageMainClassAttributeTest
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    35
 */
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    36
public class JPackageCreateImageMainClassAttributeTest {
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    37
    private static final String app = JPackagePath.getApp();
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    38
    private static final String appOutput = JPackagePath.getAppOutputFile();
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    39
    private static final String appWorkingDir = JPackagePath.getAppWorkingDir();
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    40
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    41
    private static final String[] CMD = {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    42
        "create-image",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    43
        "--input", "input",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    44
        "--output", "output",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    45
        "--name", "test",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    46
        "--main-jar", "hello.jar",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    47
        "--force",
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    48
        "--files", "hello.jar"};
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    49
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    50
    private static void validateResult(String[] result) throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    51
        if (result.length != 2) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    52
            throw new AssertionError(
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    53
                   "Unexpected number of lines: " + result.length);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    54
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    55
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    56
        if (!result[0].trim().equals("jpackage test application")) {
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    57
            throw new AssertionError("Unexpected result[0]: " + result[0]);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    58
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    59
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    60
        if (!result[1].trim().equals("args.length: 0")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    61
            throw new AssertionError("Unexpected result[1]: " + result[1]);
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
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    64
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    65
    private static void validate() throws Exception {
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    66
        int retVal = JPackageHelper.execute(null, app);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    67
        if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    68
            throw new AssertionError(
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    69
                   "Test application exited with error: " + retVal);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    70
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    71
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    72
        File outfile = new File(appWorkingDir + File.separator + appOutput);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    73
        if (!outfile.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    74
            throw new AssertionError(appOutput + " was not created");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    75
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    76
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    77
        String output = Files.readString(outfile.toPath());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    78
        String[] result = output.split("\n");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    79
        validateResult(result);
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 testMainClassAttribute() throws Exception {
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    83
        JPackageHelper.executeCLI(true, CMD);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    84
        validate();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    85
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    86
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    87
    private static void testMainClassAttributeToolProvider() throws Exception {
57039
98d3963b0b7b 8214051: rename jpackager tool to jpackage
herrick
parents: 57031
diff changeset
    88
        JPackageHelper.executeToolProvider(true, CMD);
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    89
        validate();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    90
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    91
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    92
    public static void main(String[] args) throws Exception {
57079
c53a2eca0f57 8215036: Create initial set of tests for jpackage create-installer mode
herrick
parents: 57039
diff changeset
    93
        JPackageHelper.createHelloImageJarWithMainClass();
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    94
        testMainClassAttribute();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    95
        testMainClassAttributeToolProvider();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    96
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    97
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    98
}