1 /*
   2  * Copyright (c) 2014, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.tools.packager;
  27 
  28 import org.junit.*;
  29 
  30 import java.io.File;
  31 
  32 public class CLITest {
  33 
  34     static File tmpBase;
  35     static File workDir;
  36     static File appResourcesDir;
  37     static File fakeMainJar;
  38 
  39     @BeforeClass
  40     public static void prepareApp() {
  41         Log.setLogger(new Log.Logger(true));
  42 
  43         String tmpBasePath = System.getProperty("tmpBase");
  44         if (tmpBasePath != null) {
  45             tmpBase = new File(System.getProperty("tmpBase"));
  46         } else {
  47             tmpBase = new File("build/tmp/tests");
  48         }
  49         tmpBase.mkdirs();
  50 
  51         workDir = new File(tmpBase, "cliapp");
  52         appResourcesDir = new File(tmpBase, "appResources");
  53         fakeMainJar = new File(appResourcesDir, "mainApp.jar");
  54     }
  55 
  56     @Test
  57     public void simpleTest() throws Exception {
  58         // on mac, require a full test
  59         Assume.assumeTrue(!System.getProperty("os.name").toLowerCase().contains("os x") || Boolean.parseBoolean(System.getProperty("FULL_TEST")));
  60 
  61         com.sun.javafx.tools.packager.Main.main("-deploy",
  62                 "-verbose", // verbose is required or test will call System.exit() on failures and break the build
  63                 "-srcfiles", fakeMainJar.getCanonicalPath(),
  64                 "-outdir", workDir.getCanonicalPath(),
  65                 "-outfile", "SimpleTest",
  66                 "-appclass", "hello.TestPackager",
  67                 "-native",
  68                 "-name", "SimpleTest");
  69     }
  70 
  71     @Test
  72     public void smokeParams() throws Exception {
  73         com.sun.javafx.tools.packager.Main.main("-deploy",
  74                 "-verbose", // verbose is required or test will call System.exit() on failures and break the build
  75                 "-srcfiles", fakeMainJar.getCanonicalPath(),
  76                 "-outdir", workDir.getCanonicalPath(),
  77                 "-outfile", "SimpleTest",
  78                 "-appclass", "hello.TestPackager",
  79                 "-native", "image",
  80                 "-name", "SimpleTest",
  81                 "-BOptionThatWillNeverExist=true",
  82                 "-BdesktopHint=false",
  83                 "-BshortcutHint=true",
  84                 "-Bruntime=" + System.getProperty("java.home"));
  85     }
  86 
  87     @Test(expected = PackagerException.class)
  88     public void duplicateNameClash() throws Exception {
  89         com.sun.javafx.tools.packager.Main.main("-deploy",
  90                 "-verbose", // verbose is required or test will call System.exit() on failures and break the build
  91                 "-srcfiles", fakeMainJar.getCanonicalPath(),
  92                 "-outdir", workDir.getCanonicalPath(),
  93                 "-outfile", "SimpleTest",
  94                 "-appclass", "hello.TestPackager",
  95                 "-native", "image",
  96                 "-name", "SimpleTest",
  97                 "-Bname=DuplicateTest");
  98     }
  99 
 100     @Test(expected = PackagerException.class)
 101     public void duplicateNameMatch() throws Exception {
 102         com.sun.javafx.tools.packager.Main.main("-deploy",
 103                 "-verbose", // verbose is required or test will call System.exit() on failures and break the build
 104                 "-srcfiles", fakeMainJar.getCanonicalPath(),
 105                 "-outdir", workDir.getCanonicalPath(),
 106                 "-outfile", "SimpleTest",
 107                 "-appclass", "hello.TestPackager",
 108                 "-native", "image",
 109                 "-name", "SimpleTest",
 110                 "-Bname=SimpleTest");
 111     }
 112 
 113 }