Fix unit tests: unwrap InvocationTargetExceptions thrown by subsystems

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13682 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Dave Ward
2009-03-18 22:37:00 +00:00
parent fe184c4b7b
commit 13ed69561d

View File

@@ -24,6 +24,7 @@
*/ */
package org.alfresco.repo.management; package org.alfresco.repo.management;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Map; import java.util.Map;
@@ -57,22 +58,30 @@ public class ManagedSubsystemProxyFactory extends ProxyFactoryBean
public Object invoke(MethodInvocation mi) throws Throwable public Object invoke(MethodInvocation mi) throws Throwable
{ {
Method method = mi.getMethod(); Method method = mi.getMethod();
if (ManagedSubsystemProxyFactory.this.sourceBeanName == null) try
{ {
Map<?, ?> beans = ManagedSubsystemProxyFactory.this.sourceApplicationContextFactory if (ManagedSubsystemProxyFactory.this.sourceBeanName == null)
.getApplicationContext().getBeansOfType(method.getDeclaringClass());
if (beans.size() != 1)
{ {
throw new RuntimeException("Don't know where to route call to method " + method); Map<?, ?> beans = ManagedSubsystemProxyFactory.this.sourceApplicationContextFactory
.getApplicationContext().getBeansOfType(method.getDeclaringClass());
if (beans.size() != 1)
{
throw new RuntimeException("Don't know where to route call to method " + method);
}
return method.invoke(beans.values().iterator().next(), mi.getArguments());
} }
return method.invoke(beans.values().iterator().next(), mi.getArguments()); else
} {
else Object bean = ManagedSubsystemProxyFactory.this.sourceApplicationContextFactory
{ .getApplicationContext().getBean(ManagedSubsystemProxyFactory.this.sourceBeanName);
Object bean = ManagedSubsystemProxyFactory.this.sourceApplicationContextFactory return method.invoke(bean, mi.getArguments());
.getApplicationContext().getBean(ManagedSubsystemProxyFactory.this.sourceBeanName);
return method.invoke(bean, mi.getArguments());
}
}
catch (InvocationTargetException e)
{
// Unwrap invocation target exceptions
throw e.getTargetException();
} }
} }
})); }));