SPRNET-942 - ExceptionHandlerAdvice doesn't allow for explicitly configured Handlers

This commit is contained in:
markpollack
2008-06-10 03:37:11 +00:00
parent 4c91c42635
commit 26c254d5f1
3 changed files with 817 additions and 738 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -79,7 +79,7 @@ namespace Spring.Aspects.Exceptions
private string onExceptionNameRegex = @"^(on\s+exception\s+name)\s+(.*?)\s+(log|translate|wrap|replace|return|swallow)\s*(.*?)$";
private string onExceptionRegex = @"^(on\s+exception\s+)(\(.*?\))\s+(log|translate|wrap|replace|return|swallow)\s*(.*?)$";
#endregion
#region Properties
@@ -241,6 +241,11 @@ namespace Spring.Aspects.Exceptions
}
newExceptionHandlers.Add(handler);
}
IExceptionHandler handlerObject = o as IExceptionHandler;
if (handlerObject != null)
{
newExceptionHandlers.Add(handlerObject);
}
}
//TODO sync.

View File

@@ -54,8 +54,6 @@ namespace Spring.Aspects.Exceptions
[Test]
public void LoggingTest()
{
LogExceptionHandler logHandler = new LogExceptionHandler();
string testText = @"#log.Debug('Hello World, exception message = ' + #e.Message + ', target method = ' + #method.Name)";
logHandler.SourceExceptionNames.Add("ArithmeticException");
@@ -86,7 +84,6 @@ namespace Spring.Aspects.Exceptions
ExecuteLoggingHandler(logHandlerText);
}
[Test]
public void LoggingTestWithConstraintExpression()
{
@@ -95,6 +92,17 @@ namespace Spring.Aspects.Exceptions
ExecuteLoggingHandler(logHandlerText);
}
[Test]
public void LoggingTestWithConstraintExpressionWithExceptionHandler()
{
LogExceptionHandler exHandler = new LogExceptionHandler();
exHandler.ConstraintExpressionText = "#e is T(System.ArithmeticException)";
exHandler.LogName = "Cms.Session.ExceptionHandler";
exHandler.ActionExpressionText = "#log.Fatal('Request Timeout occured', #e)";
ExecuteLoggingHandler(exHandler);
}
[Test]
[ExpectedException(typeof(ArgumentException))]
public void LoggingTestWithBadString()
@@ -142,6 +150,20 @@ namespace Spring.Aspects.Exceptions
}
}
private void ExecuteLoggingHandler(IExceptionHandler handler)
{
ITestObject to = CreateTestObjectProxy(handler);
try
{
to.Exceptional(new ArithmeticException());
}
catch (ArithmeticException)
{
//TODO assert logging occured.
}
}
[Test]
@@ -151,6 +173,25 @@ namespace Spring.Aspects.Exceptions
"on exception name ArithmeticException translate new System.InvalidOperationException('My Message, Method Name ' + #method.Name, #e)";
ITestObject to = CreateTestObjectProxy(translationHandlerText);
AssertTranslation(to);
}
[Test]
public void TranslateWithExceptionHandlerInstance()
{
TranslationExceptionHandler exHandler = new TranslationExceptionHandler();
IList exceptionNames = new ArrayList();
exceptionNames.Add("ArithmeticException");
exHandler.SourceExceptionNames = exceptionNames;
exHandler.ActionExpressionText =
"new System.InvalidOperationException('My Message, Method Name ' + #method.Name, #e)";
ITestObject to = CreateTestObjectProxy(exHandler);
AssertTranslation(to);
}
private static void AssertTranslation(ITestObject to)
{
try
{
to.Exceptional(new ArithmeticException("Bad Math"));
@@ -160,7 +201,8 @@ namespace Spring.Aspects.Exceptions
{
Assert.IsInstanceOfType(typeof(ArithmeticException), e.InnerException, "Inner exception.");
Assert.AreEqual("My Message, Method Name Exceptional", e.Message);
} catch (Exception e)
}
catch (Exception e)
{
Assert.IsInstanceOfType(typeof(InvalidOperationException), e, "wrong exception type thrown.");
}
@@ -339,8 +381,18 @@ namespace Spring.Aspects.Exceptions
private ITestObject CreateTestObjectProxy(string logHandlerText)
{
exceptionHandlerAdvice.ExceptionHandlers.Add(logHandlerText);
exceptionHandlerAdvice.AfterPropertiesSet();
return CreateProxy();
}
private ITestObject CreateTestObjectProxy(IExceptionHandler exceptionHander)
{
exceptionHandlerAdvice.ExceptionHandlers.Add(exceptionHander);
return CreateProxy();
}
private ITestObject CreateProxy()
{
exceptionHandlerAdvice.AfterPropertiesSet();
ProxyFactory pf = new ProxyFactory(new TestObject());
pf.AddAdvice(exceptionHandlerAdvice);
return (ITestObject)pf.GetProxy();