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;
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;
baseJmxRegistrator = new BaseJMXRegistrator(internalJmxRegistrator);
configRegistry = new ConfigRegistryImpl(resolver,
- platformMBeanServer, baseJmxRegistrator);
+ platformMBeanServer, baseJmxRegistrator, getCodecRegistry());
try {
configRegistryJMXRegistrator.registerToJMX(configRegistry);
return new ClassBasedModuleFactory(implementationName, configBeanClass);
}
+ protected CodecRegistry getCodecRegistry() {
+ return mock(CodecRegistry.class);
+ }
public static interface BundleContextServiceRegistrationHandler {
}
- private class RegisterServiceAnswer implements Answer {
+ private class RegisterServiceAnswer implements Answer<ServiceRegistration<?>> {
@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);
}
}
}
+
+ /**
+ * Expand inner exception wrapped by JMX
+ *
+ * @param innerObject jmx proxy which will be wrapped and returned
+ */
+ protected <T> 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;
+ }
+
}