jdk/test/sun/tools/jinfo/JInfoSanityTest.java
changeset 38360 fb63be22ffa6
parent 38359 fd9b36598481
child 38361 8ea2d56bfdf3
equal deleted inserted replaced
38359:fd9b36598481 38360:fb63be22ffa6
     1 /*
       
     2  * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 import static jdk.testlibrary.Asserts.assertNotEquals;
       
    27 import static jdk.testlibrary.Asserts.assertTrue;
       
    28 import static jdk.testlibrary.Asserts.assertFalse;
       
    29 import jdk.testlibrary.OutputAnalyzer;
       
    30 
       
    31 /**
       
    32  * @test
       
    33  * @summary The test sanity checks functionality of 'jinfo -h', 'jinfo -help',
       
    34  *          and verifies jinfo exits abnormally if started with invalid options.
       
    35  * @library /lib/testlibrary
       
    36  * @modules java.management
       
    37  * @build jdk.testlibrary.* JInfoHelper
       
    38  * @run main JInfoSanityTest
       
    39  */
       
    40 public class JInfoSanityTest {
       
    41 
       
    42     public static void main(String[] args) throws Exception {
       
    43         test_h();
       
    44         test_help();
       
    45         testVersion();
       
    46         testUnknownHost();
       
    47     }
       
    48 
       
    49     private static void test_h() throws Exception {
       
    50         OutputAnalyzer output = JInfoHelper.jinfoNoPid("-h");
       
    51         output.shouldHaveExitValue(0);
       
    52         assertFalse(output.getStderr().isEmpty(), "'jinfo -h' stderr should not be empty");
       
    53         assertTrue(output.getStdout().isEmpty(), "'jinfo -h' stdout should be empty");
       
    54     }
       
    55 
       
    56     private static void test_help() throws Exception {
       
    57         OutputAnalyzer output = JInfoHelper.jinfoNoPid("-help");
       
    58         output.shouldHaveExitValue(0);
       
    59         assertFalse(output.getStderr().isEmpty(), "'jinfo -help' stderr should not be empty");
       
    60         assertTrue(output.getStdout().isEmpty(), "'jinfo -help' stdout should be empty");
       
    61     }
       
    62 
       
    63     private static void testVersion() throws Exception {
       
    64         OutputAnalyzer output = JInfoHelper.jinfoNoPid("-version");
       
    65         output.shouldHaveExitValue(1);
       
    66         assertFalse(output.getStderr().isEmpty(), "'jinfo -version' stderr should not be empty");
       
    67         assertTrue(output.getStdout().isEmpty(), "'jinfo -version' stdout should be empty");
       
    68     }
       
    69 
       
    70     private static void testUnknownHost() throws Exception {
       
    71         String unknownHost = "Oja781nh2ev7vcvbajdg-Sda1-C";
       
    72         OutputAnalyzer output = JInfoHelper.jinfoNoPid("med@" + unknownHost);
       
    73         assertNotEquals(output.getExitValue(), 0, "A non-zero exit code should be returned for invalid operation");
       
    74         output.shouldMatch(".*(Connection refused to host\\:|UnknownHostException\\:) " + unknownHost + ".*");
       
    75     }
       
    76 
       
    77 }