diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-09-20 10:30:08 -0700 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-09-20 10:30:08 -0700 |
commit | 7eeb14be02a76468c5b791b25c5070f19ca00e1a (patch) | |
tree | 1554736c0e942771eaa6dbd8ce4d260c8778e371 /test | |
parent | 9ec19f34ace7ffe327e8bf54e252cca50d3ac7ff (diff) | |
parent | ac75cc4b50822988532754310d99b4c251ac2566 (diff) | |
download | scala-7eeb14be02a76468c5b791b25c5070f19ca00e1a.tar.gz scala-7eeb14be02a76468c5b791b25c5070f19ca00e1a.tar.bz2 scala-7eeb14be02a76468c5b791b25c5070f19ca00e1a.zip |
Merge pull request #1344 from jsuereth/wip/osgi-support
Fixes SI-5822 & SI-6305 - OSGi tests + fixes
Diffstat (limited to 'test')
-rw-r--r-- | test/osgi/src/BasicLibrary.scala | 37 | ||||
-rw-r--r-- | test/osgi/src/BasicReflection.scala | 66 | ||||
-rw-r--r-- | test/osgi/src/BasicTest.scala | 33 | ||||
-rw-r--r-- | test/osgi/src/ReflectionToolboxTest.scala | 49 | ||||
-rw-r--r-- | test/osgi/src/ScalaOsgiHelper.scala | 36 |
5 files changed, 221 insertions, 0 deletions
diff --git a/test/osgi/src/BasicLibrary.scala b/test/osgi/src/BasicLibrary.scala new file mode 100644 index 0000000000..38dea69e99 --- /dev/null +++ b/test/osgi/src/BasicLibrary.scala @@ -0,0 +1,37 @@ +package tools.test.osgi +package libonly + +import org.junit.Assert._ +import org.ops4j.pax.exam.CoreOptions._ + +import org.junit.Test +import org.junit.runner.RunWith +import org.ops4j.pax.exam +import org.ops4j.pax.exam.junit.{ + Configuration, + ExamReactorStrategy, + JUnit4TestRunner +} +import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory +import org.ops4j.pax.swissbox.framework.ServiceLookup +import org.osgi.framework.BundleContext + + + +@RunWith(classOf[JUnit4TestRunner]) +@ExamReactorStrategy(Array(classOf[AllConfinedStagedReactorFactory])) +class BasicLibraryTest extends ScalaOsgiHelper { + @Configuration + def config(): Array[exam.Option] = + justCoreLibraryOptions + + @Test + def everythingLoads(): Unit = { + // Note - This tests sun.misc usage. + import scala.concurrent._ + import scala.concurrent.util.Duration.Inf + import ExecutionContext.Implicits._ + val x = Future(2) map (_ + 1) + assertEquals(3, Await.result(x, Inf)) + } +} diff --git a/test/osgi/src/BasicReflection.scala b/test/osgi/src/BasicReflection.scala new file mode 100644 index 0000000000..8a0a05d531 --- /dev/null +++ b/test/osgi/src/BasicReflection.scala @@ -0,0 +1,66 @@ +package tools.test.osgi +package reflection +package basic + +import org.junit.Assert._ +import org.ops4j.pax.exam.CoreOptions._ + +import org.junit.Test +import org.junit.runner.RunWith +import org.ops4j.pax.exam +import org.ops4j.pax.exam.junit.{ + Configuration, + ExamReactorStrategy, + JUnit4TestRunner +} +import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory +import org.ops4j.pax.swissbox.framework.ServiceLookup +import org.osgi.framework.BundleContext + + +class C { + val f1 = 2 + var f2 = 3 + + def m1 = 4 + def m2() = 5 + def m3[T >: String <: Int]: T = ??? + def m4[A[_], B <: A[Int]](x: A[B])(implicit y: Int) = ??? + def m5(x: => Int, y: Int*): String = ??? + + class C + object M + + override def toString = "an instance of C" +} +object M + + +@RunWith(classOf[JUnit4TestRunner]) +@ExamReactorStrategy(Array(classOf[AllConfinedStagedReactorFactory])) +class BasicReflectionTest extends ScalaOsgiHelper { + + @Configuration + def config(): Array[exam.Option] = + justReflectionOptions + + // Ensure Pax-exam requires C/M in our module + def dummy = { + new C + M.toString + } + + @Test + def basicMirrorThroughOsgi(): Unit = { + // Note for now just assert that we can do this stuff. + import scala.reflect.runtime.universe._ + val cm = runtimeMirror(classOf[C].getClassLoader) + val im = cm.reflect(new C) + assertEquals("Unable to reflect field name!", + "value f1", + im.reflectField(typeOf[C].member(newTermName("f1")).asTerm).symbol.toString) + assertEquals("Unable to reflect value!", + 2, + im.reflectField(typeOf[C].member(newTermName("f1")).asTerm).get) + } +} diff --git a/test/osgi/src/BasicTest.scala b/test/osgi/src/BasicTest.scala new file mode 100644 index 0000000000..109b7b911a --- /dev/null +++ b/test/osgi/src/BasicTest.scala @@ -0,0 +1,33 @@ +package tools.test.osgi + +import org.junit.Assert._ +import org.ops4j.pax.exam.CoreOptions._ + +import org.junit.Test +import org.junit.runner.RunWith +import org.ops4j.pax.exam +import org.ops4j.pax.exam.junit.{ + Configuration, + ExamReactorStrategy, + JUnit4TestRunner +} +import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory +import org.ops4j.pax.swissbox.framework.ServiceLookup +import org.osgi.framework.BundleContext + + + + + +@RunWith(classOf[JUnit4TestRunner]) +@ExamReactorStrategy(Array(classOf[AllConfinedStagedReactorFactory])) +class BasicTest extends ScalaOsgiHelper { + @Configuration + def config(): Array[exam.Option] = { + // TODO - Find scala bundles. + standardOptions + } + + @Test + def everythingLoads(): Unit = () +} diff --git a/test/osgi/src/ReflectionToolboxTest.scala b/test/osgi/src/ReflectionToolboxTest.scala new file mode 100644 index 0000000000..bb48078e95 --- /dev/null +++ b/test/osgi/src/ReflectionToolboxTest.scala @@ -0,0 +1,49 @@ +package tools.test.osgi +package reflection +package toolbox + +import org.junit.Assert._ +import org.ops4j.pax.exam.CoreOptions._ + +import org.junit.Test +import org.junit.runner.RunWith +import org.ops4j.pax.exam +import org.ops4j.pax.exam.junit.{ + Configuration, + ExamReactorStrategy, + JUnit4TestRunner +} +import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory +import org.ops4j.pax.swissbox.framework.ServiceLookup +import org.osgi.framework.BundleContext + + +class C { + val f1 = 2 +} + +@RunWith(classOf[JUnit4TestRunner]) +@ExamReactorStrategy(Array(classOf[AllConfinedStagedReactorFactory])) +class ReflectionToolBoxTest extends ScalaOsgiHelper { + + @Configuration + def config(): Array[exam.Option] = + standardOptions + + + @Test + def basicMirrorThroughOsgi(): Unit = { + // Note - this tries to make sure when pulling a toolbox, we get the compiler. + import scala.reflect.runtime.universe._ + import scala.tools.reflect.ToolBox + val cm = runtimeMirror(classOf[C].getClassLoader) + val tb = cm.mkToolBox() + val im = cm.reflect(new C) + val tree = tb.parse("1 to 3 map (_+1)") + val eval = tb.eval(tree) + assertEquals(Vector(2, 3, 4), eval) + assertEquals("Evaluate expression using local class.", + 2, + tb.eval(tb.parse("(new tools.test.osgi.reflection.toolbox.C).f1"))) + } +} diff --git a/test/osgi/src/ScalaOsgiHelper.scala b/test/osgi/src/ScalaOsgiHelper.scala new file mode 100644 index 0000000000..bcdc5c0df1 --- /dev/null +++ b/test/osgi/src/ScalaOsgiHelper.scala @@ -0,0 +1,36 @@ +package tools.test.osgi + +import org.ops4j.pax.exam.CoreOptions._ +import org.ops4j.pax.exam +import java.io.File + +trait ScalaOsgiHelper { + + private def allBundleFiles = { + def bundleLocation = new File(sys.props.getOrElse("scala.bundle.dir", "build/osgi")) + bundleLocation.listFiles filter (_.getName endsWith ".jar") + } + + private def filteredBundleFiles(names: String*): Array[exam.Option] = + for(bundle <- allBundleFiles; if names exists (bundle.getName contains)) + yield makeBundle(bundle) + + private def makeBundle(file: File): exam.Option = + bundle(file.toURI.toASCIIString) + + def standardOptions: Array[exam.Option] = { + val bundles = (allBundleFiles map makeBundle) + bundles ++ Array[exam.Option](felix(), equinox(), junitBundles()) + } + + def justReflectionOptions: Array[exam.Option] = { + val bundles = filteredBundleFiles("scala-library", "scala-reflect") + bundles ++ Array[exam.Option](felix(), equinox(), junitBundles()) + } + + def justCoreLibraryOptions: Array[exam.Option] = { + val bundles = filteredBundleFiles("scala-library") + bundles ++ Array[exam.Option](felix(), equinox(), junitBundles()) + } + +} |