| 1 |
/* |
| 2 |
* JBoss, Home of Professional Open Source. |
| 3 |
* Copyright 2018 Red Hat, Inc., and individual contributors |
| 4 |
* as indicated by the @author tags. |
| 5 |
* |
| 6 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 |
* you may not use this file except in compliance with the License. |
| 8 |
* You may obtain a copy of the License at |
| 9 |
* |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* |
| 12 |
* Unless required by applicable law or agreed to in writing, software |
| 13 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 |
* See the License for the specific language governing permissions and |
| 16 |
* limitations under the License. |
| 17 |
*/ |
| 18 |
|
| 19 |
package org.jboss.modules; |
| 20 |
|
| 21 |
import java.net.URL; |
| 22 |
import java.util.regex.Matcher; |
| 23 |
import java.util.regex.Pattern; |
| 24 |
|
| 25 |
import org.junit.Assert; |
| 26 |
import org.junit.Assume; |
| 27 |
import org.junit.Test; |
| 28 |
|
| 29 |
/** |
| 30 |
*/ |
| 31 |
public class JDKModuleLoaderTest extends AbstractModuleTestCase { |
| 32 |
@Test |
| 33 |
public void testLoadModulesClassFile() throws ModuleLoadException { |
| 34 |
final Module module = Module.getSystemModuleLoader().loadModule("org.jboss.modules"); |
| 35 |
final URL resource = module.getClassLoader().getResource("org/jboss/modules/Main.class"); |
| 36 |
Assert.assertNotNull("Main.class", resource); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Tests that loading of "java.se" module works and classes that are present |
| 41 |
* in modules "required" by this "java.se" module can be loaded too |
| 42 |
* |
| 43 |
* @throws Exception |
| 44 |
*/ |
| 45 |
@Test |
| 46 |
public void testJavaSeModuleLoad() throws Exception { |
| 47 |
final Module module = Module.getBootModuleLoader().loadModule("java.se"); |
| 48 |
Assert.assertNotNull("java.se module not found", module); |
| 49 |
final String resultSetClassName = "java.sql.ResultSet"; |
| 50 |
final Class<?> klass = module.getClassLoader().loadClass(resultSetClassName); |
| 51 |
Assert.assertNotNull(resultSetClassName + " class couldn't be loaded from java.se module", klass); |
| 52 |
|
| 53 |
// test a class that was introduced in Java 11 |
| 54 |
String specString = System.getProperty("java.specification.version"); |
| 55 |
Pattern pat = Pattern.compile("(?:1\\.)?(\\d+)"); |
| 56 |
Matcher matcher = pat.matcher(specString); |
| 57 |
Assume.assumeTrue("Java 11 is required to test loading of classes " + |
| 58 |
"in java.net.http module", matcher.matches() && Integer.parseInt(matcher.group(1)) >= 11); |
| 59 |
final String httpClientClassName = "java.net.http.HttpClient"; |
| 60 |
final Class<?> httpClientClass = module.getClassLoader().loadClass(httpClientClassName); |
| 61 |
Assert.assertNotNull(httpClientClassName + " class couldn't be loaded from java.se module", httpClientClass); |
| 62 |
} |
| 63 |
} |