test/jdk/tools/jpackager/JPackagerHelpTest.java
author herrick
Wed, 21 Nov 2018 13:20:52 -0500
branchJDK-8200758-branch
changeset 57031 ea4755429ed8
parent 57030 902f4c4fba42
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:
57023
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
     1
/*
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
     4
 *
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
     8
 *
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    13
 * accompanied this code).
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    14
 *
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    18
 *
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    21
 * questions.
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    22
 */
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    23
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    24
 /*
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    25
 * @test
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    26
 * @summary jpackager help test
57030
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57023
diff changeset
    27
 * @library helpers
57023
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    28
 * @build JPackagerHelper
57030
902f4c4fba42 8214021: Create additional automated tests for jpackager
herrick
parents: 57023
diff changeset
    29
 * @build JPackagerPath
57023
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    30
 * @modules jdk.jpackager
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    31
 * @run main/othervm -Xmx512m JPackagerHelpTest
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    32
 */
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    33
public class JPackagerHelpTest {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    34
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    35
    // Platform specific help messages.
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    36
    private static final String WINDOWS_HELP =
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    37
            "The following options are valid for Windows platforms";
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    38
    private static final String OSX_HELP =
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    39
            "The following options are valid for Mac OS X platforms";
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    40
    private static final String LINUX_HELP =
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    41
            "The following options are valid for Linux platforms";
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    42
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    43
    private static void validate(String output1, String output2)
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    44
            throws Exception {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    45
        if (output1.split("\n").length < 25) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    46
            throw new AssertionError("jpacakger --help failed");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    47
        }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    48
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    49
        if (output2.split("\n").length < 25) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    50
            throw new AssertionError("jpacakger -h failed");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    51
        }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    52
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    53
        // Make sure output matches for --help and -h
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    54
        if (!output1.equals(output2)) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    55
            System.err.println("================= --help =================");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    56
            System.err.println(output1);
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    57
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    58
            System.err.println("=================== -h ===================");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    59
            System.err.println(output2);
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    60
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    61
            throw new AssertionError(
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    62
                    "jpacakger help text does not match between --help and -h");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    63
        }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    64
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    65
        if (JPackagerHelper.isWindows()) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    66
            if (!output1.contains(WINDOWS_HELP)) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    67
                throw new AssertionError(
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    68
                  "jpacakger help text missing Windows specific help");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    69
            }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    70
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    71
            if (output1.contains(OSX_HELP) || output1.contains(LINUX_HELP)) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    72
                throw new AssertionError(
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    73
                  "jpacakger help text contains other platforms specific help");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    74
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    75
            }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    76
        } else if (JPackagerHelper.isOSX()) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    77
            if (!output1.contains(OSX_HELP)) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    78
                throw new AssertionError(
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    79
                  "jpacakger help text missing OS X specific help");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    80
            }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    81
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    82
            if (output1.contains(WINDOWS_HELP) ||
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    83
                    output1.contains(LINUX_HELP)) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    84
                throw new AssertionError(
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    85
                 "jpacakger help text contains other platforms specific help");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    86
            }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    87
        } else if (JPackagerHelper.isLinux()) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    88
            if (!output1.contains(LINUX_HELP)) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    89
                throw new AssertionError(
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    90
                  "jpacakger help text missing Linux specific help");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    91
            }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    92
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    93
            if (output1.contains(OSX_HELP) || output1.contains(WINDOWS_HELP)) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    94
                throw new AssertionError(
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    95
                  "jpacakger help text contains other platforms specific help");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    96
            }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    97
        }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    98
    }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    99
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   100
    private static void testHelp() throws Exception {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   101
        String output1 = JPackagerHelper.executeCLI(true, "--help");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   102
        String output2 = JPackagerHelper.executeCLI(true, "-h");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   103
        validate(output1, output2);
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   104
    }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   105
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   106
    private static void testHelpToolProvider() throws Exception {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   107
        String output1 = JPackagerHelper.executeToolProvider(true, "--help");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   108
        String output2 = JPackagerHelper.executeToolProvider(true, "-h");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   109
        validate(output1, output2);
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   110
    }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   111
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   112
    public static void main(String[] args) throws Exception {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   113
        testHelp();
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   114
        testHelpToolProvider();
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   115
    }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   116
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   117
}