1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.nio.file.Files; 25 import java.nio.file.Path; 26 import java.nio.file.Paths; 27 28 import org.testng.annotations.BeforeClass; 29 import org.testng.annotations.Test; 30 31 import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; 32 import static jdk.testlibrary.ProcessTools.*; 33 import static org.testng.Assert.*; 34 35 /** 36 * @test 37 * @bug 8129126 8136802 8137316 8137317 8136804 8139350 38 * @library /lib/testlibrary /jdk/jigsaw/lib 39 * @build GetResourceBundleTest CompilerUtils jdk.testlibrary.ProcessTools 40 * @run testng GetResourceBundleTest 41 * @summary Tests Logger.getLogger + logger.getResourceBundle in an named/unnamed module, 42 * resources are in named and unnamed modules respectively. 43 * Positive tests to ensure that a Logger can retrieve ResourceBundle in its current module. 44 * Negative tests to ensure that a Logger cannot retrieve ResourceBundle in another module. 45 * This test also verifies 8136802 8137316 8137317 8136804 8139350. 46 */ 47 48 public class GetResourceBundleTest { 49 50 private static final String TEST_SRC = System.getProperty("test.src"); 51 52 private static final Path MOD_SRC_DIR = Paths.get(TEST_SRC, "src"); 53 private static final Path MOD_DEST_DIR = Paths.get("mods"); 54 private static final Path PKG_SRC_DIR = Paths.get(TEST_SRC, "pkgs"); 55 private static final Path PKG_DEST_DIR = Paths.get("pkgs"); 56 57 private static final String[] modules = new String[] {"m1", "m2"}; 58 59 /** 60 * Compiles all modules used by the test, copy resource files. 61 */ 62 @BeforeClass 63 public void setup() throws Exception { 64 // compile all modules 65 for (String mn : modules) { 66 Path msrc = MOD_SRC_DIR.resolve(mn); 67 assertTrue(CompilerUtils.compile(msrc, MOD_DEST_DIR, 68 "-modulesourcepath", MOD_SRC_DIR.toString())); 69 } 70 assertTrue(CompilerUtils.compile(PKG_SRC_DIR, PKG_DEST_DIR, 71 "-modulepath", MOD_DEST_DIR.toString())); 72 73 // copy resource files 74 String[] files = { "m1/p1/resource/p.properties", "m2/p2/resource/p.properties" }; 75 for(String f : files) { 76 Files.copy(MOD_SRC_DIR.resolve(f), MOD_DEST_DIR.resolve(f), REPLACE_EXISTING); 77 } 78 String p3 = "p3/resource/p.properties"; 79 Files.copy(PKG_SRC_DIR.resolve(p3), PKG_DEST_DIR.resolve(p3), REPLACE_EXISTING); 80 } 81 82 @Test 83 public void runWithoutSecurityManager() throws Exception { 84 int exitValue = executeTestJava( 85 "-cp", PKG_DEST_DIR.toString(), 86 "-mp", MOD_DEST_DIR.toString(), 87 "-addmods", String.join(",", modules), 88 "p3.test.ResourceBundleTest") 89 .outputTo(System.out) 90 .errorTo(System.err) 91 .getExitValue(); 92 assertTrue(exitValue == 0); 93 } 94 95 @Test 96 public void runWithSecurityManager() throws Exception { 97 int exitValue = executeTestJava( 98 "-Djava.security.manager", 99 "-cp", PKG_DEST_DIR.toString(), 100 "-mp", MOD_DEST_DIR.toString(), 101 "-addmods", String.join(",", modules), 102 "p3.test.ResourceBundleTest") 103 .outputTo(System.out) 104 .errorTo(System.err) 105 .getExitValue(); 106 assertTrue(exitValue == 0); 107 } 108 }