jdk/test/javax/security/auth/login/modules/JaasModularClientTest.java
author alanb
Thu, 17 Mar 2016 19:04:16 +0000
changeset 36511 9d0388c6b336
child 39774 25d5618feb3c
permissions -rw-r--r--
8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: alanb, mchung, naoto, rriggs, psandoz, plevart, mullan, ascarpino, vinnie, prr, sherman, dfuchs, mhaupt Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, chris.hegarty@oracle.com, alexandr.scherbatiy@oracle.com, amy.lu@oracle.com, calvin.cheung@oracle.com, daniel.fuchs@oracle.com, erik.joelsson@oracle.com, harold.seigel@oracle.com, jaroslav.bachorik@oracle.com, jean-francois.denise@oracle.com, jan.lahoda@oracle.com, james.laskey@oracle.com, lois.foltan@oracle.com, miroslav.kos@oracle.com, huaming.li@oracle.com, sean.mullan@oracle.com, naoto.sato@oracle.com, masayoshi.okutsu@oracle.com, peter.levart@gmail.com, philip.race@oracle.com, claes.redestad@oracle.com, sergey.bylokhov@oracle.com, alexandre.iline@oracle.com, volker.simonis@gmail.com, staffan.larsen@oracle.com, stuart.marks@oracle.com, semyon.sadetsky@oracle.com, serguei.spitsyn@oracle.com, sundararajan.athijegannathan@oracle.com, valerie.peng@oracle.com, vincent.x.ryan@oracle.com, weijun.wang@oracle.com, yuri.nesterenko@oracle.com, yekaterina.kantserova@oracle.com, alexander.kulyakhtin@oracle.com, felix.yang@oracle.com, andrei.eremeev@oracle.com, frank.yuan@oracle.com, sergei.pikalev@oracle.com, sibabrata.sahoo@oracle.com, tiantian.du@oracle.com, sha.jiang@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
import java.nio.file.Path;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
import java.nio.file.Paths;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
import java.util.LinkedHashMap;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import java.util.List;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.util.Map;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.util.Arrays;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.io.IOException;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import java.lang.module.ModuleDescriptor;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import java.util.ArrayList;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
import jdk.testlibrary.ProcessTools;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
import jdk.testlibrary.OutputAnalyzer;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
import org.testng.annotations.BeforeTest;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
 * @test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
 * @bug 8078813
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
 * @library /lib/testlibrary
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
 * @library /java/security/modules
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
 * @build CompilerUtils JarUtils
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
 * @summary Test custom JAAS module with all possible modular option. The test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
 *          includes different combination of JAAS client/login modules
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
 *          interaction with or without service description.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
 * @run testng JaasModularClientTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
