jdk/test/java/lang/Class/getResource/ResourcesTest.java
author alanb
Fri, 07 Apr 2017 08:05:54 +0000
changeset 44545 83b611b88ac8
parent 42338 a60f280f803c
child 45393 de4e1efc8eec
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: mchung, alanb Contributed-by: alan.bateman@oracle.com, mandy.chung@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, 2016, 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
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import static jdk.testlibrary.ProcessTools.executeTestJava;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import org.testng.annotations.BeforeTest;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import org.testng.annotations.Test;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import static org.testng.Assert.*;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
 * @test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
 * @library /lib/testlibrary
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
 * @modules jdk.compiler
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
 * @build ResourcesTest CompilerUtils jdk.testlibrary.*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
 * @run testng ResourcesTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
 * @summary Driver for basic test of Class getResource and getResourceAsStream
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
@Test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
public class ResourcesTest {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
    private static final String TEST_SRC = System.getProperty("test.src");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    47
    private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
    private static final Path CLASSES_DIR = Paths.get("classes");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
    private static final Path MODS_DIR = Paths.get("mods");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
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
     * Compiles the modules used by the test and the test Main
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
    @BeforeTest
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
    public void compileAll() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
        boolean compiled;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    59
        // javac -modulesource mods -d mods src/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        compiled = CompilerUtils
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
            .compile(SRC_DIR,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
                     MODS_DIR,
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    63
                     "--module-source-path", SRC_DIR.toString());
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
        assertTrue(compiled);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    66
        // javac --module-path mods -d classes Main.java
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
        compiled = CompilerUtils
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
            .compile(Paths.get(TEST_SRC, "Main.java"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
                     CLASSES_DIR,
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    70
                     "--module-path", MODS_DIR.toString(),
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
    71
                     "--add-modules", "m1,m2");
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        assertTrue(compiled);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
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
     * Run the test
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
    public void runTest() throws Exception {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
        int exitValue
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 36511
diff changeset
    82
            = executeTestJava("--module-path", MODS_DIR.toString(),
42338
a60f280f803c 8169069: Module system implementation refresh (11/2016)
alanb
parents: 40261
diff changeset
    83
                              "--add-modules", "m1,m2",
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
                               "-cp", CLASSES_DIR.toString(),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
                              "Main")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    86
                .outputTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
                .errorTo(System.out)
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
                .getExitValue();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
        assertTrue(exitValue == 0);
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
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