2 * Copyright (c) 2013 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
8 package org.opendaylight.protocol.bgp.rib.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Mockito.doReturn;
13 import io.netty.util.concurrent.Future;
14 import io.netty.util.concurrent.GlobalEventExecutor;
16 import java.net.InetAddress;
17 import java.net.InetSocketAddress;
18 import java.util.Collections;
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.mockito.Mock;
24 import org.mockito.MockitoAnnotations;
25 import org.opendaylight.protocol.bgp.parser.BGPParameter;
26 import org.opendaylight.protocol.bgp.parser.BGPSession;
27 import org.opendaylight.protocol.bgp.rib.impl.BGPImpl.BGPListenerRegistration;
28 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPConnection;
29 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
30 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
31 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionProposal;
32 import org.opendaylight.protocol.framework.NeverReconnectStrategy;
33 import org.opendaylight.protocol.framework.ProtocolMessageFactory;
34 import org.opendaylight.protocol.framework.ReconnectStrategy;
36 public class BGPImplTest {
39 private BGPDispatcher disp;
42 private BGPSessionProposal prop;
45 private ProtocolMessageFactory parser;
48 private Future<BGPSession> future;
53 public void setUp() throws Exception {
54 MockitoAnnotations.initMocks(this);
55 doReturn("").when(this.parser).toString();
57 doReturn(null).when(this.future).get();
58 doReturn(future).when(this.disp).createClient(any(BGPConnection.class), any(ProtocolMessageFactory.class), any(ReconnectStrategy.class));
62 public void testBgpImpl() throws Exception {
63 doReturn(new BGPSessionPreferences(null, 0, null, Collections.<BGPParameter> emptyList())).when(this.prop).getProposal();
64 this.bgp = new BGPImpl(this.disp, this.parser, new InetSocketAddress(InetAddress.getLoopbackAddress(), 2000), this.prop, null);
65 final BGPListenerRegistration reg = this.bgp.registerUpdateListener(new SimpleSessionListener(), new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000));
66 assertEquals(SimpleSessionListener.class, reg.getListener().getClass());
70 public void tearDown() {