use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ClassReflectionTests method test_callInheritedOverridenDeletedMethod.
/**
* Test related to calling 'invoke' on a method declared in superclass and overriden in the subclass (via a method
* object gotten from the superclass).
* <p>
* What if the super method is deleted in v002?
*/
@Test
public void test_callInheritedOverridenDeletedMethod() throws Exception {
Result r = getDeclaredMethod("overrideMethodDeleted");
assertMethod("public java.lang.String " + TARGET_CLASS_NAME + ".overrideMethodDeleted()", r);
Method m = (Method) r.returnValue;
// Setup subClass and an instance of the subclass
String subClassName = TARGET_PACKAGE + ".SubClassTarget";
ReloadableType subTarget = registry.addType(subClassName, loadBytesForClass(subClassName));
Object subInstance = subTarget.getClazz().newInstance();
// Calling the superclass method on the subinstance should execute the subclass method!
r = invokeOn(subInstance, m);
assertEquals("SubClassTarget.overrideMethodDeleted", r.returnValue);
// Now try what happens if we reload the superclass type, deleting the method
reloadType("002");
try {
r = invokeOn(subInstance, m);
fail("The method was deleted, should fail!");
} catch (ResultException e) {
assertNoSuchMethodError("reflection.targets.ClassTarget.overrideMethodDeleted()Ljava/lang/String;", e);
}
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ClassReflectionTests method test_getDeclaredMethodStaysAndInvoke.
/**
* Testing Class.getDeclaredMethod and Method.invoke
*
* Can we retrieve and invoke a method that existed before we reloaded the type?
*/
@Test
public void test_getDeclaredMethodStaysAndInvoke() throws Exception {
Result r = getDeclaredMethodAndInvoke("methodStays");
Assert.assertEquals(99, r.returnValue);
reloadType("002");
r = getDeclaredMethodAndInvoke("methodStays");
Assert.assertEquals(99, r.returnValue);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ClassReflectionTests method test_getDeclaredMethodStays.
/**
* Testing Class.getDeclaredMethod() - the method exists from the start and stays
*/
@Test
public void test_getDeclaredMethodStays() throws Exception {
Result r = getDeclaredMethod("methodStays");
assertMethod("public int " + TARGET_CLASS_NAME + ".methodStays()", r);
reloadType("002");
r = getDeclaredMethod("methodStays");
assertMethod("public int " + TARGET_CLASS_NAME + ".methodStays()", r);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ClassReflectionTests method test_callInheritedOverridenMethod2.
/**
* Test related to calling 'invoke' on a method declared in superclass and overridden in the subclass (via a method
* object gotten from the superclass).
* <p>
* Variant of the previous test, where the class containing the overridden method is reloaded. (This case is
* different because it will use CLV to determine an executor method).
*/
@Test
public void test_callInheritedOverridenMethod2() throws Exception {
reloadType(target, "002");
Result r = getDeclaredMethod("overrideMethod");
assertMethod("public java.lang.String " + TARGET_CLASS_NAME + ".overrideMethod()", r);
Method m = (Method) r.returnValue;
// Double check if we are using the right version...
r = invoke(m);
assertEquals("ClassTarget002.overrideMethod", r.returnValue);
// Setup subClass and an instance of the subclass
String subClassName = TARGET_PACKAGE + ".SubClassTarget";
ReloadableType subTarget = registry.addType(subClassName, loadBytesForClass(subClassName));
Object subInstance = subTarget.getClazz().newInstance();
// Calling the superclass method on the subinstance should execute the subclass method!
r = invokeOn(subInstance, m);
assertEquals("SubClassTarget.overrideMethod", r.returnValue);
// Now try what happens if we reload the subclass type, changing the method
reloadType(subTarget, "002");
r = invokeOn(subInstance, m);
assertEquals("SubClassTarget002.overrideMethod", r.returnValue);
// Now try what happens if we reload the subclass type, DELETING the method
reloadType(subTarget, "003");
r = invokeOn(subInstance, m);
assertEquals("ClassTarget002.overrideMethod", r.returnValue);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ClassReflectionTests method test_invokePublicMethodInNonReloadableDefaultClassAllowed.
/**
* Invoking a public method inside a default class by means of "invoke" call, from within a class in the same
* package as the target class should be allowed.
*/
@Test
public void test_invokePublicMethodInNonReloadableDefaultClassAllowed() throws Exception {
// Class<?> defaultClass =
nonReloadableClass(TARGET_PACKAGE + "." + "DefaultClass");
Result r = getDeclaredMethodAndInvoke("callPublicMethodOnDefaultClass");
Assert.assertEquals(82, r.returnValue);
}
Aggregations