Do not rely on deprecated classes directly
[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.Map;
11
12 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
13 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
14 import org.opendaylight.protocol.framework.ProtocolMessageFactory;
15 import org.opendaylight.yangtools.yang.binding.Notification;
16
17 /**
18  * Mock implementation of {@link BGPMessageParser}. It implements the required interface by having two internal maps,
19  * each used in one of the methods. It looks up the key provided to the method and returns whatever value is stored in
20  * the map.
21  */
22 public class BGPMessageParserMock implements ProtocolMessageFactory<Notification> {
23         private final Map<byte[], Notification> messages;
24
25         /**
26          * @param updateMessages Map<byte[], BGPUpdateEvent>
27          */
28         public BGPMessageParserMock(final Map<byte[], Notification> messages) {
29                 this.messages = messages;
30         }
31
32         @Override
33         public Notification parse(final byte[] bytes) throws BGPParsingException, BGPDocumentedException {
34                 final Notification ret = this.messages.get(bytes);
35                 if (ret == null) {
36                         throw new IllegalArgumentException("Undefined message encountered");
37                 }
38                 return ret;
39         }
40
41         @Override
42         public byte[] put(final Notification msg) {
43                 // nothing
44                 return null;
45         }
46 }