X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=bgp%2Fparser-mock%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fbgp%2Fparser%2Fmock%2FBGPMessageParserMock.java;h=c48e3bd3e09ee61b5e2013d743006c69f82074f1;hb=8896ea0a68188dba41c89d23be96ccc15e60c546;hp=75e4f8816f3c6397cb095d1af98afbb2508648d1;hpb=6b9fe165ff3b6e4848b1fc76ff2d6b98ad3b108f;p=bgpcep.git diff --git a/bgp/parser-mock/src/main/java/org/opendaylight/protocol/bgp/parser/mock/BGPMessageParserMock.java b/bgp/parser-mock/src/main/java/org/opendaylight/protocol/bgp/parser/mock/BGPMessageParserMock.java index 75e4f8816f..c48e3bd3e0 100644 --- a/bgp/parser-mock/src/main/java/org/opendaylight/protocol/bgp/parser/mock/BGPMessageParserMock.java +++ b/bgp/parser-mock/src/main/java/org/opendaylight/protocol/bgp/parser/mock/BGPMessageParserMock.java @@ -7,40 +7,42 @@ */ package org.opendaylight.protocol.bgp.parser.mock; +import com.google.common.base.Preconditions; +import io.netty.buffer.ByteBuf; import java.util.Map; - -import org.opendaylight.protocol.framework.DeserializerException; -import org.opendaylight.protocol.framework.DocumentedException; -import org.opendaylight.protocol.framework.ProtocolMessageFactory; +import org.opendaylight.protocol.bgp.parser.BGPDocumentedException; +import org.opendaylight.protocol.bgp.parser.BGPParsingException; +import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry; +import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint; import org.opendaylight.yangtools.yang.binding.Notification; /** - * Mock implementation of {@link BGPMessageParser}. It implements the required interface by having two internal maps, + * Mock implementation of {@link MessageRegistry}. It implements the required interface by having two internal maps, * each used in one of the methods. It looks up the key provided to the method and returns whatever value is stored in * the map. */ -public class BGPMessageParserMock implements ProtocolMessageFactory { - private final Map messages; +public class BGPMessageParserMock implements MessageRegistry { + private final Map> messages; - /** - * @param updateMessages Map - */ - public BGPMessageParserMock(final Map messages) { - this.messages = messages; - } + /** + * Creates a new BGPMessageParserMock with given messages. + * + * @param messages represents a new map of ByteBuf and Notification + */ + public BGPMessageParserMock(final Map> messages) { + this.messages = messages; + } - @Override - public Notification parse(final byte[] bytes) throws DeserializerException, DocumentedException { - final Notification ret = this.messages.get(bytes); - if (ret == null) { - throw new IllegalArgumentException("Undefined message encountered"); - } - return ret; - } + @Override + public void serializeMessage(final Notification msg, final ByteBuf buffer) { + // no action needed, it's a mock for parsing, not serializing + } - @Override - public byte[] put(final Notification msg) { - // nothing - return null; - } + @Override + public Notification parseMessage(final ByteBuf buffer, final PeerSpecificParserConstraint constraint) + throws BGPDocumentedException, BGPParsingException { + final Notification ret = messages.get(buffer); + Preconditions.checkArgument(ret != null, "Undefined message encountered"); + return ret; + } }