< prev index next >

test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageMainClassAttributeTest.java

Print this page




  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 JPackageCreateAppImageMainClassAttributeTest
  35  */
  36 public class JPackageCreateAppImageMainClassAttributeTest {
  37     private static final String OUTPUT = "output";
  38     private static final String app = JPackagePath.getApp();
  39     private static final String appOutput = JPackagePath.getAppOutputFile();
  40     private static final String appWorkingDir = JPackagePath.getAppWorkingDir();
  41 
  42     private static final String[] CMD = {
  43         "--input", "input",
  44         "--output", OUTPUT,
  45         "--name", "test",
  46         "--main-jar", "hello.jar"};
  47 
  48     private static void validateResult(String[] result) throws Exception {
  49         if (result.length != 2) {
  50             throw new AssertionError(
  51                    "Unexpected number of lines: " + result.length);
  52         }
  53 
  54         if (!result[0].trim().equals("jpackage test application")) {
  55             throw new AssertionError("Unexpected result[0]: " + result[0]);
  56         }
  57 
  58         if (!result[1].trim().equals("args.length: 0")) {
  59             throw new AssertionError("Unexpected result[1]: " + result[1]);
  60         }
  61     }
  62 
  63     private static void validate() throws Exception {
  64         int retVal = JPackageHelper.execute(null, app);
  65         if (retVal != 0) {
  66             throw new AssertionError(
  67                    "Test application exited with error: " + retVal);
  68         }
  69 
  70         File outfile = new File(appWorkingDir + File.separator + appOutput);
  71         if (!outfile.exists()) {
  72             throw new AssertionError(appOutput + " was not created");
  73         }
  74 
  75         String output = Files.readString(outfile.toPath());
  76         String[] result = output.split("\n");
  77         validateResult(result);
  78     }
  79 
  80     private static void testMainClassAttribute() throws Exception {
  81         JPackageHelper.executeCLI(true, CMD);
  82         validate();
  83     }
  84 
  85     private static void testMainClassAttributeToolProvider() throws Exception {
  86         JPackageHelper.deleteOutputFolder(OUTPUT);
  87         JPackageHelper.executeToolProvider(true, CMD);
  88         validate();
  89     }
  90 


  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 JPackageCreateAppImageMainClassAttributeTest
  35  */
  36 public class JPackageCreateAppImageMainClassAttributeTest {
  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[] CMD = {
  42         "--input", "input",
  43         "--output", OUTPUT,
  44         "--name", "test",
  45         "--main-jar", "hello.jar"};
  46 
  47     private static void validateResult(String[] result) throws Exception {
  48         if (result.length != 2) {
  49             throw new AssertionError(
  50                    "Unexpected number of lines: " + result.length);
  51         }
  52 
  53         if (!result[0].trim().equals("jpackage test application")) {
  54             throw new AssertionError("Unexpected result[0]: " + result[0]);
  55         }
  56 
  57         if (!result[1].trim().equals("args.length: 0")) {
  58             throw new AssertionError("Unexpected result[1]: " + result[1]);
  59         }
  60     }
  61 
  62     private static void validate() throws Exception {
  63         int retVal = JPackageHelper.execute(null, app);
  64         if (retVal != 0) {
  65             throw new AssertionError(
  66                    "Test application exited with error: " + retVal);
  67         }
  68 
  69         File outfile = new File(appOutput);
  70         if (!outfile.exists()) {
  71             throw new AssertionError(appOutput + " was not created");
  72         }
  73 
  74         String output = Files.readString(outfile.toPath());
  75         String[] result = output.split("\n");
  76         validateResult(result);
  77     }
  78 
  79     private static void testMainClassAttribute() throws Exception {
  80         JPackageHelper.executeCLI(true, CMD);
  81         validate();
  82     }
  83 
  84     private static void testMainClassAttributeToolProvider() throws Exception {
  85         JPackageHelper.deleteOutputFolder(OUTPUT);
  86         JPackageHelper.executeToolProvider(true, CMD);
  87         validate();
  88     }
  89 
< prev index next >