test/jdk/tools/jpackage/windows/base/InstallDirBase.java
branchJDK-8200758-branch
changeset 58113 885b0543f6e4
parent 58037 c127c766fe8e
child 58114 42df7de58e39
equal deleted inserted replaced
58037:c127c766fe8e 58113:885b0543f6e4
     1 /*
       
     2  * Copyright (c) 2019, 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.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    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.File;
       
    25 import java.util.ArrayList;
       
    26 import java.util.List;
       
    27 
       
    28 public class InstallDirBase {
       
    29 
       
    30     private static String TEST_NAME;
       
    31     private static String EXT;
       
    32     private static String OUTPUT;
       
    33     private static String[] CMD;
       
    34     private static String INSTALL_DIR;
       
    35 
       
    36     private static void copyResults() throws Exception {
       
    37         List<String> files = new ArrayList<>();
       
    38         files.add(OUTPUT);
       
    39         JPackageInstallerHelper.copyTestResults(files);
       
    40     }
       
    41 
       
    42     private static void testCreateInstaller() throws Exception {
       
    43         JPackageHelper.executeCLI(true, CMD);
       
    44         JPackageInstallerHelper.validateOutput(OUTPUT);
       
    45         copyResults();
       
    46     }
       
    47 
       
    48     private static void verifyInstall() throws Exception {
       
    49         String app = JPackagePath.getWinInstalledApp(INSTALL_DIR, TEST_NAME);
       
    50         JPackageInstallerHelper.validateApp(app);
       
    51 
       
    52         // Validate start menu
       
    53         JPackageInstallerHelper.validateStartMenu("Unknown", TEST_NAME, false);
       
    54 
       
    55         // Validate desktop shortcut
       
    56         JPackageInstallerHelper.validateDesktopShortcut(TEST_NAME, true);
       
    57     }
       
    58 
       
    59     private static void verifyUnInstall() throws Exception {
       
    60         String folderPath = JPackagePath.getWinInstallFolder(INSTALL_DIR);
       
    61         File folder = new File(folderPath);
       
    62         if (folder.exists()) {
       
    63             throw new AssertionError("Error: " + folder.getAbsolutePath() + " exist");
       
    64         }
       
    65 
       
    66         // Validate start menu
       
    67         JPackageInstallerHelper.validateStartMenu("Unknown", TEST_NAME, false);
       
    68 
       
    69         // Validate desktop shortcut
       
    70         JPackageInstallerHelper.validateDesktopShortcut(TEST_NAME, false);
       
    71     }
       
    72 
       
    73     private static void init(String name, String ext) {
       
    74         TEST_NAME = name;
       
    75         EXT = ext;
       
    76         OUTPUT = "output" + File.separator + TEST_NAME + "-1.0." + EXT;
       
    77         INSTALL_DIR = "TestVendor" + File.separator + TEST_NAME;
       
    78         CMD = new String[]{
       
    79             "--package-type", EXT,
       
    80             "--input", "input",
       
    81             "--output", "output",
       
    82             "--name", TEST_NAME,
       
    83             "--main-jar", "hello.jar",
       
    84             "--main-class", "Hello",
       
    85             "--install-dir", INSTALL_DIR,
       
    86             "--win-shortcut"};
       
    87     }
       
    88 
       
    89     public static void run(String name, String ext) throws Exception {
       
    90         init(name, ext);
       
    91 
       
    92         if (JPackageInstallerHelper.isVerifyInstall()) {
       
    93             verifyInstall();
       
    94         } else if (JPackageInstallerHelper.isVerifyUnInstall()) {
       
    95             verifyUnInstall();
       
    96         } else {
       
    97             JPackageHelper.createHelloInstallerJar();
       
    98             testCreateInstaller();
       
    99         }
       
   100     }
       
   101 }