< prev index next >

test/java/util/logging/modules/GetResourceBundleTest.java

Print this page



   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  * @build GetResourceBundleTest CompilerUtils jdk.testlibrary.ProcessTools
  41  * @run testng GetResourceBundleTest
  42  * @summary Tests Logger.getLogger + logger.getResourceBundle in an named/unnamed module,
  43  *          resources are in named and unnamed modules respectively.
  44  *          Positive tests to ensure that a Logger can retrieve ResourceBundle in its current module.
  45  *          Negative tests to ensure that a Logger cannot retrieve ResourceBundle in another module.
  46  *          This test also verifies 8136802 8137316 8137317 8136804 8139350.


  65         // compile all modules
  66         for (String mn : modules) {
  67             Path msrc = MOD_SRC_DIR.resolve(mn);
  68             assertTrue(CompilerUtils.compile(msrc, MOD_DEST_DIR,
  69                     "-modulesourcepath", MOD_SRC_DIR.toString()));
  70         }
  71         assertTrue(CompilerUtils.compile(PKG_SRC_DIR, PKG_DEST_DIR,
  72                 "-modulepath", MOD_DEST_DIR.toString(), "-addmods", String.join(",", modules)));
  73 
  74         // copy resource files
  75         String[] files = { "m1/p1/resource/p.properties", "m2/p2/resource/p.properties" };
  76         for(String f : files) {
  77             Files.copy(MOD_SRC_DIR.resolve(f), MOD_DEST_DIR.resolve(f), REPLACE_EXISTING);
  78         }
  79         String p3 = "p3/resource/p.properties";
  80         Files.copy(PKG_SRC_DIR.resolve(p3), PKG_DEST_DIR.resolve(p3), REPLACE_EXISTING);
  81     }
  82 
  83     @Test
  84     public void runWithoutSecurityManager() throws Exception {
  85         int exitValue = executeTestJava(
  86                 "-cp", PKG_DEST_DIR.toString(),
  87                 "-mp", MOD_DEST_DIR.toString(),
  88                 "-addmods", String.join(",", modules),
  89                 "p3.test.ResourceBundleTest")
  90                 .outputTo(System.out)
  91                 .errorTo(System.err)
  92                 .getExitValue();
  93         assertTrue(exitValue == 0);
  94     }
  95 
  96     @Test
  97     public void runWithSecurityManager() throws Exception {
  98         int exitValue = executeTestJava(
  99                 "-Djava.security.manager",
 100                 "-cp", PKG_DEST_DIR.toString(),
 101                 "-mp", MOD_DEST_DIR.toString(),
 102                 "-addmods", String.join(",", modules),
 103                 "p3.test.ResourceBundleTest")
 104                 .outputTo(System.out)
 105                 .errorTo(System.err)
 106                 .getExitValue();
 107         assertTrue(exitValue == 0);
 108     }
 109 }

   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 import java.util.Collections;
  28 import java.util.Arrays;
  29 
  30 import org.testng.annotations.BeforeClass;
  31 import org.testng.annotations.Test;
  32 
  33 import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
  34 import static jdk.testlibrary.ProcessTools.*;
  35 import static org.testng.Assert.*;
  36 
  37 /**
  38  * @test
  39  * @bug 8129126 8136802 8137316 8137317 8136804 8139350
  40  * @library /lib/testlibrary
  41  * @modules jdk.compiler
  42  * @build GetResourceBundleTest CompilerUtils jdk.testlibrary.ProcessTools
  43  * @run testng GetResourceBundleTest
  44  * @summary Tests Logger.getLogger + logger.getResourceBundle in an named/unnamed module,
  45  *          resources are in named and unnamed modules respectively.
  46  *          Positive tests to ensure that a Logger can retrieve ResourceBundle in its current module.
  47  *          Negative tests to ensure that a Logger cannot retrieve ResourceBundle in another module.
  48  *          This test also verifies 8136802 8137316 8137317 8136804 8139350.


  67         // compile all modules
  68         for (String mn : modules) {
  69             Path msrc = MOD_SRC_DIR.resolve(mn);
  70             assertTrue(CompilerUtils.compile(msrc, MOD_DEST_DIR,
  71                     "-modulesourcepath", MOD_SRC_DIR.toString()));
  72         }
  73         assertTrue(CompilerUtils.compile(PKG_SRC_DIR, PKG_DEST_DIR,
  74                 "-modulepath", MOD_DEST_DIR.toString(), "-addmods", String.join(",", modules)));
  75 
  76         // copy resource files
  77         String[] files = { "m1/p1/resource/p.properties", "m2/p2/resource/p.properties" };
  78         for(String f : files) {
  79             Files.copy(MOD_SRC_DIR.resolve(f), MOD_DEST_DIR.resolve(f), REPLACE_EXISTING);
  80         }
  81         String p3 = "p3/resource/p.properties";
  82         Files.copy(PKG_SRC_DIR.resolve(p3), PKG_DEST_DIR.resolve(p3), REPLACE_EXISTING);
  83     }
  84 
  85     @Test
  86     public void runWithoutSecurityManager() throws Exception {
  87         int exitValue = executeModularTest(null, "p3.test.ResourceBundleTest", null,
  88             Arrays.asList(PKG_DEST_DIR), Arrays.asList(MOD_DEST_DIR), Arrays.asList(modules))





  89                 .getExitValue();
  90         assertTrue(exitValue == 0);
  91     }
  92 
  93     @Test
  94     public void runWithSecurityManager() throws Exception {
  95         int exitValue = executeModularTest(null, "p3.test.ResourceBundleTest",
  96             Arrays.asList("-Djava.security.manager"),
  97             Arrays.asList(PKG_DEST_DIR), Arrays.asList(MOD_DEST_DIR), Arrays.asList(modules))





  98                 .getExitValue();
  99         assertTrue(exitValue == 0);
 100     }
 101 }
< prev index next >