< prev index next >

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

Print this page




  49 public class GetResourceBundleTest {
  50 
  51     private static final String TEST_SRC = System.getProperty("test.src");
  52 
  53     private static final Path MOD_SRC_DIR = Paths.get(TEST_SRC, "src");
  54     private static final Path MOD_DEST_DIR = Paths.get("mods");
  55     private static final Path PKG_SRC_DIR = Paths.get(TEST_SRC, "pkgs");
  56     private static final Path PKG_DEST_DIR = Paths.get("pkgs");
  57 
  58     private static final String[] modules = new String[] {"m1", "m2"};
  59 
  60     /**
  61      * Compiles all modules used by the test, copy resource files.
  62      */
  63     @BeforeClass
  64     public void setup() throws Exception {
  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 }


  49 public class GetResourceBundleTest {
  50 
  51     private static final String TEST_SRC = System.getProperty("test.src");
  52 
  53     private static final Path MOD_SRC_DIR = Paths.get(TEST_SRC, "src");
  54     private static final Path MOD_DEST_DIR = Paths.get("mods");
  55     private static final Path PKG_SRC_DIR = Paths.get(TEST_SRC, "pkgs");
  56     private static final Path PKG_DEST_DIR = Paths.get("pkgs");
  57 
  58     private static final String[] modules = new String[] {"m1", "m2"};
  59 
  60     /**
  61      * Compiles all modules used by the test, copy resource files.
  62      */
  63     @BeforeClass
  64     public void setup() throws Exception {
  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                     "--module-source-path", MOD_SRC_DIR.toString()));
  70         }
  71         assertTrue(CompilerUtils.compile(PKG_SRC_DIR, PKG_DEST_DIR,
  72                 "--module-path", MOD_DEST_DIR.toString(), "--add-modules", 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                 "--module-path", MOD_DEST_DIR.toString(),
  88                 "--add-modules", 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                 "--module-path", MOD_DEST_DIR.toString(),
 102                 "--add-modules", String.join(",", modules),
 103                 "p3.test.ResourceBundleTest")
 104                 .outputTo(System.out)
 105                 .errorTo(System.err)
 106                 .getExitValue();
 107         assertTrue(exitValue == 0);
 108     }
 109 }
< prev index next >