BUG-58: refactor to take advantage of netty
[bgpcep.git] / bgp / parser-mock / src / main / java / org / opendaylight / protocol / bgp / parser / mock / BGPMessageParserMock.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.parser.mock;
9
10 import java.util.List;
11 import java.util.Map;
12
13 import org.opendaylight.protocol.bgp.parser.BGPMessage;
14 import org.opendaylight.protocol.framework.DeserializerException;
15 import org.opendaylight.protocol.framework.DocumentedException;
16 import org.opendaylight.protocol.framework.ProtocolMessageFactory;
17
18 /**
19  * Mock implementation of {@link BGPMessageParser}. It implements the required interface by having two internal maps,
20  * each used in one of the methods. It looks up the key provided to the method and returns whatever value is stored in
21  * the map.
22  */
23 public class BGPMessageParserMock implements ProtocolMessageFactory<BGPMessage> {
24         private final Map<byte[], List<BGPMessage>> messages;
25
26         /**
27          * @param updateMessages Map<byte[], BGPUpdateEvent>
28          */
29         public BGPMessageParserMock(final Map<byte[], List<BGPMessage>> messages) {
30                 this.messages = messages;
31         }
32
33         @Override
34         public List<BGPMessage> parse(final byte[] bytes) throws DeserializerException, DocumentedException {
35                 final List<BGPMessage> ret = this.messages.get(bytes);
36                 if (ret == null) {
37                         throw new IllegalArgumentException("Undefined message encountered");
38                 }
39                 return ret;
40         }
41
42         @Override
43         public byte[] put(final BGPMessage msg) {
44                 // nothing
45                 return null;
46         }
47 }