You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2010/11/20 19:48:32 UTC

svn commit: r1037296 - /incubator/clerezza/trunk/scala-scripting/tests/src/test/scala/org/apache/clerezza/scala/tests/CompilerServiceTest.scala

Author: reto
Date: Sat Nov 20 18:48:32 2010
New Revision: 1037296

URL: http://svn.apache.org/viewvc?rev=1037296&view=rev
Log:
CLEREZZA-362: testing that the class is available even if a new class has been compiled in between with the same name

Modified:
    incubator/clerezza/trunk/scala-scripting/tests/src/test/scala/org/apache/clerezza/scala/tests/CompilerServiceTest.scala

Modified: incubator/clerezza/trunk/scala-scripting/tests/src/test/scala/org/apache/clerezza/scala/tests/CompilerServiceTest.scala
URL: http://svn.apache.org/viewvc/incubator/clerezza/trunk/scala-scripting/tests/src/test/scala/org/apache/clerezza/scala/tests/CompilerServiceTest.scala?rev=1037296&r1=1037295&r2=1037296&view=diff
==============================================================================
--- incubator/clerezza/trunk/scala-scripting/tests/src/test/scala/org/apache/clerezza/scala/tests/CompilerServiceTest.scala (original)
+++ incubator/clerezza/trunk/scala-scripting/tests/src/test/scala/org/apache/clerezza/scala/tests/CompilerServiceTest.scala Sat Nov 20 18:48:32 2010
@@ -27,6 +27,9 @@ import org.ops4j.pax.exam.CoreOptions._;
 import org.ops4j.pax.exam.container.`def`.PaxRunnerOptions._;
 import org.ops4j.pax.exam.junit.JUnitOptions._;
 
+import java.security.AccessController
+import java.security.PrivilegedActionException
+import java.security.PrivilegedExceptionAction
 import org.apache.clerezza.scala.scripting.CompilerService
 import org.junit.Assert
 import org.junit.Before;
@@ -73,7 +76,7 @@ class CompilerServiceTest {
 	def checkEngine(): Unit =  {
 		Assert.assertNotNull(service);
 		//do it once
-		{
+		val testClassClass1 = {
 			val s = """
 			package foo {
 				class TestClass() {
@@ -85,13 +88,12 @@ class CompilerServiceTest {
 				}
 			}
 			"""
-			val compileResult = service.compile(List(s.toCharArray))
+			val compileResult = priv(service.compile(List(s.toCharArray)))
 			println("finished compiling")
 			Assert.assertEquals(1, compileResult.size)
 			val testClassClass: Class[_] = compileResult(0)
-			Assert.assertEquals("foo.TestClass", testClassClass.getName)
-			val method = testClassClass.getMethod("msg")
-			Assert.assertEquals("Hello", method.invoke(null))
+			//Assert.assertEquals("foo.TestClass", testClassClass.getName)
+			testClassClass
 		}
 		//compile different class with same name
 		{
@@ -106,12 +108,14 @@ class CompilerServiceTest {
 				}
 			}
 			"""
-			val compileResult = service.compile(List(s.toCharArray))
+			val compileResult = priv(service.compile(List(s.toCharArray)))
 			val testClassClass: Class[_] = compileResult(0)
 			Assert.assertEquals("foo.TestClass", testClassClass.getName)
 			val method = testClassClass.getMethod("msg")
 			Assert.assertEquals("Hello2", method.invoke(null))
 		}
+		val methodFrom1Again = testClassClass1.getMethod("msg")
+		Assert.assertEquals("Hello", methodFrom1Again.invoke(null))
 	}
 
 	@Test
@@ -138,7 +142,7 @@ object """+objectName+""" {
 
 							//println("compiling: "+source)
 							val sources = List(source.toCharArray)
-							val compiled = service.compile(sources)
+							val compiled = priv(service.compile(sources))
 							val clazz = compiled(0)
 							val className = clazz.getName
 							testRunner ! (objectName, className)
@@ -166,6 +170,18 @@ object """+objectName+""" {
 
 	}
 
+	def priv[T](action: => T): T = {
+		try {
+			AccessController.doPrivileged(
+			new PrivilegedExceptionAction[T]() {
+				def run = action
+			})
+		} catch {
+			case e: PrivilegedActionException => throw e.getCause
+			case e => throw e
+		}
+	}
+
 }
 
 object CompilerServiceTest {