test/jdk/tools/jpackage/windows/base/WinUpgradeUUIDBase.java
branchJDK-8200758-branch
changeset 57446 5a5b85f00a63
parent 57414 6eda749d3117
equal deleted inserted replaced
57445:405ddd80496e 57446:5a5b85f00a63
       
     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.BufferedWriter;
       
    25 import java.io.File;
       
    26 import java.io.FileWriter;
       
    27 import java.io.PrintWriter;
       
    28 import java.util.ArrayList;
       
    29 import java.util.List;
       
    30 
       
    31 public class WinUpgradeUUIDBase {
       
    32 
       
    33     private static String TEST_NAME;
       
    34     private static String EXT;
       
    35     private static String OUTPUT_1;
       
    36     private static String[] CMD_1;
       
    37     private static String OUTPUT_2;
       
    38     private static String[] CMD_2;
       
    39     private static final String FILE_1 = "file1.txt";
       
    40     private static final String FILE_2 = "file2.txt";
       
    41 
       
    42     private static void copyResults() throws Exception {
       
    43         List<String> files = new ArrayList<>();
       
    44         files.add(OUTPUT_1);
       
    45         files.add(OUTPUT_2);
       
    46         JPackageInstallerHelper.copyTestResults(files);
       
    47     }
       
    48 
       
    49     private static void testCreateInstaller() throws Exception {
       
    50         JPackageHelper.executeCLI(true, CMD_1);
       
    51         JPackageInstallerHelper.validateOutput(OUTPUT_1);
       
    52         JPackageHelper.executeCLI(true, CMD_2);
       
    53         JPackageInstallerHelper.validateOutput(OUTPUT_2);
       
    54         copyResults();
       
    55     }
       
    56 
       
    57     private static void verifyInstall() throws Exception {
       
    58         String app = JPackagePath.getWinInstalledApp(TEST_NAME);
       
    59         JPackageInstallerHelper.validateApp(app);
       
    60 
       
    61         String file1Path = JPackagePath.getWinInstalledAppFolder(TEST_NAME) + File.separator + FILE_1;
       
    62         File file1 = new File(file1Path);
       
    63         if (EXT.equals("msi")) {
       
    64             if (file1.exists()) {
       
    65                 throw new AssertionError("Unexpected file does exist: "
       
    66                         + file1.getAbsolutePath());
       
    67             }
       
    68         } else if (EXT.equals("exe")) {
       
    69             if (!file1.exists()) {
       
    70                 throw new AssertionError("Unexpected file does not exist: "
       
    71                     + file1.getAbsolutePath());
       
    72             }
       
    73         } else {
       
    74             throw new AssertionError("Unknown installer type: " + EXT);
       
    75         }
       
    76 
       
    77         String file2Path = JPackagePath.getWinInstalledAppFolder(TEST_NAME) + File.separator + FILE_2;
       
    78         File file2 = new File(file2Path);
       
    79         if (!file2.exists()) {
       
    80             throw new AssertionError("Unexpected file does not exist: "
       
    81                     + file2.getAbsolutePath());
       
    82         }
       
    83     }
       
    84 
       
    85     private static void verifyUnInstall() throws Exception {
       
    86         String folderPath = JPackagePath.getWinInstallFolder(TEST_NAME);
       
    87         File folder = new File(folderPath);
       
    88         if (folder.exists()) {
       
    89             throw new AssertionError("Error: " + folder.getAbsolutePath() + " exist");
       
    90         }
       
    91     }
       
    92 
       
    93     private static void init(String name, String ext) {
       
    94         TEST_NAME = name;
       
    95         EXT = ext;
       
    96         OUTPUT_1 = "output" + File.separator + TEST_NAME + "-1.0." + EXT;
       
    97         CMD_1 = new String[]{
       
    98             "--package-type", EXT,
       
    99             "--input", "input",
       
   100             "--output", "output",
       
   101             "--name", TEST_NAME,
       
   102             "--main-jar", "hello.jar",
       
   103             "--main-class", "Hello",
       
   104             "--app-version", "1.0",
       
   105             "--win-upgrade-uuid", "F0B18E75-52AD-41A2-BC86-6BE4FCD50BEB"};
       
   106         OUTPUT_2 = "output" + File.separator + TEST_NAME + "-2.0." + EXT;
       
   107         CMD_2 = new String[]{
       
   108             "--package-type", EXT,
       
   109             "--input", "input",
       
   110             "--output", "output",
       
   111             "--name", TEST_NAME,
       
   112             "--main-jar", "hello.jar",
       
   113             "--main-class", "Hello",
       
   114             "--app-version", "2.0",
       
   115             "--win-upgrade-uuid", "F0B18E75-52AD-41A2-BC86-6BE4FCD50BEB"};
       
   116     }
       
   117 
       
   118     private static void createInputFile(String name, String context) throws Exception {
       
   119         try (PrintWriter out = new PrintWriter(
       
   120                 new BufferedWriter(new FileWriter("input" + File.separator + name)))) {
       
   121             out.println(context);
       
   122         }
       
   123     }
       
   124 
       
   125     public static void run(String name, String ext) throws Exception {
       
   126         init(name, ext);
       
   127 
       
   128         if (JPackageInstallerHelper.isVerifyInstall()) {
       
   129             verifyInstall();
       
   130         } else if (JPackageInstallerHelper.isVerifyUnInstall()) {
       
   131             verifyUnInstall();
       
   132         } else {
       
   133             JPackageHelper.createHelloInstallerJar();
       
   134             createInputFile(FILE_1, FILE_1);
       
   135             createInputFile(FILE_2, FILE_2);
       
   136             testCreateInstaller();
       
   137         }
       
   138     }
       
   139 }