Bump upstreams to 2022.09
[bgpcep.git] / bgp / parser-mock / src / main / java / org / opendaylight / protocol / bgp / parser / mock / BGPMessageParserMock.java
index 75e4f8816f3c6397cb095d1af98afbb2508648d1..c48e3bd3e09ee61b5e2013d743006c69f82074f1 100644 (file)
@@ -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<Notification> {
-       private final Map<byte[], Notification> messages;
+public class BGPMessageParserMock implements MessageRegistry {
+    private final Map<ByteBuf, Notification<?>> messages;
 
-       /**
-        * @param updateMessages Map<byte[], BGPUpdateEvent>
-        */
-       public BGPMessageParserMock(final Map<byte[], Notification> 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<ByteBuf, Notification<?>> 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;
+    }
 }