summaryrefslogtreecommitdiff
path: root/test/osgi
diff options
context:
space:
mode:
authorJosh Suereth <joshua.suereth@gmail.com>2012-09-17 13:55:44 -0400
committerJosh Suereth <joshua.suereth@gmail.com>2012-09-18 15:36:14 -0400
commitfd4c197cf1c62236d2bd07f09e6866c149a10867 (patch)
treeee4dc152782fb61a0367bf6e7ae61ffff4afc0fd /test/osgi
parentd7acf92be65b6005aaab33e071b4bff1d7aa9911 (diff)
downloadscala-fd4c197cf1c62236d2bd07f09e6866c149a10867.tar.gz
scala-fd4c197cf1c62236d2bd07f09e6866c149a10867.tar.bz2
scala-fd4c197cf1c62236d2bd07f09e6866c149a10867.zip
Adds very simplistic reflection in OSGi test. Provides the framework
to discover important reflection bugs in OSGi containers.
Diffstat (limited to 'test/osgi')
-rw-r--r--test/osgi/src/BasicReflection.scala66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/osgi/src/BasicReflection.scala b/test/osgi/src/BasicReflection.scala
new file mode 100644
index 0000000000..7dd958d6fd
--- /dev/null
+++ b/test/osgi/src/BasicReflection.scala
@@ -0,0 +1,66 @@
+package tools.test.osgi
+package reflection
+package allmirrors
+
+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] =
+ scalaBundles
+
+ // 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)
+ }
+}