test/jdk/tools/jpackage/share/ErrorTest.java
author herrick
Fri, 08 Nov 2019 14:53:03 -0500
branchJDK-8200758-branch
changeset 58994 b09ba68c6a19
parent 58993 b5e1baa9d2c3
permissions -rw-r--r--
8233636 : Make jpackage an incubator and remove tool provider implementation Reviewed-by: asemenyuk, almatvee, kcr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
     1
/*
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
     4
 *
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
     8
 *
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    13
 * accompanied this code).
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    14
 *
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    18
 *
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    21
 * questions.
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    22
 */
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    23
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    24
 /*
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    25
 * @test
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    26
 * @summary jpackage create app image error test
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    27
 * @library ../helpers
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    28
 * @build JPackageHelper
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    29
 * @build JPackagePath
57446
5a5b85f00a63 8226891: rename and re-layout jpackage tests.
herrick
parents: 57438
diff changeset
    30
 * @build Base
58994
b09ba68c6a19 8233636 : Make jpackage an incubator and remove tool provider implementation
herrick
parents: 58993
diff changeset
    31
 * @modules jdk.incubator.jpackage
57446
5a5b85f00a63 8226891: rename and re-layout jpackage tests.
herrick
parents: 57438
diff changeset
    32
 * @run main/othervm -Xmx512m ErrorTest
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    33
 */
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    34
import java.util.*;
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    35
import java.io.*;
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    36
import java.nio.*;
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    37
import java.nio.file.*;
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    38
import java.nio.file.attribute.*;
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    39
57446
5a5b85f00a63 8226891: rename and re-layout jpackage tests.
herrick
parents: 57438
diff changeset
    40
public class ErrorTest {
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    41
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    42
    private static final String OUTPUT = "output";
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    43
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    44
    private static final String ARG1 = "--no-such-argument";
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    45
    private static final String EXPECTED1 =
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    46
            "Invalid Option: [--no-such-argument]";
58147
45a9084fe981 8230521: rename --output/-o option and add default value (".")
herrick
parents: 58114
diff changeset
    47
    private static final String ARG2 = "--dest";
57438
4a31db8d42bd 8226599: use code coverage results to remove dead code
herrick
parents: 57414
diff changeset
    48
    private static final String EXPECTED2 = "--main-jar or --module";
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    49
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    50
    private static final String [] CMD1 = {
58993
b5e1baa9d2c3 8233592: change --package-type option name to --type and allow -t short form
herrick
parents: 58359
diff changeset
    51
        "--type", "app-image",
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    52
        "--input", "input",
58147
45a9084fe981 8230521: rename --output/-o option and add default value (".")
herrick
parents: 58114
diff changeset
    53
        "--dest", OUTPUT,
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    54
        "--name", "test",
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    55
        "--main-jar", "non-existant.jar",
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    56
    };
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    57
    private static final String EXP1 = "main jar does not exist";
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    58
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    59
    private static final String [] CMD2 = {
58993
b5e1baa9d2c3 8233592: change --package-type option name to --type and allow -t short form
herrick
parents: 58359
diff changeset
    60
        "--type", "app-image",
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    61
        "--input", "input",
58147
45a9084fe981 8230521: rename --output/-o option and add default value (".")
herrick
parents: 58114
diff changeset
    62
        "--dest", OUTPUT,
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    63
        "--name", "test",
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    64
        "--main-jar", "hello.jar",
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    65
    };
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    66
    private static final String EXP2 = "class was not specified nor was";
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    67
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    68
    private static void validate(String output, String expected, boolean single)
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    69
            throws Exception {
58359
e065fd274bc1 8230649 : Make jpackage tool an experimental feature
herrick
parents: 58147
diff changeset
    70
        String[] result = JPackageHelper.splitAndFilter(output);
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    71
        if (single && result.length != 1) {
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    72
            System.err.println(output);
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    73
            throw new AssertionError("Unexpected multiple lines of output: "
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    74
                    + output);
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    75
        }
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    76
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    77
        if (!result[0].trim().contains(expected)) {
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    78
            throw new AssertionError("Unexpected output: " + result[0]
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    79
                    + " - expected output to contain: " + expected);
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    80
        }
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    81
    }
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    82
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    83
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    84
    public static void main(String[] args) throws Exception {
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    85
        JPackageHelper.createHelloImageJar();
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    86
58114
42df7de58e39 8230519: jpackage "--package-type" values and default
herrick
parents: 57446
diff changeset
    87
        validate(JPackageHelper.executeToolProvider(false,
58993
b5e1baa9d2c3 8233592: change --package-type option name to --type and allow -t short form
herrick
parents: 58359
diff changeset
    88
            "--type", "app-image", ARG1), EXPECTED1, true);
58147
45a9084fe981 8230521: rename --output/-o option and add default value (".")
herrick
parents: 58114
diff changeset
    89
        validate(JPackageHelper.executeToolProvider(false,
58993
b5e1baa9d2c3 8233592: change --package-type option name to --type and allow -t short form
herrick
parents: 58359
diff changeset
    90
            "--type", "app-image", ARG2), EXPECTED2, true);
57314
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    91
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    92
        JPackageHelper.deleteOutputFolder(OUTPUT);
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    93
        validate(JPackageHelper.executeToolProvider(false, CMD1), EXP1, false);
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    94
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    95
        JPackageHelper.deleteOutputFolder(OUTPUT);
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    96
        validate(JPackageHelper.executeToolProvider(false, CMD2), EXP2, false);
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    97
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    98
    }
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
    99
23da9e6f446f 8221641: Follow up code clean up for JDK-8221582
herrick
parents:
diff changeset
   100
}