Author: wglass Date: Fri Nov 10 07:19:09 2006 New Revision: 473363 URL: http://svn.apache.org/viewvc?view=rev&rev=473363 Log: throw methodinvcationexception from velocimacros. VELOCITY-284.
Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/MethodInvocationExceptionTestCase.java Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java?view=diff&rev=473363&r1=473362&r2=473363 ============================================================================== --- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java (original) +++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java Fri Nov 10 07:19:09 2006 @@ -76,8 +76,9 @@ /** * Get an object from the context, or null if the key is equal to the loop variable * @see org.apache.velocity.context.InternalContextAdapter#get(java.lang.String) + * @exception MethodInvocationException passes on potential exception from reference method call */ - public Object get( String key ) + public Object get( String key ) throws MethodInvocationException { return ( active && loopVariableKey.equals(key) ) ? null @@ -98,8 +99,14 @@ } /** + * Allows callers to explicitly put objects in the local context. + * Objects added to the context through this method always end up + * in the top-level context of possible wrapped contexts. + * + * @param key name of item to set. + * @param value object to set to key. * @see InternalWrapperContext#localPut(String, Object) - */ + */ public Object localPut(final String key, final Object value) { return put(key, value); Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java?view=diff&rev=473363&r1=473362&r2=473363 ============================================================================== --- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java (original) +++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VMProxyArg.java Fri Nov 10 07:19:09 2006 @@ -242,9 +242,9 @@ * * @param context Context to use for getting current value * @return Object value - * + * @exception MethodInvocationException passes on potential exception from reference method call */ - public Object getObject( InternalContextAdapter context ) + public Object getObject( InternalContextAdapter context ) throws MethodInvocationException { try { @@ -358,8 +358,7 @@ */ log.error("VMProxyArg.getObject() : method invocation error getting value", mie); - - return null; + throw mie; } } Modified: jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/MethodInvocationExceptionTestCase.java URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/MethodInvocationExceptionTestCase.java?view=diff&rev=473363&r1=473362&r2=473363 ============================================================================== --- jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/MethodInvocationExceptionTestCase.java (original) +++ jakarta/velocity/engine/trunk/src/test/org/apache/velocity/test/MethodInvocationExceptionTestCase.java Fri Nov 10 07:19:09 2006 @@ -39,6 +39,7 @@ { /** * Default constructor. + * @param name */ public MethodInvocationExceptionTestCase(String name) { @@ -65,6 +66,7 @@ * uses the Velocity class to eval a string * which accesses a method that throws an * exception. + * @throws Exception */ public void testNormalMethodInvocationException () throws Exception @@ -203,6 +205,7 @@ * test that no exception is thrown when in parameter to macro. * This is the way we expect the system to work, but it would be better * to throw an exception. + * @throws Exception */ public void testMacroInvocationException () throws Exception @@ -217,10 +220,25 @@ try { Velocity. evaluate( vc, w, "test", template ); + fail("No exception thrown, macro invocation test."); } catch( MethodInvocationException mie ) { - fail("Shouldn't have thrown exception, macro param test."); + System.out.println("Caught MIE (good!) :" ); + System.out.println(" reference = " + mie.getReferenceName() ); + System.out.println(" method = " + mie.getMethodName() ); + + Throwable t = mie.getWrappedThrowable(); + System.out.println(" throwable = " + t ); + + if( t instanceof Exception) + { + System.out.println(" exception = " + ( (Exception) t).getMessage() ); + } + } + catch( Exception e) + { + fail("Wrong exception thrown, test of exception within macro parameter"); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]