Skip to content

Commit

Permalink
deal with jruby-openssl pre-release not being reported by `Gem.loaded…
Browse files Browse the repository at this point in the history
…_specs`
  • Loading branch information
kares committed Jul 30, 2015
1 parent 5bbee5a commit 94e54f3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
package org.jruby.embed.osgi.test;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import static org.ops4j.pax.exam.CoreOptions.bundle;
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.options;
Expand All @@ -35,6 +36,8 @@

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;

import org.jruby.embed.osgi.OSGiIsolatedScriptingContainer;
import org.junit.Test;
Expand Down Expand Up @@ -107,14 +110,37 @@ public void testJRubyCreate() throws Exception {
assertEquals(true, loaded);

jruby.runScriptlet( "require 'jar-dependencies'" );
list = (String) jruby.runScriptlet( "Gem.loaded_specs.keys.sort.inspect" );
assertEquals( "[\"jar-dependencies\", \"jruby-openssl\", \"rake\"]", list );

assertGemListEquals(jruby, "jar-dependencies", "jruby-openssl", "rake");

// ensure we can load can load embedded gems
loaded = (Boolean) jruby.runScriptlet( "require 'virtus'" );
assertEquals(true, loaded);

list = (String) jruby.runScriptlet( "Gem.loaded_specs.keys.sort.inspect" );
assertEquals( "[\"axiom-types\", \"coercible\", \"descendants_tracker\", \"equalizer\", \"ice_nine\", \"jar-dependencies\", \"jruby-openssl\", \"rake\", \"thread_safe\", \"virtus\"]", list );
assertGemListEquals(jruby, "axiom-types", "coercible", "descendants_tracker", "equalizer", "ice_nine", "jar-dependencies", "jruby-openssl", "rake", "thread_safe", "virtus");
}

private static void assertGemListEquals(final OSGiIsolatedScriptingContainer jruby, final String... expected) {
String list = (String) jruby.runScriptlet( "Gem.loaded_specs.keys.sort.join(', ')" );

Arrays.sort(expected);

if ( gemJOpenSSLPreRelease(jruby) ) {
ArrayList<String> tmp = new ArrayList<String>(Arrays.asList(expected));
tmp.remove("jruby-openssl"); // pre-release gem not reported in loaded_keys

for ( String name : tmp.toArray(new String[0]) ) {
assertThat(list, containsString(name));
}
}
else {
assertEquals( Arrays.toString(expected), list );
}
}

private static boolean gemJOpenSSLPreRelease(final OSGiIsolatedScriptingContainer jruby) {
String josslVersion = (String) jruby.runScriptlet( "require 'jopenssl/version'; Jopenssl::Version::VERSION" );
return josslVersion.matches(".*?[a-zA-Z]");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@
package org.jruby.embed.osgi.test;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import static org.ops4j.pax.exam.CoreOptions.bundle;
import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import static org.ops4j.pax.exam.CoreOptions.options;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;

import org.jruby.embed.osgi.OSGiIsolatedScriptingContainer;
import org.junit.Test;
Expand Down Expand Up @@ -93,14 +96,37 @@ public void testJRubyCreate() throws InterruptedException {
assertEquals( "[\"uri:classloader:/specifications\", \"uri:classloader://specifications\"]", gemPath );

jruby.runScriptlet( "require 'jar-dependencies'" );
list = (String) jruby.runScriptlet( "Gem.loaded_specs.keys.sort.inspect" );
assertEquals( "[\"jar-dependencies\", \"jruby-openssl\", \"rake\"]", list );

assertGemListEquals(jruby, "jar-dependencies", "jruby-openssl", "rake");

// ensure we can load can load embedded gems
loaded = (Boolean) jruby.runScriptlet( "require 'virtus'" );
assertEquals(true, loaded);

list = (String) jruby.runScriptlet( "Gem.loaded_specs.keys.sort.inspect" );
assertEquals( "[\"axiom-types\", \"coercible\", \"descendants_tracker\", \"equalizer\", \"ice_nine\", \"jar-dependencies\", \"jruby-openssl\", \"rake\", \"thread_safe\", \"virtus\"]", list );
assertGemListEquals(jruby, "axiom-types", "coercible", "descendants_tracker", "equalizer", "ice_nine", "jar-dependencies", "jruby-openssl", "rake", "thread_safe", "virtus");
}

private static void assertGemListEquals(final OSGiIsolatedScriptingContainer jruby, final String... expected) {
String list = (String) jruby.runScriptlet( "Gem.loaded_specs.keys.sort.join(', ')" );

Arrays.sort(expected);

if ( gemJOpenSSLPreRelease(jruby) ) {
ArrayList<String> tmp = new ArrayList<String>(Arrays.asList(expected));
tmp.remove("jruby-openssl"); // pre-release gem not reported in loaded_keys

for ( String name : tmp.toArray(new String[0]) ) {
assertThat(list, containsString(name));
}
}
else {
assertEquals( Arrays.toString(expected), list );
}
}

private static boolean gemJOpenSSLPreRelease(final OSGiIsolatedScriptingContainer jruby) {
String josslVersion = (String) jruby.runScriptlet( "require 'jopenssl/version'; Jopenssl::Version::VERSION" );
return josslVersion.matches(".*?[a-zA-Z]");
}

}

0 comments on commit 94e54f3

Please sign in to comment.