Skip to content
Permalink
Browse files
added small test for IsolatedScriptingContainer simulating an OSGi co…
…ntainer
  • Loading branch information
mkristian committed Jan 13, 2015
1 parent 3320b8a commit a042abbb32bd5271fd554809f9d4bf1e0d57e7e9
Showing 2 changed files with 57 additions and 0 deletions.
@@ -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);
}
}
@@ -0,0 +1,9 @@
# dummy to run IsolatedScriptingContainerTest
module Gem
class Specification
def self.reset
end
def self.add_dir *args
end
end
end

0 comments on commit a042abb

Please sign in to comment.