X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2FAbstractConfigTest.java;h=64ce14e8f1733b8ab28465a9edd4a191141a6a09;hp=028d7d1f40d83077dd9fe5359fed4b12d349d3b2;hb=91d7c1ee52322acad08e9f81228ac36b3aa684f5;hpb=515e60d60ac7dd08aa2440468cd8dab42892e7d0 diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigTest.java index 028d7d1f40..64ce14e8f1 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/AbstractConfigTest.java @@ -31,12 +31,17 @@ import org.slf4j.LoggerFactory; import javax.management.InstanceAlreadyExistsException; import javax.management.MBeanServer; import javax.management.ObjectName; +import javax.management.RuntimeMBeanException; import java.io.Closeable; import java.io.InputStream; import java.lang.management.ManagementFactory; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; import java.util.Dictionary; import java.util.List; import java.util.Set; @@ -249,4 +254,30 @@ public abstract class AbstractConfigTest extends } } } + + /** + * Expand inner exception wrapped by JMX + * + * @param innerObject jmx proxy which will be wrapped and returned + */ + protected T rethrowCause(final T innerObject) { + + Object proxy = Proxy.newProxyInstance(innerObject.getClass().getClassLoader(), + innerObject.getClass().getInterfaces(), new InvocationHandler() { + @Override + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + try { + return method.invoke(innerObject, args); + } catch (InvocationTargetException e) { + try { + throw e.getTargetException(); + } catch (RuntimeMBeanException e2) { + throw e2.getTargetException(); + } + } + } + }); + return (T) proxy; + } + }