< prev index next >

test/jdk/tools/jpackage/createimage/JPackageCreateImageInputFilesTest.java

Print this page




  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.BufferedWriter;
  25 import java.io.File;
  26 import java.io.FileWriter;
  27 import java.io.PrintWriter;
  28 
  29  /*
  30  * @test
  31  * @summary jpackage create image input/files test
  32  * @library ../helpers
  33  * @build JPackageHelper
  34  * @build JPackagePath
  35  * @modules jdk.jpackage
  36  * @run main/othervm -Xmx512m JPackageCreateImageInputFilesTest
  37  */
  38 public class JPackageCreateImageInputFilesTest {

  39     private static final String inputFile =
  40             "input" + File.separator + "input.txt";
  41     private static final String jarFile =
  42             "input" + File.separator + "hello.jar";
  43     private static final String appInputFilePath;
  44     private static final String appJarFilePath;
  45 
  46     static {
  47         appInputFilePath = JPackagePath.getAppWorkingDir() + File.separator + "input.txt";
  48         appJarFilePath = JPackagePath.getAppWorkingDir() + File.separator + "hello.jar";
  49     }
  50 
  51     private static final String [] CMD_1 = {
  52         "create-image",
  53         "--input", "input",
  54         "--output", "output",
  55         "--name", "test",
  56         "--main-jar", "hello.jar",
  57         "--overwrite",
  58         "--main-class", "Hello"};
  59 
  60     private static final String [] CMD_2 = {
  61         "create-image",
  62         "--input", "input",
  63         "--output", "output",
  64         "--name", "test",
  65         "--main-jar", "hello.jar",
  66         "--main-class", "Hello",
  67         "--overwrite",
  68         "--files", "hello.jar"};
  69 
  70     private static void validate1() throws Exception {
  71         File input = new File(appInputFilePath);
  72         if (!input.exists()) {
  73             throw new AssertionError("Unexpected file does not exist: "
  74                     + input.getAbsolutePath());
  75         }
  76 
  77         File jar = new File(appJarFilePath);
  78         if (!jar.exists()) {
  79             throw new AssertionError("Unexpected file does not exist: "
  80                     + jar.getAbsolutePath());
  81         }
  82     }
  83 
  84     private static void validate2() throws Exception {
  85         File input = new File(appInputFilePath);
  86         if (input.exists()) {
  87             throw new AssertionError("Unexpected file exist: "
  88                     + input.getAbsolutePath());
  89         }
  90 
  91         File jar = new File(appJarFilePath);
  92         if (!jar.exists()) {
  93             throw new AssertionError("Unexpected file does not exist: "
  94                     + jar.getAbsolutePath());
  95         }
  96     }
  97 
  98     private static void testCreateImage() throws Exception {
  99         JPackageHelper.executeCLI(true, CMD_1);
 100         validate1();
 101 

 102         JPackageHelper.executeCLI(true, CMD_2);
 103         validate2();
 104     }
 105 
 106     private static void testCreateImageToolProvider() throws Exception {

 107         JPackageHelper.executeToolProvider(true, CMD_1);
 108         validate1();
 109 

 110         JPackageHelper.executeToolProvider(true, CMD_2);
 111         validate2();
 112     }
 113 
 114     private static void createInputFile() throws Exception {
 115         try (PrintWriter out = new PrintWriter(
 116                 new BufferedWriter(new FileWriter(inputFile)))) {
 117             out.println("jpackgaer resource file");
 118         }
 119     }
 120 
 121     public static void main(String[] args) throws Exception {
 122         JPackageHelper.createHelloImageJar();
 123 
 124         createInputFile();
 125 
 126         testCreateImage();
 127         testCreateImageToolProvider();
 128     }
 129 


  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.BufferedWriter;
  25 import java.io.File;
  26 import java.io.FileWriter;
  27 import java.io.PrintWriter;
  28 
  29  /*
  30  * @test
  31  * @summary jpackage create image input/files test
  32  * @library ../helpers
  33  * @build JPackageHelper
  34  * @build JPackagePath
  35  * @modules jdk.jpackage
  36  * @run main/othervm -Xmx512m JPackageCreateImageInputFilesTest
  37  */
  38 public class JPackageCreateImageInputFilesTest {
  39     private static final String OUTPUT = "output";
  40     private static final String inputFile =
  41             "input" + File.separator + "input.txt";
  42     private static final String jarFile =
  43             "input" + File.separator + "hello.jar";
  44     private static final String appInputFilePath;
  45     private static final String appJarFilePath;
  46 
  47     static {
  48         appInputFilePath = JPackagePath.getAppWorkingDir() + File.separator + "input.txt";
  49         appJarFilePath = JPackagePath.getAppWorkingDir() + File.separator + "hello.jar";
  50     }
  51 
  52     private static final String [] CMD_1 = {
  53         "create-image",
  54         "--input", "input",
  55         "--output", OUTPUT,
  56         "--name", "test",
  57         "--main-jar", "hello.jar",

  58         "--main-class", "Hello"};
  59 
  60     private static final String [] CMD_2 = {
  61         "create-image",
  62         "--input", "input",
  63         "--output", OUTPUT,
  64         "--name", "test",
  65         "--main-jar", "hello.jar",
  66         "--main-class", "Hello",

  67         "--files", "hello.jar"};
  68 
  69     private static void validate1() throws Exception {
  70         File input = new File(appInputFilePath);
  71         if (!input.exists()) {
  72             throw new AssertionError("Unexpected file does not exist: "
  73                     + input.getAbsolutePath());
  74         }
  75 
  76         File jar = new File(appJarFilePath);
  77         if (!jar.exists()) {
  78             throw new AssertionError("Unexpected file does not exist: "
  79                     + jar.getAbsolutePath());
  80         }
  81     }
  82 
  83     private static void validate2() throws Exception {
  84         File input = new File(appInputFilePath);
  85         if (input.exists()) {
  86             throw new AssertionError("Unexpected file exist: "
  87                     + input.getAbsolutePath());
  88         }
  89 
  90         File jar = new File(appJarFilePath);
  91         if (!jar.exists()) {
  92             throw new AssertionError("Unexpected file does not exist: "
  93                     + jar.getAbsolutePath());
  94         }
  95     }
  96 
  97     private static void testCreateImage() throws Exception {
  98         JPackageHelper.executeCLI(true, CMD_1);
  99         validate1();
 100 
 101         JPackageHelper.deleteOutputFolder(OUTPUT);
 102         JPackageHelper.executeCLI(true, CMD_2);
 103         validate2();
 104     }
 105 
 106     private static void testCreateImageToolProvider() throws Exception {
 107         JPackageHelper.deleteOutputFolder(OUTPUT);
 108         JPackageHelper.executeToolProvider(true, CMD_1);
 109         validate1();
 110 
 111         JPackageHelper.deleteOutputFolder(OUTPUT);
 112         JPackageHelper.executeToolProvider(true, CMD_2);
 113         validate2();
 114     }
 115 
 116     private static void createInputFile() throws Exception {
 117         try (PrintWriter out = new PrintWriter(
 118                 new BufferedWriter(new FileWriter(inputFile)))) {
 119             out.println("jpackgaer resource file");
 120         }
 121     }
 122 
 123     public static void main(String[] args) throws Exception {
 124         JPackageHelper.createHelloImageJar();
 125 
 126         createInputFile();
 127 
 128         testCreateImage();
 129         testCreateImageToolProvider();
 130     }
 131 
< prev index next >