2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.bgp.parser.mock;
10 import io.netty.buffer.ByteBuf;
14 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
15 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
16 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
17 import org.opendaylight.yangtools.yang.binding.Notification;
20 * Mock implementation of {@link BGPMessageParser}. It implements the required interface by having two internal maps,
21 * each used in one of the methods. It looks up the key provided to the method and returns whatever value is stored in
24 public class BGPMessageParserMock implements MessageRegistry {
25 private final Map<ByteBuf, Notification> messages;
28 * @param updateMessages Map<byte[], BGPUpdateEvent>
30 public BGPMessageParserMock(final Map<ByteBuf, Notification> messages) {
31 this.messages = messages;
35 public Notification parseMessage(final ByteBuf buffer) throws BGPParsingException, BGPDocumentedException {
36 final Notification ret = this.messages.get(buffer);
38 throw new IllegalArgumentException("Undefined message encountered");
44 public void serializeMessage(final Notification msg, final ByteBuf buffer) {
45 // no action needed, it's a mock for parsing, not serializing