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 com.google.common.base.Preconditions;
11 import io.netty.buffer.ByteBuf;
13 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
14 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
15 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
16 import org.opendaylight.yangtools.yang.binding.Notification;
19 * Mock implementation of {@link MessageRegistry}. 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
23 public class BGPMessageParserMock implements MessageRegistry {
24 private final Map<ByteBuf, Notification> messages;
27 * Creates a new BGPMessageParserMock with given messages.
29 * @param messages represents a new map of ByteBuf and Notification
31 public BGPMessageParserMock(final Map<ByteBuf, Notification> messages) {
32 this.messages = messages;
36 public Notification parseMessage(final ByteBuf buffer) throws BGPParsingException, BGPDocumentedException {
37 final Notification ret = this.messages.get(buffer);
38 Preconditions.checkArgument(ret != null, "Undefined message encountered");
43 public void serializeMessage(final Notification msg, final ByteBuf buffer) {
44 // no action needed, it's a mock for parsing, not serializing