86331cf1245090817bdff10e17e7d0aa652ea476
[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 java.util.Set;
14
15 import org.opendaylight.protocol.bgp.concepts.BGPTableType;
16 import org.opendaylight.protocol.bgp.parser.BGPError;
17 import org.opendaylight.protocol.bgp.parser.BGPMessage;
18 import org.opendaylight.protocol.bgp.parser.BGPSession;
19 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
20
21
22 /**
23  * Mock implementation of {@link BGPListener} for testing purposes.
24  */
25 final class BGPListenerMock extends BGPSessionListener {
26         private final List<BGPMessage> buffer = Collections.synchronizedList(new ArrayList<BGPMessage>());
27         private boolean connected = false;
28
29         protected List<BGPMessage> getBuffer() {
30                 return this.buffer;
31         }
32
33         protected boolean isConnected() {
34                 return this.connected;
35         }
36
37         @Override
38         public void onMessage(final BGPMessage message) {
39                 this.buffer.add(message);
40         }
41
42         @Override
43         public void onSessionUp(final Set<BGPTableType> remoteParams) {
44                 this.connected = true;
45         }
46
47         @Override
48         public void onSessionDown(final BGPSession session, final Exception e) {
49                 this.connected = false;
50         }
51
52         @Override
53         public void onSessionTerminated(final BGPError cause) {
54                 this.connected = false;
55         }
56 }