9e9e8b62fe4ec530b5f571fc6ff705a1677d29e0
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / BGPImplTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.rib.impl;
9
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;
15
16 import java.net.InetAddress;
17 import java.net.InetSocketAddress;
18 import java.util.Collections;
19
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;
35
36 public class BGPImplTest {
37
38         @Mock
39         private BGPDispatcher disp;
40
41         @Mock
42         private BGPSessionProposal prop;
43
44         @Mock
45         private ProtocolMessageFactory parser;
46
47         @Mock
48         private Future<BGPSession> future;
49
50         private BGPImpl bgp;
51
52         @Before
53         public void setUp() throws Exception {
54                 MockitoAnnotations.initMocks(this);
55                 doReturn("").when(this.parser).toString();
56
57                 doReturn(null).when(this.future).get();
58                 doReturn(future).when(this.disp).createClient(any(BGPConnection.class), any(ProtocolMessageFactory.class), any(ReconnectStrategy.class));
59         }
60
61         @Test
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());
67         }
68
69         @After
70         public void tearDown() {
71                 this.bgp.close();
72         }
73 }