test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageModuleMainClassErrorTest.java
branchJDK-8200758-branch
changeset 57446 5a5b85f00a63
parent 57445 405ddd80496e
child 57447 3fbe47a62ed0
equal deleted inserted replaced
57445:405ddd80496e 57446:5a5b85f00a63
     1 /*
       
     2  * Copyright (c) 2018, 2019, 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.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 import java.io.File;
       
    25 import java.nio.file.Files;
       
    26 
       
    27 /*
       
    28  * @test
       
    29  * @summary jpackage create image with no main class arguments and with main-class attribute
       
    30  * @library ../helpers
       
    31  * @build JPackageHelper
       
    32  * @build JPackagePath
       
    33  * @modules jdk.jpackage
       
    34  * @run main/othervm -Xmx512m JPackageCreateAppImageModuleMainClassErrorTest
       
    35  */
       
    36 public class JPackageCreateAppImageModuleMainClassErrorTest {
       
    37     private static final String OUTPUT = "output";
       
    38     private static final String app = JPackagePath.getApp();
       
    39     private static final String appOutput = JPackagePath.getAppOutputFile();
       
    40 
       
    41     private static final String [] CMD1 = {
       
    42         "--output", OUTPUT,
       
    43         "--name", "test",
       
    44         "--module", "com.hello",
       
    45         "--module-path", "input"};
       
    46 
       
    47     private static final String [] CMD2 = {
       
    48         "--output", OUTPUT,
       
    49         "--name", "test",
       
    50         "--module", "com.hello/com.hello.Hello",
       
    51         "--module-path", "input"};
       
    52 
       
    53     private static void validate(String buildOutput) throws Exception {
       
    54 
       
    55         File outfile = new File(appOutput);
       
    56         int retVal = JPackageHelper.execute(outfile, app);
       
    57         if (retVal != 0) {
       
    58             throw new AssertionError(
       
    59                    "Test application exited with error: ");
       
    60         }
       
    61 
       
    62         if (!outfile.exists()) {
       
    63             throw new AssertionError(appOutput + " was not created");
       
    64         }
       
    65         String output = Files.readString(outfile.toPath());
       
    66         String[] result = output.split("\n");
       
    67 
       
    68         if (!result[0].trim().equals("jpackage test application")) {
       
    69             throw new AssertionError("Unexpected result[0]: " + result[0]);
       
    70         }
       
    71 
       
    72         if (!result[1].trim().equals("args.length: 0")) {
       
    73             throw new AssertionError("Unexpected result[1]: " + result[1]);
       
    74         }
       
    75     }
       
    76 
       
    77     public static void main(String[] args) throws Exception {
       
    78         JPackageHelper.createHelloModule();
       
    79 
       
    80         JPackageHelper.deleteOutputFolder(OUTPUT);
       
    81         JPackageHelper.executeCLI(false, CMD1);
       
    82 
       
    83         JPackageHelper.deleteOutputFolder(OUTPUT);
       
    84         JPackageHelper.executeToolProvider(false, CMD1);
       
    85 
       
    86         JPackageHelper.deleteOutputFolder(OUTPUT);
       
    87         validate(JPackageHelper.executeCLI(true, CMD2));
       
    88 
       
    89         JPackageHelper.deleteOutputFolder(OUTPUT);
       
    90         validate(JPackageHelper.executeToolProvider(true, CMD2));
       
    91     }
       
    92 
       
    93 }