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=d9bbeb4a2c9de5ab420eebbaaf702271e381b8a1;hp=028d7d1f40d83077dd9fe5359fed4b12d349d3b2;hb=20500c9eb46d1ceb99d742d1c110dcb7c558dc2b;hpb=0ae12c54560ef14cb8c08beef4553f7523d41578 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..d9bbeb4a2c 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 @@ -23,6 +23,7 @@ import org.opendaylight.controller.config.manager.testingservices.threadpool.Tes import org.opendaylight.controller.config.spi.Module; import org.opendaylight.controller.config.util.ConfigRegistryJMXClient; import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; +import org.opendaylight.yangtools.yang.data.impl.codec.CodecRegistry; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; import org.slf4j.Logger; @@ -31,12 +32,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; @@ -92,7 +98,7 @@ public abstract class AbstractConfigTest extends baseJmxRegistrator = new BaseJMXRegistrator(internalJmxRegistrator); configRegistry = new ConfigRegistryImpl(resolver, - platformMBeanServer, baseJmxRegistrator); + platformMBeanServer, baseJmxRegistrator, getCodecRegistry()); try { configRegistryJMXRegistrator.registerToJMX(configRegistry); @@ -203,6 +209,10 @@ public abstract class AbstractConfigTest extends return new ClassBasedModuleFactory(implementationName, configBeanClass); } + protected CodecRegistry getCodecRegistry() { + return mock(CodecRegistry.class); + } + public static interface BundleContextServiceRegistrationHandler { @@ -210,10 +220,10 @@ public abstract class AbstractConfigTest extends } - private class RegisterServiceAnswer implements Answer { + private class RegisterServiceAnswer implements Answer> { @Override - public Object answer(InvocationOnMock invocation) throws Throwable { + public ServiceRegistration answer(InvocationOnMock invocation) throws Throwable { Object[] args = invocation.getArguments(); Preconditions.checkArgument(args.length == 3, "Unexpected arguments size (expected 3 was %s)", args.length); @@ -249,4 +259,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; + } + }