BUG-2109 : clear BGP session after it was already initialized
[bgpcep.git] / bgp / rib-mock / src / test / java / org / opendaylight / protocol / bgp / rib / mock / BGPListenerMock.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.mock;
9
10 import java.util.ArrayList;
11 import java.util.Collections;
12 import java.util.List;
13 import org.opendaylight.protocol.bgp.rib.spi.BGPSession;
14 import org.opendaylight.protocol.bgp.rib.spi.BGPSessionListener;
15 import org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason;
16 import org.opendaylight.yangtools.yang.binding.Notification;
17
18 /**
19  * Mock implementation of {@link BGPSessionListener} for testing purposes.
20  */
21 public final class BGPListenerMock implements BGPSessionListener {
22     private final List<Notification> buffer = Collections.synchronizedList(new ArrayList<Notification>());
23     private boolean connected = false;
24
25     protected List<Notification> getBuffer() {
26         return this.buffer;
27     }
28
29     protected boolean isConnected() {
30         return this.connected;
31     }
32
33     @Override
34     public void onMessage(final BGPSession session, final Notification message) {
35         this.buffer.add(message);
36     }
37
38     @Override
39     public void onSessionUp(final BGPSession session) {
40         this.connected = true;
41     }
42
43     @Override
44     public void onSessionDown(final BGPSession session, final Exception e) {
45         this.connected = false;
46
47     }
48
49     @Override
50     public void onSessionTerminated(final BGPSession session, final BGPTerminationReason reason) {
51         this.connected = false;
52     }
53
54     @Override
55     public boolean isSessionActive() {
56         return true;
57     }
58 }