test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageModuleMainClassErrorTest.java
branchJDK-8200758-branch
changeset 57389 cce526c681dc
parent 57314 23da9e6f446f
child 57414 6eda749d3117
equal deleted inserted replaced
57384:4a296d9a76a0 57389:cce526c681dc
    37     private static final String OUTPUT = "output";
    37     private static final String OUTPUT = "output";
    38     private static final String app = JPackagePath.getApp();
    38     private static final String app = JPackagePath.getApp();
    39     private static final String appOutput = JPackagePath.getAppOutputFile();
    39     private static final String appOutput = JPackagePath.getAppOutputFile();
    40     private static final String appWorkingDir = JPackagePath.getAppWorkingDir();
    40     private static final String appWorkingDir = JPackagePath.getAppWorkingDir();
    41 
    41 
    42     private static final String [] CMD = {
    42     private static final String [] CMD1 = {
    43         "create-app-image",
    43         "create-app-image",
    44         "--output", OUTPUT,
    44         "--output", OUTPUT,
    45         "--name", "test",
    45         "--name", "test",
    46         "--module", "com.hello",
    46         "--module", "com.hello",
    47         "--module-path", "input"};
    47         "--module-path", "input"};
    48 
    48 
       
    49     private static final String [] CMD2 = {
       
    50         "create-app-image",
       
    51         "--output", OUTPUT,
       
    52         "--name", "test",
       
    53         "--module", "com.hello/com.hello.Hello",
       
    54         "--module-path", "input"};
       
    55 
    49     private static void validate(String buildOutput) throws Exception {
    56     private static void validate(String buildOutput) throws Exception {
    50 
    57 
    51         File outfile = new File(appWorkingDir + File.separator + appOutput);
    58         File outfile = new File(appWorkingDir + File.separator + appOutput);
    52         int retVal = JPackageHelper.execute(outfile, app);
    59         int retVal = JPackageHelper.execute(outfile, app);
    53         if (retVal == 0) {
    60         if (retVal != 0) {
    54             throw new AssertionError(
    61             throw new AssertionError(
    55                    "Test application exited without error: ");
    62                    "Test application exited with error: ");
    56         }
    63         }
    57 
    64 
    58         if (!outfile.exists()) {
    65         if (!outfile.exists()) {
    59             throw new AssertionError(appOutput + " was not created");
    66             throw new AssertionError(appOutput + " was not created");
    60         }
    67         }
    61         String output = Files.readString(outfile.toPath());
    68         String output = Files.readString(outfile.toPath());
    62         String[] result = output.split("\n");
    69         String[] result = output.split("\n");
    63 
    70 
    64         if (result.length != 1) {
    71         if (!result[0].trim().equals("jpackage test application")) {
    65             System.out.println("outfile (" + outfile + ") content: " + output);
    72             throw new AssertionError("Unexpected result[0]: " + result[0]);
    66             throw new AssertionError(
       
    67                    "Unexpected number of lines: " + result.length);
       
    68         }
    73         }
    69 
    74 
    70         if (!result[0].trim().contains(
    75         if (!result[1].trim().equals("args.length: 0")) {
    71                 "does not have a ModuleMainClass attribute")) {
    76             throw new AssertionError("Unexpected result[1]: " + result[1]);
    72             throw new AssertionError("Unexpected result[0]: " + result[0]);
       
    73         }
    77         }
    74     }
    78     }
    75 
    79 
    76     public static void main(String[] args) throws Exception {
    80     public static void main(String[] args) throws Exception {
    77         JPackageHelper.createHelloModule();
    81         JPackageHelper.createHelloModule();
    78 
    82 
    79         JPackageHelper.deleteOutputFolder(OUTPUT);
    83         JPackageHelper.deleteOutputFolder(OUTPUT);
    80         validate(JPackageHelper.executeCLI(true, CMD));
    84         JPackageHelper.executeCLI(false, CMD1);
    81 
    85 
    82         JPackageHelper.deleteOutputFolder(OUTPUT);
    86         JPackageHelper.deleteOutputFolder(OUTPUT);
    83         validate(JPackageHelper.executeToolProvider(true, CMD));
    87         JPackageHelper.executeToolProvider(false, CMD1);
       
    88 
       
    89         JPackageHelper.deleteOutputFolder(OUTPUT);
       
    90         validate(JPackageHelper.executeCLI(true, CMD2));
       
    91 
       
    92         JPackageHelper.deleteOutputFolder(OUTPUT);
       
    93         validate(JPackageHelper.executeToolProvider(true, CMD2));
    84     }
    94     }
    85 
    95 
    86 }
    96 }