jdk/test/java/util/ServiceLoader/modules/BadProvidersTest.java
author alanb
Fri, 10 Feb 2017 09:04:39 +0000
changeset 43712 5dfd0950317c
parent 42338 a60f280f803c
child 44545 83b611b88ac8
permissions -rw-r--r--
8173393: Module system implementation refresh (2/2017) Reviewed-by: dfuchs, psandoz, mchung, alanb Contributed-by: alan.bateman@oracle.com, mandy.chung@oracle.com, claes.redestad@oracle.com, alex.buckley@oracle.com, mark.reinhold@oracle.com, john.r.rose@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     1
/*
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     4
 *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     8
 *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    13
 * accompanied this code).
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    14
 *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    18
 *
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    21
 * questions.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    22
 */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    23
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    24
/**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    25
 * @test
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    26
 * @library /lib/testlibrary
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    27
 * @modules jdk.compiler
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    28
 * @build CompilerUtils
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    29
 * @run testng/othervm BadProvidersTest
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    30
 * @summary Basic test of ServiceLoader with bad provider and bad provider
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    31
 *          factories deployed on the module path
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    32
 */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    33
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    34
import java.lang.module.Configuration;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    35
import java.lang.module.ModuleFinder;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    36
import java.lang.reflect.Layer;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    37
import java.nio.file.Files;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    38
import java.nio.file.Path;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    39
import java.nio.file.Paths;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    40
import java.nio.file.StandardCopyOption;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    41
import java.util.List;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    42
import java.util.ServiceConfigurationError;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    43
import java.util.ServiceLoader;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    44
import java.util.ServiceLoader.Provider;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    45
import java.util.Set;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    46
import java.util.stream.Collectors;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    47
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    48
import org.testng.annotations.Test;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    49
import org.testng.annotations.DataProvider;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    50
import static org.testng.Assert.*;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    51
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    52
/**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    53
 * Basic test of `provides S with PF` and `provides S with P` where the provider
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    54
 * factory or provider
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    55
 */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    56
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    57
public class BadProvidersTest {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    58
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    59
    private static final String TEST_SRC = System.getProperty("test.src");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    60
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    61
    private static final Path USER_DIR   = Paths.get(System.getProperty("user.dir"));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    62
    private static final Path SRC_DIR    = Paths.get(TEST_SRC, "modules");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    63
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    64
    private static final Path BADFACTORIES_DIR = Paths.get(TEST_SRC, "badfactories");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    65
    private static final Path BADPROVIDERS_DIR = Paths.get(TEST_SRC, "badproviders");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    66
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    67
    private static final String TEST1_MODULE = "test1";
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    68
    private static final String TEST2_MODULE = "test2";
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    69
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    70
    private static final String TEST_SERVICE = "p.Service";
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    71
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    72
    /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    73
     * Compiles a module, returning a module path with the compiled module.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    74
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    75
    private Path compileTest(String moduleName) throws Exception {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    76
        Path dir = Files.createTempDirectory(USER_DIR, "mods");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    77
        Path output = Files.createDirectory(dir.resolve(moduleName));
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    78
        boolean compiled = CompilerUtils.compile(SRC_DIR.resolve(moduleName), output);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    79
        assertTrue(compiled);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    80
        return dir;
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    81
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    82
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    83
    /**
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    84
     * Resolves a test module and loads it into its own layer. ServiceLoader
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    85
     * is then used to load all providers.
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    86
     */
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    87
    private List<Provider> loadProviders(Path mp, String moduleName) throws Exception {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    88
        ModuleFinder finder = ModuleFinder.of(mp);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    89
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    90
        Layer bootLayer = Layer.boot();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    91
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    92
        Configuration cf = bootLayer.configuration()
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42338
diff changeset
    93
                .resolveAndBind(finder, ModuleFinder.of(), Set.of(moduleName));
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    94
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    95
        ClassLoader scl = ClassLoader.getSystemClassLoader();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    96
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    97
        Layer layer = Layer.boot().defineModulesWithOneLoader(cf, scl);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    98
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
    99
        Class<?> service = layer.findLoader(moduleName).loadClass(TEST_SERVICE);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   100
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   101
        return ServiceLoader.load(layer, service)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   102
                .stream()
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   103
                .collect(Collectors.toList());
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   104
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   105
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   106
    @Test
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   107
    public void sanityTest1() throws Exception {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   108
        Path mods = compileTest(TEST1_MODULE);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   109
        List<Provider> list = loadProviders(mods, TEST1_MODULE);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   110
        assertTrue(list.size() == 1);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   111
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   112
        // the provider is a singleton, enforced by the provider factory
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   113
        Object p1 = list.get(0).get();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   114
        Object p2 = list.get(0).get();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   115
        assertTrue(p1 != null);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   116
        assertTrue(p1 == p2);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   117
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   118
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   119
    @Test
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   120
    public void sanityTest2() throws Exception {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   121
        Path mods = compileTest(TEST2_MODULE);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   122
        List<Provider> list = loadProviders(mods, TEST2_MODULE);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   123
        assertTrue(list.size() == 1);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   124
        Object p = list.get(0).get();
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   125
        assertTrue(p != null);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   126
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   127
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   128
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   129
    @DataProvider(name = "badfactories")
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   130
    public Object[][] createBadFactories() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   131
        return new Object[][] {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   132
                { "classnotpublic",     null },
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   133
                { "methodnotpublic",    null },
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   134
                { "badreturntype",      null },
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   135
                { "returnsnull",        null },
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   136
                { "throwsexception",    null },
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   137
        };
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   138
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   139
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   140
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   141
    @Test(dataProvider = "badfactories",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   142
          expectedExceptions = ServiceConfigurationError.class)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   143
    public void testBadFactory(String testName, String ignore) throws Exception {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   144
        Path mods = compileTest(TEST1_MODULE);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   145
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   146
        // compile the bad factory
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   147
        Path source = BADFACTORIES_DIR.resolve(testName);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   148
        Path output = Files.createTempDirectory(USER_DIR, "tmp");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   149
        boolean compiled = CompilerUtils.compile(source, output);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   150
        assertTrue(compiled);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   151
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   152
        // copy the compiled class into the module
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   153
        Path classFile = Paths.get("p", "ProviderFactory.class");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   154
        Files.copy(output.resolve(classFile),
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   155
                   mods.resolve(TEST1_MODULE).resolve(classFile),
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   156
                   StandardCopyOption.REPLACE_EXISTING);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   157
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   158
        // load providers and instantiate each one
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   159
        loadProviders(mods, TEST1_MODULE).forEach(Provider::get);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   160
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   161
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   162
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   163
    @DataProvider(name = "badproviders")
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   164
    public Object[][] createBadProviders() {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   165
        return new Object[][] {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   166
                { "notpublic",          null },
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   167
                { "ctornotpublic",      null },
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   168
                { "notasubtype",        null },
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   169
                { "throwsexception",    null }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   170
        };
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   171
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   172
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   173
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   174
    @Test(dataProvider = "badproviders",
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   175
          expectedExceptions = ServiceConfigurationError.class)
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   176
    public void testBadProvider(String testName, String ignore) throws Exception {
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   177
        Path mods = compileTest(TEST2_MODULE);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   178
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   179
        // compile the bad provider
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   180
        Path source = BADPROVIDERS_DIR.resolve(testName);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   181
        Path output = Files.createTempDirectory(USER_DIR, "tmp");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   182
        boolean compiled = CompilerUtils.compile(source, output);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   183
        assertTrue(compiled);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   184
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   185
        // copy the compiled class into the module
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   186
        Path classFile = Paths.get("p", "Provider.class");
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   187
        Files.copy(output.resolve(classFile),
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   188
                   mods.resolve(TEST2_MODULE).resolve(classFile),
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   189
                   StandardCopyOption.REPLACE_EXISTING);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   190
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   191
        // load providers and instantiate each one
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   192
        loadProviders(mods, TEST2_MODULE).forEach(Provider::get);
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   193
    }
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   194
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   195
}
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents:
diff changeset
   196