1 /* 2 * Copyright (c) 2015, 2016, 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 39 * @modules jdk.compiler 40 * java.logging 41 * @build GetResourceBundleTest CompilerUtils jdk.testlibrary.ProcessTools 42 * @run testng GetResourceBundleTest 43 * @summary Tests Logger.getLogger + logger.getResourceBundle in an named/unnamed module, 44 * resources are in named and unnamed modules respectively. 45 * Positive tests to ensure that a Logger can retrieve ResourceBundle in its current module. 46 * Negative tests to ensure that a Logger cannot retrieve ResourceBundle in another module. 47 * This test also verifies 8136802 8137316 8137317 8136804 8139350. 48 */ 49 50 public class GetResourceBundleTest { 51 52 private static final String TEST_SRC = System.getProperty("test.src"); 53 54 private static final Path MOD_SRC_DIR = Paths.get(TEST_SRC, "src"); 55 private static final Path MOD_DEST_DIR = Paths.get("mods"); 56 private static final Path PKG_SRC_DIR = Paths.get(TEST_SRC, "pkgs"); 57 private static final Path PKG_DEST_DIR = Paths.get("pkgs"); 58 59 private static final String[] modules = new String[] {"m1", "m2"}; 60 61 /** 62 * Compiles all modules used by the test, copy resource files. 63 */ 64 @BeforeClass 65 public void setup() throws Exception { 66 // compile all modules 67 for (String mn : modules) { 68 Path msrc = MOD_SRC_DIR.resolve(mn); 69 assertTrue(CompilerUtils.compile(msrc, MOD_DEST_DIR, 70 "--module-source-path", MOD_SRC_DIR.toString())); 71 } 72 assertTrue(CompilerUtils.compile(PKG_SRC_DIR, PKG_DEST_DIR, 73 "--module-path", MOD_DEST_DIR.toString(), "--add-modules", String.join(",", modules))); 74 75 // copy resource files 76 String[] files = { "m1/p1/resource/p.properties", "m2/p2/resource/p.properties" }; 77 for(String f : files) { 78 Files.copy(MOD_SRC_DIR.resolve(f), MOD_DEST_DIR.resolve(f), REPLACE_EXISTING); 79 } 80 String p3 = "p3/resource/p.properties"; 81 Files.copy(PKG_SRC_DIR.resolve(p3), PKG_DEST_DIR.resolve(p3), REPLACE_EXISTING); 82 } 83 84 @Test 85 public void runWithoutSecurityManager() throws Exception { 86 int exitValue = executeTestJava( 87 "-cp", PKG_DEST_DIR.toString(), 88 "--module-path", MOD_DEST_DIR.toString(), 89 "--add-modules", String.join(",", modules), 90 "p3.test.ResourceBundleTest") 91 .outputTo(System.out) 92 .errorTo(System.err) 93 .getExitValue(); 94 assertTrue(exitValue == 0); 95 } 96 97 @Test 98 public void runWithSecurityManager() throws Exception { 99 int exitValue = executeTestJava( 100 "-Djava.security.manager", 101 "-cp", PKG_DEST_DIR.toString(), 102 "--module-path", MOD_DEST_DIR.toString(), 103 "--add-modules", String.join(",", modules), 104 "p3.test.ResourceBundleTest") 105 .outputTo(System.out) 106 .errorTo(System.err) 107 .getExitValue(); 108 assertTrue(exitValue == 0); 109 } 110 }