-
-
Notifications
You must be signed in to change notification settings - Fork 924
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added small test for IsolatedScriptingContainer simulating an OSGi co…
…ntainer
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
core/src/test/java/org/jruby/embed/IsolatedScriptingContainerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.jruby.embed; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.fail; | ||
|
||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class IsolatedScriptingContainerTest { | ||
|
||
static ClassLoader cl; | ||
|
||
@BeforeClass | ||
public static void setupClassLoader() { | ||
cl = Thread.currentThread().getContextClassLoader(); | ||
// make sure we have classloader which does not find jruby | ||
ClassLoader c = new URLClassLoader( new URL[] {}, null ); | ||
try { | ||
c.loadClass( "org.jruby.embed.ScriptingContainer" ); | ||
fail( "this classloader shall not find jruby" ); | ||
} | ||
catch( ClassNotFoundException expected){} | ||
// set it as context classloader | ||
Thread.currentThread().setContextClassLoader( c ); | ||
} | ||
|
||
@AfterClass | ||
public static void restClassLoader() { | ||
Thread.currentThread().setContextClassLoader( cl ); | ||
} | ||
|
||
@Test | ||
public void testIsolatedScriptingContainer() throws Exception { | ||
// we do have an instance of "jruby" loaded via some other classloader | ||
//System.setProperty("jruby.debug.loadService", "true"); | ||
ScriptingContainer instance = new IsolatedScriptingContainer(); | ||
String result = instance.runScriptlet( "$LOAD_PATH" ).toString(); | ||
assertNotNull(result); | ||
|
||
assertEquals(instance.runScriptlet("JRuby.runtime.jruby_class_loader.parent" ), cl ); | ||
assertEquals(ScriptingContainer.class.getClassLoader(), cl); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# dummy to run IsolatedScriptingContainerTest | ||
module Gem | ||
class Specification | ||
def self.reset | ||
end | ||
def self.add_dir *args | ||
end | ||
end | ||
end |