Remove reliance on BGPMessageFactory
[bgpcep.git] / bgp / testtool / src / test / java / org / opendaylight / protocol / bgp / testtool / BGPSpeakerMock.java
index bc97576179b65cf9db62741f5fd215bd407ff508..8f7a63cea2f1bc9b551608fe3a1db2ba9c5fb7e2 100644 (file)
@@ -7,24 +7,23 @@
  */
 package org.opendaylight.protocol.bgp.testtool;
 
+import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.util.HashedWheelTimer;
 import io.netty.util.concurrent.DefaultPromise;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import io.netty.util.concurrent.Promise;
 
-import java.io.IOException;
 import java.net.InetSocketAddress;
 
 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
-import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactoryImpl;
+import org.opendaylight.protocol.bgp.parser.spi.pojo.ServiceLoaderBGPExtensionProviderContext;
 import org.opendaylight.protocol.bgp.rib.impl.BGPHandlerFactory;
 import org.opendaylight.protocol.bgp.rib.impl.BGPSessionImpl;
 import org.opendaylight.protocol.bgp.rib.impl.BGPSessionNegotiatorFactory;
 import org.opendaylight.protocol.bgp.rib.impl.BGPSessionProposalImpl;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
 import org.opendaylight.protocol.framework.AbstractDispatcher;
-import org.opendaylight.protocol.framework.ProtocolHandlerFactory;
 import org.opendaylight.protocol.framework.ProtocolSession;
 import org.opendaylight.protocol.framework.SessionListener;
 import org.opendaylight.protocol.framework.SessionListenerFactory;
@@ -37,10 +36,11 @@ import com.google.common.base.Preconditions;
 public class BGPSpeakerMock<M, S extends ProtocolSession<M>, L extends SessionListener<M, ?, ?>> extends AbstractDispatcher<S, L> {
 
        private final SessionNegotiatorFactory<M, S, L> negotiatorFactory;
-       private final ProtocolHandlerFactory<?> factory;
+       private final BGPHandlerFactory factory;
 
-       public BGPSpeakerMock(final SessionNegotiatorFactory<M, S, L> negotiatorFactory, final ProtocolHandlerFactory<?> factory,
+       public BGPSpeakerMock(final SessionNegotiatorFactory<M, S, L> negotiatorFactory, final BGPHandlerFactory factory,
                        final DefaultPromise<BGPSessionImpl> defaultPromise) {
+               super(new NioEventLoopGroup(), new NioEventLoopGroup());
                this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory);
                this.factory = Preconditions.checkNotNull(factory);
        }
@@ -58,7 +58,7 @@ public class BGPSpeakerMock<M, S extends ProtocolSession<M>, L extends SessionLi
                });
        }
 
-       public static void main(final String[] args) throws IOException {
+       public static void main(final String[] args) throws Exception {
 
                final SessionListenerFactory<BGPSessionListener> f = new SessionListenerFactory<BGPSessionListener>() {
                        @Override
@@ -72,7 +72,7 @@ public class BGPSpeakerMock<M, S extends ProtocolSession<M>, L extends SessionLi
                final SessionNegotiatorFactory<Notification, BGPSessionImpl, BGPSessionListener> snf = new BGPSessionNegotiatorFactory(new HashedWheelTimer(), prefs);
 
                final BGPSpeakerMock<Notification, BGPSessionImpl, BGPSessionListener> mock = new BGPSpeakerMock<>(snf,
-                               new BGPHandlerFactory(BGPMessageFactoryImpl.getInstance()),
+                               new BGPHandlerFactory(ServiceLoaderBGPExtensionProviderContext.createConsumerContext().getMessageRegistry()),
                                new DefaultPromise<BGPSessionImpl>(GlobalEventExecutor.INSTANCE));
 
                mock.createServer(new InetSocketAddress("127.0.0.2", 12345), f);