use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class FieldAdHocTest method doTestAccessibleFlagIsRefreshed.
/**
* When a Field is "regotten" the newly gotten Field will have to be a "fresh" object with its accessibility flag
* NOT set.
*/
private void doTestAccessibleFlagIsRefreshed(String scope) throws Exception {
registry = getTypeRegistry("reflection.fields..*");
targetClass = reloadableClass("reflection.fields.FieldSetAccessTarget");
callerClazz = nonReloadableClass(INVOKER_CLASS_NAME);
callerInstance = newInstance(callerClazz);
String fieldToAccess = scope + "Field";
String expectMsg = "Class " + INVOKER_CLASS_NAME + " " + "can not access a member of class " + targetClass.dottedtypename + " " + "with modifiers \"" + (scope.equals("default") ? "" : scope) + "\"";
//First... we do set the Access flag, it should work!
Result r = runOnInstance(callerClazz, callerInstance, "getFieldWithAccess", targetClass.getClazz(), fieldToAccess, true);
Assert.assertEquals(r.returnValue, fieldToAccess + " value");
//Then... we do not set the Access flag, it should fail!
try {
r = runOnInstance(callerClazz, callerInstance, "getFieldWithAccess", targetClass.getClazz(), fieldToAccess, false);
Assert.fail("Without setting access flag shouldn't be allowed!");
} catch (ResultException e) {
assertIllegalAccess(expectMsg, e);
}
//Finally, this should also still work... after we reload the type!
reloadType(targetClass, "002");
//First... we do set the Access flag, it should work!
r = runOnInstance(callerClazz, callerInstance, "getFieldWithAccess", targetClass.getClazz(), fieldToAccess, true);
Assert.assertEquals("new " + fieldToAccess + " value", r.returnValue);
//Then... we do not set the Access flag, it should not be allowed!
try {
r = runOnInstance(callerClazz, callerInstance, "getFieldWithAccess", targetClass.getClazz(), fieldToAccess, false);
Assert.fail("Without setting access flag shouldn't be allowed!");
} catch (ResultException e) {
assertIllegalAccess(expectMsg, e);
}
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class FieldAdHocTest method test_accessDeletedField.
@Test
public void test_accessDeletedField() throws Exception {
registry = getTypeRegistry("reflection.fields..*");
targetClass = reloadableClass("reflection.fields.ClassTarget");
Object targetInstance = newInstance(targetClass.getClazz());
Field f = jlClassGetField(targetClass.getClazz(), "myDeletedField");
Assert.assertEquals("myDeletedField", f.getName());
// First try to access the field before reloading
callerClazz = nonReloadableClass(INVOKER_CLASS_NAME);
callerInstance = newInstance(callerClazz);
Result r = runOnInstance(callerClazz, callerInstance, "callGet", f, targetInstance);
Assert.assertEquals(100, r.returnValue);
// Now reload the class... field is deleted
reloadType(targetClass, "002");
try {
r = runOnInstance(callerClazz, callerInstance, "callGet", f, targetInstance);
Assert.fail("Expected an error");
} catch (ResultException re) {
Throwable e = re.getCause();
// e.printStackTrace();
Assert.assertEquals(InvocationTargetException.class, e.getClass());
//Nested exception
e = e.getCause();
Assert.assertEquals(NoSuchFieldError.class, e.getClass());
Assert.assertEquals("myDeletedField", e.getMessage());
}
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class FieldGetAnnotationsTest method test.
@Override
public Result test() throws ResultException, Exception {
try {
Result r = runOnInstance(callerClazz, callerInstance, testedMethodCaller, field);
Assert.assertTrue(r.returnValue instanceof List<?>);
return r;
} catch (ResultException e) {
throw new Error(e);
}
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class MethodGetAnnotationsTest method test.
@Override
public Result test() throws ResultException, Exception {
try {
Result r = runOnInstance(callerClazz, callerInstance, testedMethodCaller, method);
Assert.assertTrue(r.returnValue instanceof List<?>);
return r;
} catch (ResultException e) {
throw new Error(e);
}
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ClassGetAnnotationsTest method test.
@Override
public Result test() throws ResultException, Exception {
try {
Result r = runOnInstance(callerClazz, callerInstance, testedMethodCaller, targetClass);
Assert.assertTrue(r.returnValue instanceof List<?>);
return r;
} catch (ResultException e) {
throw new Error(e);
}
}
Aggregations