test/jdk/tools/jpackager/JPackagerHelpTest.java
author herrick
Thu, 08 Nov 2018 19:07:57 -0500
branchJDK-8200758-branch
changeset 57023 8bf89434f0a5
child 57030 902f4c4fba42
permissions -rw-r--r--
8213332: Create minimal 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
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    27
 * @build JPackagerHelper
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    28
 * @modules jdk.jpackager
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    29
 * @run main/othervm -Xmx512m JPackagerHelpTest
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    30
 */
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    31
public class 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
    // Platform specific help messages.
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    34
    private static final String WINDOWS_HELP =
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    35
            "The following options are valid for Windows platforms";
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    36
    private static final String OSX_HELP =
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    37
            "The following options are valid for Mac OS X platforms";
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    38
    private static final String LINUX_HELP =
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    39
            "The following options are valid for Linux platforms";
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    40
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    41
    private static void validate(String output1, String output2)
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    42
            throws Exception {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    43
        if (output1.split("\n").length < 25) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    44
            throw new AssertionError("jpacakger --help failed");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    45
        }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    46
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    47
        if (output2.split("\n").length < 25) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    48
            throw new AssertionError("jpacakger -h failed");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    49
        }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    50
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    51
        // Make sure output matches for --help and -h
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    52
        if (!output1.equals(output2)) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    53
            System.err.println("================= --help =================");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    54
            System.err.println(output1);
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    55
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    56
            System.err.println("=================== -h ===================");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    57
            System.err.println(output2);
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    58
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    59
            throw new AssertionError(
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    60
                    "jpacakger help text does not match between --help and -h");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    61
        }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    62
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    63
        if (JPackagerHelper.isWindows()) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    64
            if (!output1.contains(WINDOWS_HELP)) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    65
                throw new AssertionError(
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    66
                  "jpacakger help text missing Windows specific help");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    67
            }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    68
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    69
            if (output1.contains(OSX_HELP) || output1.contains(LINUX_HELP)) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    70
                throw new AssertionError(
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    71
                  "jpacakger help text contains other platforms specific help");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    72
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    73
            }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    74
        } else if (JPackagerHelper.isOSX()) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    75
            if (!output1.contains(OSX_HELP)) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    76
                throw new AssertionError(
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    77
                  "jpacakger help text missing OS X specific help");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    78
            }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    79
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    80
            if (output1.contains(WINDOWS_HELP) ||
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    81
                    output1.contains(LINUX_HELP)) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    82
                throw new AssertionError(
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    83
                 "jpacakger help text contains other platforms specific help");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    84
            }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    85
        } else if (JPackagerHelper.isLinux()) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    86
            if (!output1.contains(LINUX_HELP)) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    87
                throw new AssertionError(
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    88
                  "jpacakger help text missing Linux specific help");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    89
            }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    90
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    91
            if (output1.contains(OSX_HELP) || output1.contains(WINDOWS_HELP)) {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    92
                throw new AssertionError(
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    93
                  "jpacakger help text contains other platforms specific help");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    94
            }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    95
        }
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
    private static void testHelp() throws Exception {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
    99
        String output1 = JPackagerHelper.executeCLI(true, "--help");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   100
        String output2 = JPackagerHelper.executeCLI(true, "-h");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   101
        validate(output1, output2);
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   102
    }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   103
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   104
    private static void testHelpToolProvider() throws Exception {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   105
        String output1 = JPackagerHelper.executeToolProvider(true, "--help");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   106
        String output2 = JPackagerHelper.executeToolProvider(true, "-h");
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   107
        validate(output1, output2);
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   108
    }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   109
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   110
    public static void main(String[] args) throws Exception {
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   111
        testHelp();
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   112
        testHelpToolProvider();
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   113
    }
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   114
8bf89434f0a5 8213332: Create minimal automated tests for jpackager
herrick
parents:
diff changeset
   115
}