2 * Copyright (c) 2014 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.spi;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertTrue;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
15 import org.junit.Test;
16 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
17 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
18 import org.opendaylight.protocol.util.ByteArray;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Keepalive;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.KeepaliveBuilder;
21 import org.opendaylight.yangtools.yang.binding.Notification;
23 public class AbstractMessageRegistryTest {
25 public static final byte[] keepAliveBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
26 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
27 (byte) 0xff, (byte) 0x00, (byte) 0x13, (byte) 0x04 };
29 private final AbstractMessageRegistry registry = new AbstractMessageRegistry() {
32 protected void serializeMessageImpl(final Notification message, final ByteBuf buffer) {
33 buffer.writeBytes(keepAliveBMsg);
37 protected Notification parseBody(int type, ByteBuf body, int messageLength) throws BGPDocumentedException {
38 return new KeepaliveBuilder().build();
43 public void testRegistry() throws BGPDocumentedException, BGPParsingException {
44 final Notification keepAlive = new KeepaliveBuilder().build();
45 final ByteBuf buffer = Unpooled.buffer();
46 this.registry.serializeMessage(keepAlive, buffer);
47 assertArrayEquals(keepAliveBMsg, ByteArray.getAllBytes(buffer));
49 final Notification not = this.registry.parseMessage(Unpooled.copiedBuffer(keepAliveBMsg));
50 assertTrue(not instanceof Keepalive);