BUG-58: refactor to take advantage of netty
[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.parser.BGPSessionListener;
28 import org.opendaylight.protocol.bgp.parser.impl.BGPMessageFactory;
29 import org.opendaylight.protocol.bgp.rib.impl.BGPImpl.BGPListenerRegistration;
30 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
31 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
32 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionProposal;
33 import org.opendaylight.protocol.framework.NeverReconnectStrategy;
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 BGPMessageFactory 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(InetSocketAddress.class), any(BGPSessionPreferences.class),
59                                 any(BGPSessionListener.class), any(ReconnectStrategy.class));
60         }
61
62         @Test
63         public void testBgpImpl() throws Exception {
64                 doReturn(new BGPSessionPreferences(null, 0, null, Collections.<BGPParameter> emptyList())).when(this.prop).getProposal();
65                 this.bgp = new BGPImpl(this.disp, new InetSocketAddress(InetAddress.getLoopbackAddress(), 2000), this.prop);
66                 final BGPListenerRegistration reg = this.bgp.registerUpdateListener(new SimpleSessionListener(), new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000));
67                 assertEquals(SimpleSessionListener.class, reg.getListener().getClass());
68         }
69
70         @After
71         public void tearDown() {
72                 this.bgp.close();
73         }
74 }