jdk/test/java/lang/Class/getResource/ResourcesTest.java
author iignatyev
Tue, 06 Jun 2017 19:54:08 -0700
changeset 45393 de4e1efc8eec
parent 42338 a60f280f803c
permissions -rw-r--r--
8181335: remove packageless CompilerUtils Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
45393
de4e1efc8eec 8181335: remove packageless CompilerUtils
iignatyev
parents: 42338
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
36511
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
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import static jdk.testlibrary.ProcessTools.executeTestJava;
45393
de4e1efc8eec 8181335: remove packageless CompilerUtils
iignatyev
parents: 42338
diff changeset
    28
import jdk.test.lib.compiler.CompilerUtils;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import org.testng.annotations.BeforeTest;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import org.testng.annotations.Test;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
import static org.testng.Assert.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
 * @test
45393
de4e1efc8eec 8181335: remove packageless CompilerUtils
iignatyev
parents: 42338
diff changeset
    36
 * @library /lib/testlibrary /test/lib
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
 * @modules jdk.compiler
45393
de4e1efc8eec 8181335: remove packageless CompilerUtils
iignatyev
parents: 42338
diff changeset
    38
 * @build ResourcesTest jdk.test.lib.compiler.CompilerUtils jdk.testlibrary.*
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
 * @run testng ResourcesTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
 * @summary Driver for basic test of Class getResource and getResourceAsStream
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
@Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
public class ResourcesTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
    private static final String TEST_SRC = System.getProperty("test.src");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
    private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
    private static final Path CLASSES_DIR = Paths.get("classes");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
    private static final Path MODS_DIR = Paths.get("mods");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    53
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
     * Compiles the modules used by the test and the test Main
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    @BeforeTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
    public void compileAll() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        boolean compiled;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        // javac -modulesource mods -d mods src/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
        compiled = CompilerUtils
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
            .compile(SRC_DIR,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
                     MODS_DIR,
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    64
                     "--module-source-path", SRC_DIR.toString());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
        assertTrue(compiled);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    66
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    67
        // javac --module-path mods -d classes Main.java
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        compiled = CompilerUtils
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
            .compile(Paths.get(TEST_SRC, "Main.java"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
                     CLASSES_DIR,
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    71
                     "--module-path", MODS_DIR.toString(),
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
    72
                     "--add-modules", "m1,m2");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
        assertTrue(compiled);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
     * Run the test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
    public void runTest() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
        int exitValue
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    83
            = executeTestJava("--module-path", MODS_DIR.toString(),
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
    84
                              "--add-modules", "m1,m2",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
                               "-cp", CLASSES_DIR.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
                              "Main")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
                .outputTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
                .errorTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
                .getExitValue();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
        assertTrue(exitValue == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
}
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    96