Search in sources :

Example 1 with TestClassLoader

use of com.alipay.sofa.ark.container.test.TestClassLoader in project sofa-ark by alipay.

the class ClassLoaderTest method testDelegateConfigure.

@Test
public void testDelegateConfigure() throws Throwable {
    EnvironmentUtils.setProperty(Constants.FORCE_DELEGATE_TO_TEST_CLASSLOADER, Test.class.getPackage().getName());
    EnvironmentUtils.setProperty(Constants.FORCE_DELEGATE_TO_APP_CLASSLOADER, ClassLoaderTest.class.getPackage().getName());
    // incompatible with JDK9+
    URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
    TestClassLoader testClassLoader = new TestClassLoader("mock:1.0", urlClassLoader.getURLs(), urlClassLoader);
    Assert.assertEquals(testClassLoader, testClassLoader.loadClass(Test.class.getCanonicalName()).getClassLoader());
    Assert.assertEquals(urlClassLoader, testClassLoader.loadClass(ClassLoaderTest.class.getCanonicalName()).getClassLoader());
    EnvironmentUtils.clearProperty(Constants.FORCE_DELEGATE_TO_APP_CLASSLOADER);
    EnvironmentUtils.clearProperty(Constants.FORCE_DELEGATE_TO_TEST_CLASSLOADER);
}
Also used : TestClassLoader(com.alipay.sofa.ark.container.test.TestClassLoader) Test(org.junit.Test) URLClassLoader(java.net.URLClassLoader) Test(org.junit.Test)

Example 2 with TestClassLoader

use of com.alipay.sofa.ark.container.test.TestClassLoader in project sofa-ark by alipay.

the class ClassLoaderTest method testDefaultDelegate.

@Test
public void testDefaultDelegate() throws Throwable {
    // incompatible with JDK9+
    URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
    TestClassLoader testClassLoader = new TestClassLoader("mock:1.0", urlClassLoader.getURLs(), urlClassLoader);
    Assert.assertEquals(urlClassLoader, testClassLoader.loadClass(Test.class.getCanonicalName()).getClassLoader());
    Assert.assertEquals(testClassLoader, testClassLoader.loadClass(ClassLoaderTest.class.getCanonicalName()).getClassLoader());
}
Also used : TestClassLoader(com.alipay.sofa.ark.container.test.TestClassLoader) Test(org.junit.Test) URLClassLoader(java.net.URLClassLoader) Test(org.junit.Test)

Example 3 with TestClassLoader

use of com.alipay.sofa.ark.container.test.TestClassLoader in project sofa-ark by alipay.

the class ArkJUnit4RunnerTest method test.

@Test
public void test() {
    ClassLoader testClassLoader = getClass().getClassLoader();
    Assert.assertTrue(testClassLoader.getClass().getCanonicalName().equals(TestClassLoader.class.getCanonicalName()));
    Assert.assertTrue("@Before".equals(state));
    state = "@Test";
    ClassLoader testClCl = testClassLoader.getClass().getClassLoader();
    Assert.assertTrue(testClCl.getClass().getCanonicalName().equals(ContainerClassLoader.class.getCanonicalName()));
}
Also used : TestClassLoader(com.alipay.sofa.ark.container.test.TestClassLoader) ContainerClassLoader(com.alipay.sofa.ark.bootstrap.ContainerClassLoader)

Aggregations

TestClassLoader (com.alipay.sofa.ark.container.test.TestClassLoader)3 URLClassLoader (java.net.URLClassLoader)2 Test (org.junit.Test)2 ContainerClassLoader (com.alipay.sofa.ark.bootstrap.ContainerClassLoader)1