Skip to content

Commit

Permalink
added small test for IsolatedScriptingContainer simulating an OSGi co…
Browse files Browse the repository at this point in the history
…ntainer
  • Loading branch information
mkristian committed Jan 13, 2015
1 parent 3320b8a commit a042abb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
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);
}
}
9 changes: 9 additions & 0 deletions core/src/test/resources/rubygems/defaults/jruby.rb
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

0 comments on commit a042abb

Please sign in to comment.