test/jdk/tools/jpackager/createimage/JPackagerCreateImageSecondaryLauncherBase.java
author herrick
Wed, 21 Nov 2018 13:20:52 -0500
branchJDK-8200758-branch
changeset 57031 ea4755429ed8
permissions -rw-r--r--
8214021: Create additional automated tests for jpackager Submitten-by: almatvee Reviewed-by: herrick. kcr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57031
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     1
/*
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     4
 *
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     8
 *
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    13
 * accompanied this code).
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    14
 *
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    18
 *
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    21
 * questions.
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    22
 */
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    23
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    24
import java.io.BufferedWriter;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    25
import java.io.File;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    26
import java.io.FileWriter;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    27
import java.io.PrintWriter;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    28
import java.nio.file.Files;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    29
import java.util.ArrayList;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    30
import java.util.List;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    31
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    32
public class JPackagerCreateImageSecondaryLauncherBase {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    33
    private static final String app = JPackagerPath.getApp();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    34
    private static final String app2 = JPackagerPath.getAppSL();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    35
    private static final String appOutput = JPackagerPath.getAppOutputFile();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    36
    private static final String appWorkingDir = JPackagerPath.getAppWorkingDir();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    37
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    38
    // Note: quotes in argument for secondary launcher is not support by test
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    39
    private static final String ARGUMENT1 = "argument 1";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    40
    private static final String ARGUMENT2 = "argument 2";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    41
    private static final String ARGUMENT3 = "argument 3";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    42
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    43
    private static final List<String> arguments = new ArrayList<>();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    44
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    45
    private static final String PARAM1 = "-Dparam1=Some Param 1";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    46
    private static final String PARAM2 = "-Dparam2=Some Param 2";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    47
    private static final String PARAM3 = "-Dparam3=Some Param 3";
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    48
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    49
    private static final List<String> vmArguments = new ArrayList<>();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    50
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    51
    private static void validateResult(List<String> args, List<String> vmArgs)
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    52
            throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    53
        File outfile = new File(appWorkingDir + File.separator + appOutput);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    54
        if (!outfile.exists()) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    55
            throw new AssertionError(appOutput + " was not created");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    56
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    57
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    58
        String output = Files.readString(outfile.toPath());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    59
        String[] result = output.split("\n");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    60
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    61
        if (result.length != (args.size() + vmArgs.size() + 2)) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    62
            throw new AssertionError("Unexpected number of lines: "
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    63
                    + result.length);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    64
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    65
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    66
        if (!result[0].trim().equals("jpackager test application")) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    67
            throw new AssertionError("Unexpected result[0]: " + result[0]);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    68
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    69
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    70
        if (!result[1].trim().equals("args.length: " + args.size())) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    71
            throw new AssertionError("Unexpected result[1]: " + result[1]);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    72
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    73
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    74
        int index = 2;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    75
        for (String arg : args) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    76
            if (!result[index].trim().equals(arg)) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    77
                throw new AssertionError("Unexpected result[" + index + "]: "
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    78
                    + result[index]);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    79
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    80
            index++;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    81
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    82
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    83
        for (String vmArg : vmArgs) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    84
            if (!result[index].trim().equals(vmArg)) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    85
                throw new AssertionError("Unexpected result[" + index + "]: "
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    86
                    + result[index]);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    87
            }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    88
            index++;
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    89
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    90
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    91
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    92
    private static void validate() throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    93
        int retVal = JPackagerHelper.execute(null, app);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    94
        if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    95
            throw new AssertionError("Test application exited with error: "
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    96
                    + retVal);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    97
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    98
        validateResult(new ArrayList<>(), new ArrayList<>());
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
    99
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   100
        retVal = JPackagerHelper.execute(null, app2);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   101
        if (retVal != 0) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   102
            throw new AssertionError("Test application exited with error: "
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   103
                    + retVal);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   104
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   105
        validateResult(arguments, vmArguments);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   106
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   107
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   108
    public static void testCreateImage(String [] cmd) throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   109
        JPackagerHelper.executeCLI(true, cmd);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   110
        validate();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   111
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   112
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   113
    public static void testCreateImageToolProvider(String [] cmd) throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   114
        JPackagerHelper.executeToolProvider(true, cmd);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   115
        validate();
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   116
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   117
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   118
    public static void createSLProperties() throws Exception {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   119
        arguments.add(ARGUMENT1);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   120
        arguments.add(ARGUMENT2);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   121
        arguments.add(ARGUMENT3);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   122
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   123
        String argumentsMap =
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   124
                JPackagerHelper.listToArgumentsMap(arguments, true);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   125
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   126
        vmArguments.add(PARAM1);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   127
        vmArguments.add(PARAM2);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   128
        vmArguments.add(PARAM3);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   129
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   130
        String vmArgumentsMap =
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   131
                JPackagerHelper.listToArgumentsMap(vmArguments, true);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   132
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   133
        try (PrintWriter out = new PrintWriter(new BufferedWriter(
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   134
                new FileWriter("sl.properties")))) {
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   135
            out.println("name=test2");
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   136
            out.println("arguments=" + argumentsMap);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   137
            out.println("jvm-args=" + vmArgumentsMap);
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   138
        }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   139
    }
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   140
ea4755429ed8 8214021: Create additional automated tests for jpackager
herrick
parents:
diff changeset
   141
}