Refactor LinkstateNlriParser
[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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
17 import org.opendaylight.yangtools.yang.binding.Notification;
18
19 /**
20  * Mock implementation of {@link BGPSessionListener} for testing purposes.
21  */
22 public final class BGPListenerMock implements BGPSessionListener {
23     private final List<Notification> buffer = Collections.synchronizedList(new ArrayList<Notification>());
24     private boolean connected = false;
25
26     protected List<Notification> getBuffer() {
27         return this.buffer;
28     }
29
30     protected boolean isConnected() {
31         return this.connected;
32     }
33
34     @Override
35     public void onMessage(final BGPSession session, final Notification message) {
36         this.buffer.add(message);
37     }
38
39     @Override
40     public void onSessionUp(final BGPSession session) {
41         this.connected = true;
42     }
43
44     @Override
45     public void onSessionDown(final BGPSession session, final Exception e) {
46         this.connected = false;
47
48     }
49
50     @Override
51     public void onSessionTerminated(final BGPSession session, final BGPTerminationReason reason) {
52         this.connected = false;
53     }
54
55     @Override
56     public boolean isSessionActive() {
57         return true;
58     }
59
60     @Override
61     public void markUptodate(final TablesKey tablesKey) {
62     }
63 }