< prev index next >

jdk/test/jdk/modules/etc/VerifyModuleDelegation.java

Print this page




   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 /**
  25  * @test
  26  * @summary Verify the defining class loader of each module never delegates
  27  *          to its child class loader. Also sanity check java.compact2
  28  *          requires.
  29  * @run testng/othervm -Djdk.launcher.addmods=ALL-SYSTEM VerifyModuleDelegation
  30  */
  31 
  32 import java.lang.module.ModuleDescriptor;
  33 import java.lang.module.ModuleFinder;
  34 import java.lang.module.ModuleReference;
  35 import java.lang.reflect.Layer;
  36 import java.util.Set;
  37 
  38 import static java.lang.module.ModuleDescriptor.Requires.Modifier.*;
  39 
  40 import org.testng.annotations.*;
  41 
  42 import static org.testng.Assert.*;
  43 
  44 public class VerifyModuleDelegation {
  45     private static final String JAVA_BASE = "java.base";
  46     private static final String JAVA_COMPACT1 = "java.compact1";
  47     private static final String JAVA_COMPACT2 = "java.compact2";
  48 
  49     private static final ModuleDescriptor BASE
  50         = new ModuleDescriptor.Builder(JAVA_BASE).build();
  51 
  52     private static final ModuleDescriptor COMPACT2
  53         = new ModuleDescriptor.Builder(JAVA_COMPACT2)
  54             .requires(MANDATED, JAVA_BASE)
  55             .requires(PUBLIC, JAVA_COMPACT1)
  56             .requires(PUBLIC, "java.rmi")
  57             .requires(PUBLIC, "java.sql")
  58             .requires(PUBLIC, "java.xml")
  59             .build();
  60 
  61     private static final Set<ModuleReference> MREFS
  62             = ModuleFinder.ofSystem().findAll();
  63 
  64     private void check(ModuleDescriptor md, ModuleDescriptor ref) {
  65         assertTrue(md.requires().size() == ref.requires().size());
  66         assertTrue(md.requires().containsAll(ref.requires()));
  67     }
  68 
  69     @Test
  70     public void checkJavaBase() {
  71         ModuleDescriptor md =
  72                 MREFS.stream().map(ModuleReference::descriptor)
  73                      .filter(d -> d.name().equals(JAVA_BASE))
  74                      .findFirst().orElseThrow(Error::new);
  75 
  76         check(md, BASE);
  77     }
  78     @Test




   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 /**
  25  * @test
  26  * @summary Verify the defining class loader of each module never delegates
  27  *          to its child class loader. Also sanity check java.compact2
  28  *          requires.
  29  * @run testng/othervm --add-modules=ALL-SYSTEM VerifyModuleDelegation
  30  */
  31 
  32 import java.lang.module.ModuleDescriptor;
  33 import java.lang.module.ModuleFinder;
  34 import java.lang.module.ModuleReference;
  35 import java.lang.reflect.Layer;
  36 import java.util.Set;
  37 
  38 import static java.lang.module.ModuleDescriptor.Requires.Modifier.*;
  39 
  40 import org.testng.annotations.*;
  41 
  42 import static org.testng.Assert.*;
  43 
  44 public class VerifyModuleDelegation {
  45     private static final String JAVA_BASE = "java.base";
  46     private static final String JAVA_COMPACT1 = "java.compact1";
  47     private static final String JAVA_COMPACT2 = "java.compact2";
  48 
  49     private static final ModuleDescriptor BASE
  50         = new ModuleDescriptor.Builder(JAVA_BASE).build();
  51 
  52     private static final ModuleDescriptor COMPACT2
  53         = new ModuleDescriptor.Builder(JAVA_COMPACT2)
  54             .requires(Set.of(MANDATED), JAVA_BASE)
  55             .requires(Set.of(PUBLIC), JAVA_COMPACT1)
  56             .requires(Set.of(PUBLIC), "java.rmi")
  57             .requires(Set.of(PUBLIC), "java.sql")
  58             .requires(Set.of(PUBLIC), "java.xml")
  59             .build();
  60 
  61     private static final Set<ModuleReference> MREFS
  62             = ModuleFinder.ofSystem().findAll();
  63 
  64     private void check(ModuleDescriptor md, ModuleDescriptor ref) {
  65         assertTrue(md.requires().size() == ref.requires().size());
  66         assertTrue(md.requires().containsAll(ref.requires()));
  67     }
  68 
  69     @Test
  70     public void checkJavaBase() {
  71         ModuleDescriptor md =
  72                 MREFS.stream().map(ModuleReference::descriptor)
  73                      .filter(d -> d.name().equals(JAVA_BASE))
  74                      .findFirst().orElseThrow(Error::new);
  75 
  76         check(md, BASE);
  77     }
  78     @Test


< prev index next >