< prev index next >

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

Print this page




  18  *
  19  * You should have received a copy of the GNU General Public License version
  20  * 2 along with this work; if not, write to the Free Software Foundation,
  21  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  22  *
  23  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  24  * or visit www.oracle.com if you need additional information or have any
  25  * questions.
  26  */
  27 
  28 /*
  29  * @test
  30  * @summary jpackage create image --app-version test
  31  * @library ../helpers
  32  * @build JPackageHelper
  33  * @build JPackagePath
  34  * @modules jdk.jpackage
  35  * @run main/othervm -Xmx512m JPackageCreateImageVersionTest
  36  */
  37 public class JPackageCreateImageVersionTest {

  38     private static final String appCfg = JPackagePath.getAppCfg();
  39     private static final String VERSION = "2.3";
  40     private static final String VERSION_DEFAULT = "1.0";
  41 
  42     private static final String[] CMD = {
  43         "create-image",
  44         "--input", "input",
  45         "--output", "output",
  46         "--name", "test",
  47         "--main-jar", "hello.jar",
  48         "--main-class", "Hello",
  49         "--overwrite",
  50         "--files", "hello.jar"};
  51 
  52     private static final String[] CMD_VERSION = {
  53         "create-image",
  54         "--input", "input",
  55         "--output", "output",
  56         "--name", "test",
  57         "--main-jar", "hello.jar",
  58         "--main-class", "Hello",
  59         "--files", "hello.jar",
  60         "--overwrite",
  61         "--app-version", VERSION};
  62 
  63     private static void validate(String version)
  64             throws Exception {
  65         File outfile = new File(appCfg);
  66         if (!outfile.exists()) {
  67             throw new AssertionError(appCfg + " was not created");
  68         }
  69 
  70         String output = Files.readString(outfile.toPath());
  71         if (version == null) {
  72             version = VERSION_DEFAULT;
  73         }
  74 
  75         String expected = "app.version=" + version;
  76         if (!output.contains(expected)) {
  77             System.err.println("Expected: " + expected);
  78             throw new AssertionError("Cannot find expected entry in config file");
  79         }
  80     }
  81 
  82     private static void testVersion() throws Exception {
  83         JPackageHelper.executeCLI(true, CMD);
  84         validate(null);

  85         JPackageHelper.executeCLI(true, CMD_VERSION);
  86         validate(VERSION);
  87     }
  88 
  89     private static void testVersionToolProvider() throws Exception {

  90         JPackageHelper.executeToolProvider(true, CMD);
  91         validate(null);

  92         JPackageHelper.executeToolProvider(true, CMD_VERSION);
  93         validate(VERSION);
  94     }
  95 
  96     public static void main(String[] args) throws Exception {
  97         JPackageHelper.createHelloImageJar();
  98         testVersion();
  99         testVersionToolProvider();
 100     }
 101 
 102 }


  18  *
  19  * You should have received a copy of the GNU General Public License version
  20  * 2 along with this work; if not, write to the Free Software Foundation,
  21  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  22  *
  23  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  24  * or visit www.oracle.com if you need additional information or have any
  25  * questions.
  26  */
  27 
  28 /*
  29  * @test
  30  * @summary jpackage create image --app-version test
  31  * @library ../helpers
  32  * @build JPackageHelper
  33  * @build JPackagePath
  34  * @modules jdk.jpackage
  35  * @run main/othervm -Xmx512m JPackageCreateImageVersionTest
  36  */
  37 public class JPackageCreateImageVersionTest {
  38     private static final String OUTPUT = "output";
  39     private static final String appCfg = JPackagePath.getAppCfg();
  40     private static final String VERSION = "2.3";
  41     private static final String VERSION_DEFAULT = "1.0";
  42 
  43     private static final String[] CMD = {
  44         "create-image",
  45         "--input", "input",
  46         "--output", OUTPUT,
  47         "--name", "test",
  48         "--main-jar", "hello.jar",
  49         "--main-class", "Hello",

  50         "--files", "hello.jar"};
  51 
  52     private static final String[] CMD_VERSION = {
  53         "create-image",
  54         "--input", "input",
  55         "--output", OUTPUT,
  56         "--name", "test",
  57         "--main-jar", "hello.jar",
  58         "--main-class", "Hello",
  59         "--files", "hello.jar",

  60         "--app-version", VERSION};
  61 
  62     private static void validate(String version)
  63             throws Exception {
  64         File outfile = new File(appCfg);
  65         if (!outfile.exists()) {
  66             throw new AssertionError(appCfg + " was not created");
  67         }
  68 
  69         String output = Files.readString(outfile.toPath());
  70         if (version == null) {
  71             version = VERSION_DEFAULT;
  72         }
  73 
  74         String expected = "app.version=" + version;
  75         if (!output.contains(expected)) {
  76             System.err.println("Expected: " + expected);
  77             throw new AssertionError("Cannot find expected entry in config file");
  78         }
  79     }
  80 
  81     private static void testVersion() throws Exception {
  82         JPackageHelper.executeCLI(true, CMD);
  83         validate(null);
  84         JPackageHelper.deleteOutputFolder(OUTPUT);
  85         JPackageHelper.executeCLI(true, CMD_VERSION);
  86         validate(VERSION);
  87     }
  88 
  89     private static void testVersionToolProvider() throws Exception {
  90         JPackageHelper.deleteOutputFolder(OUTPUT);
  91         JPackageHelper.executeToolProvider(true, CMD);
  92         validate(null);
  93         JPackageHelper.deleteOutputFolder(OUTPUT);
  94         JPackageHelper.executeToolProvider(true, CMD_VERSION);
  95         validate(VERSION);
  96     }
  97 
  98     public static void main(String[] args) throws Exception {
  99         JPackageHelper.createHelloImageJar();
 100         testVersion();
 101         testVersionToolProvider();
 102     }
 103 
 104 }
< prev index next >