2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.protocol.bmp.mock;
11 import com.google.common.base.Optional;
12 import com.google.common.net.InetAddresses;
13 import io.netty.channel.Channel;
14 import io.netty.channel.ChannelFuture;
15 import io.netty.channel.nio.NioEventLoopGroup;
16 import java.net.InetSocketAddress;
17 import org.junit.Assert;
18 import org.junit.Test;
19 import org.mockito.Mockito;
20 import org.opendaylight.protocol.bmp.api.BmpSessionFactory;
21 import org.opendaylight.protocol.bmp.api.BmpSessionListenerFactory;
22 import org.opendaylight.protocol.bmp.impl.BmpDispatcherImpl;
23 import org.opendaylight.protocol.bmp.spi.registry.BmpMessageRegistry;
24 import org.opendaylight.tcpmd5.api.KeyMapping;
26 public class BmpMockDispatcherTest {
28 private final BmpMessageRegistry registry = Mockito.mock(BmpMessageRegistry.class);
29 private final BmpSessionFactory sessionFactory = Mockito.mock(BmpSessionFactory.class);
30 private final BmpSessionListenerFactory slf = Mockito.mock(BmpSessionListenerFactory.class);
33 public void testCreateClient() throws InterruptedException {
34 final BmpMockDispatcher dispatcher = new BmpMockDispatcher(this.registry, this.sessionFactory);
35 final int port = getRandomPort();
36 final BmpDispatcherImpl serverDispatcher = new BmpDispatcherImpl(new NioEventLoopGroup(), new NioEventLoopGroup(),
37 this.registry, this.sessionFactory);
38 serverDispatcher.createServer(new InetSocketAddress(InetAddresses.forString("0.0.0.0"), port), this.slf, Optional.<KeyMapping>absent());
40 final ChannelFuture channelFuture = dispatcher.createClient(new InetSocketAddress(InetAddresses.forString("127.0.0.2"), 0),
41 new InetSocketAddress(InetAddresses.forString("127.0.0.3"), port));
42 final Channel channel = channelFuture.sync().channel();
44 Assert.assertTrue(channel.isActive());
45 serverDispatcher.close();
48 protected static int getRandomPort() {
49 return (int) (Math.random() * 64000 + 1024);