public class JaasModularClientTest extends ModularTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
    private static final Path S_SRC = SRC.resolve("TestLoginModule.java");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
    private static final String S_PKG = "login";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
    private static final String S_JAR_NAME = S_PKG + JAR_EXTN;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
    private static final String S_DESCR_JAR_NAME = S_PKG + DESCRIPTOR
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
            + JAR_EXTN;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    private static final String MS_JAR_NAME = MODULAR + S_PKG + JAR_EXTN;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    private static final String MS_DESCR_JAR_NAME = MODULAR + S_PKG + DESCRIPTOR
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
            + JAR_EXTN;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
    private static final Path C_SRC = SRC.resolve("JaasClient.java");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
    private static final String C_PKG = "client";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
    private static final String C_JAR_NAME = C_PKG + JAR_EXTN;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
    private static final String MC_DEPENDS_ON_AUTO_SERVICE_JAR_NAME = MODULAR
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
            + C_PKG + AUTO + JAR_EXTN;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
    private static final String MC_JAR_NAME = MODULAR + C_PKG + JAR_EXTN;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
    private static final Path BUILD_DIR = Paths.get(".").resolve("build");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
    private static final Path COMPILE_DIR = BUILD_DIR.resolve("bin");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
    private static final Path S_BUILD_DIR = COMPILE_DIR.resolve(S_PKG);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
    private static final Path S_WITH_META_DESCR_BUILD_DIR = COMPILE_DIR.resolve(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
            S_PKG + DESCRIPTOR);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
    private static final Path C_BUILD_DIR = COMPILE_DIR.resolve(C_PKG);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
    private static final Path M_BASE_PATH = BUILD_DIR.resolve("mbase");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
    private static final Path ARTIFACTS_DIR = BUILD_DIR.resolve("artifacts");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
    private static final Path S_ARTIFACTS_DIR = ARTIFACTS_DIR.resolve(S_PKG);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
    private static final Path S_JAR = S_ARTIFACTS_DIR.resolve(S_JAR_NAME);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
    private static final Path S_WITH_DESCRIPTOR_JAR = S_ARTIFACTS_DIR.resolve(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
            S_DESCR_JAR_NAME);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
    private static final Path MS_JAR = S_ARTIFACTS_DIR.resolve(MS_JAR_NAME);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
    private static final Path MS_WITH_DESCR_JAR = S_ARTIFACTS_DIR.resolve(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
            MS_DESCR_JAR_NAME);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
    private static final Path C_ARTIFACTS_DIR = ARTIFACTS_DIR.resolve(C_PKG);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
    private static final Path C_JAR = C_ARTIFACTS_DIR.resolve(C_JAR_NAME);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
    private static final Path MC_JAR = C_ARTIFACTS_DIR.resolve(MC_JAR_NAME);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
    private static final Path MC_DEPENDS_ON_AUTO_SERVICE_JAR = C_ARTIFACTS_DIR
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
            .resolve(MC_DEPENDS_ON_AUTO_SERVICE_JAR_NAME);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
    private static final String MAIN = C_PKG + ".JaasClient";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
    private static final String S_INTERFACE
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
            = "javax.security.auth.spi.LoginModule";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
    private static final String S_IMPL = S_PKG + ".TestLoginModule";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
    private static final List<String> M_REQUIRED = Arrays.asList("java.base",
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
            "jdk.security.auth");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
    private static final Path META_DESCR_PATH = Paths.get("META-INF")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96
            .resolve("services").resolve(S_INTERFACE);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
    private static final Path S_META_DESCR_FPATH = S_WITH_META_DESCR_BUILD_DIR
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
            .resolve(META_DESCR_PATH);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
    private static final boolean WITH_S_DESCR = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
    private static final boolean WITHOUT_S_DESCR = false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
    private static final String LOGIN_MODULE_NOT_FOUND_MSG
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
            = "No LoginModule found";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   104
    private static final String NO_FAILURE = null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   105
    private static final Map<String, String> VM_ARGS = new LinkedHashMap<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
     * Generates Test specific input parameters.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
    public Object[][] getTestInput() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
        List<List<Object>> params = new ArrayList<>();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        String[] args = new String[]{};
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
        //PARAMETER ORDERS -
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
        //client Module Type, Service Module Type,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
        //Service META Descriptor Required,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
        //Expected Failure message, mechanism used to find the provider
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
        params.add(Arrays.asList(MODULE_TYPE.EXPLICIT, MODULE_TYPE.EXPLICIT,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
                WITH_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
        params.add(Arrays.asList(MODULE_TYPE.EXPLICIT, MODULE_TYPE.EXPLICIT,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
                WITHOUT_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
        params.add(Arrays.asList(MODULE_TYPE.EXPLICIT, MODULE_TYPE.AUTO,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
                WITH_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
        params.add(Arrays.asList(MODULE_TYPE.EXPLICIT, MODULE_TYPE.AUTO,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
                WITHOUT_S_DESCR, LOGIN_MODULE_NOT_FOUND_MSG, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
        params.add(Arrays.asList(MODULE_TYPE.EXPLICIT, MODULE_TYPE.UNNAMED,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
                WITH_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
        params.add(Arrays.asList(MODULE_TYPE.EXPLICIT, MODULE_TYPE.UNNAMED,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
                WITHOUT_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
        params.add(Arrays.asList(MODULE_TYPE.AUTO, MODULE_TYPE.EXPLICIT,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
                WITH_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
        params.add(Arrays.asList(MODULE_TYPE.AUTO, MODULE_TYPE.EXPLICIT,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
                WITHOUT_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
        params.add(Arrays.asList(MODULE_TYPE.AUTO, MODULE_TYPE.AUTO,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
                WITH_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
        params.add(Arrays.asList(MODULE_TYPE.AUTO, MODULE_TYPE.AUTO,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
                WITHOUT_S_DESCR, LOGIN_MODULE_NOT_FOUND_MSG, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
        params.add(Arrays.asList(MODULE_TYPE.AUTO, MODULE_TYPE.UNNAMED,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
                WITH_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
        params.add(Arrays.asList(MODULE_TYPE.AUTO, MODULE_TYPE.UNNAMED,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
                WITHOUT_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
        params.add(Arrays.asList(MODULE_TYPE.UNNAMED, MODULE_TYPE.EXPLICIT,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
                WITH_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
        params.add(Arrays.asList(MODULE_TYPE.UNNAMED, MODULE_TYPE.EXPLICIT,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
                WITHOUT_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
        params.add(Arrays.asList(MODULE_TYPE.UNNAMED, MODULE_TYPE.AUTO,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
                WITH_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
        params.add(Arrays.asList(MODULE_TYPE.UNNAMED, MODULE_TYPE.AUTO,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
                WITHOUT_S_DESCR, LOGIN_MODULE_NOT_FOUND_MSG, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
        params.add(Arrays.asList(MODULE_TYPE.UNNAMED, MODULE_TYPE.UNNAMED,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
                WITH_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
        params.add(Arrays.asList(MODULE_TYPE.UNNAMED, MODULE_TYPE.UNNAMED,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
                WITHOUT_S_DESCR, NO_FAILURE, args));
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
        return params.stream().map(p -> p.toArray()).toArray(Object[][]::new);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
     * Pre-compile and generate the artifacts required to run this test before
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
     * running each test cases.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
    @BeforeTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
    public void buildArtifacts() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
        boolean done = true;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
            VM_ARGS.put("-Duser.language=", "en");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
            VM_ARGS.put("-Duser.region", "US");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
            VM_ARGS.put("-Djava.security.auth.login.config=", SRC.resolve(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
                    "jaas.conf").toFile().getCanonicalPath());
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
            done = CompilerUtils.compile(S_SRC, S_BUILD_DIR);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   175
            done &= CompilerUtils.compile(S_SRC, S_WITH_META_DESCR_BUILD_DIR);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   176
            done &= createMetaInfServiceDescriptor(S_META_DESCR_FPATH, S_IMPL);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   177
            //Generate regular/modular jars with(out) META-INF
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   178
            //service descriptor
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   179
            generateJar(true, MODULE_TYPE.EXPLICIT, MS_JAR, S_BUILD_DIR, false);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
            generateJar(true, MODULE_TYPE.EXPLICIT, MS_WITH_DESCR_JAR,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
                    S_WITH_META_DESCR_BUILD_DIR, false);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
            generateJar(true, MODULE_TYPE.UNNAMED, S_JAR, S_BUILD_DIR, false);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
            generateJar(true, MODULE_TYPE.UNNAMED, S_WITH_DESCRIPTOR_JAR,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
                    S_WITH_META_DESCR_BUILD_DIR, false);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
            //Generate regular/modular(depends on explicit/auto service)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   186
            //jars for client
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
            done &= CompilerUtils.compile(C_SRC, C_BUILD_DIR);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
            generateJar(false, MODULE_TYPE.EXPLICIT, MC_JAR, C_BUILD_DIR, true);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
            generateJar(false, MODULE_TYPE.EXPLICIT,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
                    MC_DEPENDS_ON_AUTO_SERVICE_JAR, C_BUILD_DIR, false);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
            generateJar(false, MODULE_TYPE.UNNAMED, C_JAR, C_BUILD_DIR, false);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
            System.out.format("%nArtifacts generated successfully? %s", done);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
            if (!done) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   194
                throw new RuntimeException("Artifact generation failed");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   195
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   196
        } catch (IOException e) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   197
            throw new RuntimeException(e);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   199
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   201
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   202
     * Generate modular/regular jar based on module type for this test.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   203
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   204
    private void generateJar(boolean isService, MODULE_TYPE moduleType,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   205
            Path jar, Path compilePath, boolean depends) throws IOException {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   206
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   207
        ModuleDescriptor mDescriptor = null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   208
        if (isService) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   209
            mDescriptor = generateModuleDescriptor(isService, moduleType, S_PKG,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   210
                    S_PKG, S_INTERFACE, S_IMPL, null, M_REQUIRED, depends);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   211
        } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   212
            mDescriptor = generateModuleDescriptor(isService, moduleType, C_PKG,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   213
                    C_PKG, S_INTERFACE, null, S_PKG, M_REQUIRED, depends);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   214
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   215
        generateJar(mDescriptor, jar, compilePath);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   216
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   217
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   218
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   219
     * Holds Logic for the test client. This method will get called with each
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   220
     * test parameter.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   221
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   222
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   223
    public OutputAnalyzer executeTestClient(MODULE_TYPE cModuleType,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   224
            Path cJarPath, MODULE_TYPE sModuletype, Path sJarPath,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   225
            String... args) throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   226
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   227
        OutputAnalyzer output = null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   228
        try {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   229
            //For automated/explicit module type copy the corresponding
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   230
            //jars to module base folder, which will be considered as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   231
            //module base path during execution.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   232
            if (!(cModuleType == MODULE_TYPE.UNNAMED
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   233
                    && sModuletype == MODULE_TYPE.UNNAMED)) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   234
                copyJarsToModuleBase(cModuleType, cJarPath, M_BASE_PATH);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   235
                copyJarsToModuleBase(sModuletype, sJarPath, M_BASE_PATH);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   236
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   237
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   238
            System.out.format("%nExecuting java client with required"
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   239
                    + " custom service in class/module path.");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   240
            String mName = getModuleName(cModuleType, cJarPath,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   241
                    C_PKG);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   242
            Path cmBasePath = (cModuleType != MODULE_TYPE.UNNAMED
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   243
                    || sModuletype != MODULE_TYPE.UNNAMED) ? M_BASE_PATH : null;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   244
            String cPath = buildClassPath(cModuleType, cJarPath, sModuletype,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   245
                    sJarPath);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   246
            output = ProcessTools.executeTestJava(
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   247
                    getJavaCommand(cmBasePath, cPath, mName, MAIN, VM_ARGS,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   248
                            args)).outputTo(System.out).errorTo(System.out);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   249
        } finally {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   250
            //clean module path so that the modulepath can hold only
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   251
            //the required jars for next run.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   252
            cleanModuleBasePath(M_BASE_PATH);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   253
            System.out.println("--------------------------------------------");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   254
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   255
        return output;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   256
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   257
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   258
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   259
     * Decide the pre-generated client/service jar path for each test case
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   260
     * based on client/service module type.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   261
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   262
    @Override
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   263
    public Path findJarPath(boolean service, MODULE_TYPE moduleType,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   264
            boolean addMetaDesc, boolean dependsOnServiceModule) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   265
        if (service) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   266
            if (moduleType == MODULE_TYPE.EXPLICIT) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   267
                if (addMetaDesc) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   268
                    return MS_WITH_DESCR_JAR;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   269
                } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   270
                    return MS_JAR;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   271
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   272
            } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   273
                if (addMetaDesc) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   274
                    return S_WITH_DESCRIPTOR_JAR;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   275
                } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   276
                    return S_JAR;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   277
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   278
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   279
        } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   280
            if (moduleType == MODULE_TYPE.EXPLICIT) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   281
                if (dependsOnServiceModule) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   282
                    return MC_JAR;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   283
                } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   284
                    return MC_DEPENDS_ON_AUTO_SERVICE_JAR;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   285
                }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   286
            } else {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   287
                return C_JAR;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   288
            }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   289
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   290
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   291
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   292
}