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.bgp.rib.impl.state;
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;
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;
25 public class BGPStateCollectorImplTest {
27 private BGPRibStateConsumer bgpribStateConsumer;
29 private BGPPeerStateConsumer bgpPeerStateConsumer;
33 MockitoAnnotations.initMocks(this);
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();
42 collector.bind(this.bgpribStateConsumer);
43 collector.bind(this.bgpPeerStateConsumer);
44 assertFalse(collector.getRibStats().isEmpty());
45 assertFalse(collector.getPeerStats().isEmpty());
47 collector.unbind(this.bgpribStateConsumer);
48 collector.unbind(this.bgpPeerStateConsumer);
49 assertTrue(collector.getRibStats().isEmpty());
50 assertTrue(collector.getPeerStats().isEmpty());
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();
59 collector.bind(this.bgpribStateConsumer);
60 collector.bind(this.bgpPeerStateConsumer);
61 assertFalse(collector.getRibStats().isEmpty());
62 assertTrue(collector.getPeerStats().isEmpty());
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());
73 collector.bind(this.bgpribStateConsumer);
74 collector.bind(this.bgpPeerStateConsumer);
75 assertTrue(collector.getRibStats().isEmpty());
76 assertTrue(collector.getPeerStats().isEmpty());