Rename distribution-karaf artifact to bgpcep-karaf
[bgpcep.git] / bgp / rib-impl / src / test / java / org / opendaylight / protocol / bgp / rib / impl / state / BGPStateCollectorImplTest.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.protocol.bgp.rib.impl.state;
10
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.mock;
15
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.mockito.Mock;
19 import org.mockito.MockitoAnnotations;
20 import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerState;
21 import org.opendaylight.protocol.bgp.rib.spi.state.BGPPeerStateConsumer;
22 import org.opendaylight.protocol.bgp.rib.spi.state.BGPRibState;
23 import org.opendaylight.protocol.bgp.rib.spi.state.BGPRibStateConsumer;
24
25 public class BGPStateCollectorImplTest {
26     @Mock
27     private BGPRibStateConsumer bgpribStateConsumer;
28     @Mock
29     private BGPPeerStateConsumer bgpPeerStateConsumer;
30
31     @Before
32     public void setUp() {
33         MockitoAnnotations.initMocks(this);
34     }
35
36     @Test
37     public void getRibStatsTest() {
38         doReturn(mock(BGPPeerState.class)).when(this.bgpPeerStateConsumer).getPeerState();
39         doReturn(mock(BGPRibState.class)).when(this.bgpribStateConsumer).getRIBState();
40         final BGPStateCollectorImpl collector = new BGPStateCollectorImpl();
41
42         collector.bind(this.bgpribStateConsumer);
43         collector.bind(this.bgpPeerStateConsumer);
44         assertFalse(collector.getRibStats().isEmpty());
45         assertFalse(collector.getPeerStats().isEmpty());
46
47         collector.unbind(this.bgpribStateConsumer);
48         collector.unbind(this.bgpPeerStateConsumer);
49         assertTrue(collector.getRibStats().isEmpty());
50         assertTrue(collector.getPeerStats().isEmpty());
51     }
52
53     @Test
54     public void getRibStatsEmptyPeerTest() {
55         doReturn(mock(BGPRibState.class)).when(this.bgpribStateConsumer).getRIBState();
56         doReturn(null).when(this.bgpPeerStateConsumer).getPeerState();
57         final BGPStateCollectorImpl collector = new BGPStateCollectorImpl();
58
59         collector.bind(this.bgpribStateConsumer);
60         collector.bind(this.bgpPeerStateConsumer);
61         assertFalse(collector.getRibStats().isEmpty());
62         assertTrue(collector.getPeerStats().isEmpty());
63     }
64
65     @Test
66     public void getRibStatsEmptyRibTest() {
67         doReturn(null).when(this.bgpribStateConsumer).getRIBState();
68         doReturn(null).when(this.bgpPeerStateConsumer).getPeerState();
69         final BGPStateCollectorImpl collector = new BGPStateCollectorImpl();
70         assertTrue(collector.getRibStats().isEmpty());
71         assertTrue(collector.getPeerStats().isEmpty());
72
73         collector.bind(this.bgpribStateConsumer);
74         collector.bind(this.bgpPeerStateConsumer);
75         assertTrue(collector.getRibStats().isEmpty());
76         assertTrue(collector.getPeerStats().isEmpty());
77     }
78 }