Updates stx:libjava/libs definition.
To use new javaBundle method to define java code doe this package.
"
Copyright (c) 2010-2011 Jan Vrany, Jan Kurs & Marcel Hlopko,
SWING Research Group, Czech Technical University
in Prague
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"
"{ Package: 'stx:libjava/experiments' }"
TestCase subclass:#JavaClassReloadingTests
instanceVariableNames:'testClassLoader'
classVariableNames:''
poolDictionaries:''
category:'Languages-Java-Tests-ClassReloading'
!
!JavaClassReloadingTests class methodsFor:'documentation'!
copyright
"
Copyright (c) 2010-2011 Jan Vrany, Jan Kurs & Marcel Hlopko,
SWING Research Group, Czech Technical University
in Prague
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
"
!
history
"Created: #resources / 21-12-2012 / 18:09:27 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
! !
!JavaClassReloadingTests class methodsFor:'resources'!
resources
^ Array
with: JavaInitializedResource.
"Created: / 21-12-2012 / 18:09:27 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
! !
!JavaClassReloadingTests methodsFor:'private'!
compile: sourceCode
| classes |
classes := JavaCompiler compile: sourceCode.
"/ classes do:[:cls|cls classLoader: testClassLoader] .
^classes
"Created: / 16-12-2012 / 17:02:41 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
"Modified: / 09-04-2013 / 22:39:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
compileAndRegister: sourceCode
|compiledClasses|
compiledClasses := self compile: sourceCode.
^ self register: compiledClasses.
"Created: / 16-12-2012 / 16:59:19 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
!
performTest
JavaClassReader classLoaderQuerySignal answer: testClassLoader do:[
super performTest
].
"Created: / 16-12-2012 / 16:35:01 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
!
register: aClassOrArray
^aClassOrArray isArray ifTrue:[
JavaVM registry registerClasses: aClassOrArray .
JavaVM registry classNamed: aClassOrArray anElement name loader: aClassOrArray anElement classLoader
] ifFalse:[
JavaVM registry registerClass: aClassOrArray.
JavaVM registry classNamed: aClassOrArray name loader: aClassOrArray classLoader
].
"Created: / 16-12-2012 / 17:02:04 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
"Modified: / 09-04-2013 / 22:27:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
testInfrastructure
|compiledClass|
self assert: (JavaClassReader classLoaderQuerySignal query = testClassLoader )
message: 'tests should run in testClassLoader sandbox'.
compiledClass := self compileAndRegister: '
public class HelloSun {
public String hello() {
return "helloooo";
}
}
'.
self assert: compiledClass notNil message: 'Java compiler should be working for these tests to run'.
self assert: compiledClass classLoader = testClassLoader message: 'compiled classes should have testClassLoader as their defining cl'.
self assert: (JavaVM registry getClassesDefinedBy: testClassLoader) size = 1 message: 'only classes from these tests should use testClassLoader'.
self assert: (JavaVM registry getClassesDefinedBy: testClassLoader) anElement == compiledClass message: 'compiled classes should be registered in testClassLoader'.
"Created: / 16-12-2012 / 16:38:17 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
! !
!JavaClassReloadingTests methodsFor:'running'!
setUp
testClassLoader := JAVA java lang ClassLoader new.
"Created: / 16-12-2012 / 16:32:32 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
!
tearDown
JavaVM registry unregisterClassLoader: testClassLoader.
"Created: / 16-12-2012 / 16:33:31 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
! !
!JavaClassReloadingTests methodsFor:'test helpers'!
callerClass
| callerClass |
callerClass := (JavaCompiler
compile: '
package classReloadingTests;
public class Caller {
public String callFooToString(Object c) {
return c.toString();
}
}
') anElement.
callerClass
ifNil: [ self error: 'callerClass is expected to be not nil in these tests' ].
^ callerClass.
"Created: / 06-12-2012 / 21:41:35 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
"Modified: / 18-12-2012 / 14:00:12 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
"Modified: / 04-01-2013 / 14:51:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
compileAndRegisterChangingClassParent
self compileAndRegister: '
package classReloadingTests;
public class ChangingClassParent {
public String foo() {
return "parent";
}
public String toString() {
return "" + foo();
}
}'.
"Created: / 18-12-2012 / 13:47:32 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
! !
!JavaClassReloadingTests class methodsFor:'documentation'!
version_CVS
^ '$Header: /cvs/stx/stx/libjava/experiments/ClassReloadingTests.st,v 1.2 2013-02-25 11:15:34 vrany Exp $'
!
version_HG
^ '$Changeset: <not expanded> $'
!
version_SVN
^ '§Id:: §'
! !