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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Keepalive;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.KeepaliveBuilder;
20 import org.opendaylight.yangtools.yang.binding.Notification;
22 public class AbstractMessageRegistryTest {
24 public static final byte[] keepAliveBMsg = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
25 (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
26 (byte) 0x00, (byte) 0x13, (byte) 0x04 };
28 private final AbstractMessageRegistry registry = new AbstractMessageRegistry() {
31 protected byte[] serializeMessageImpl(Notification message) {
36 protected Notification parseBody(int type, ByteBuf body, int messageLength) throws BGPDocumentedException {
37 return new KeepaliveBuilder().build();
42 public void testRegistry() throws BGPDocumentedException, BGPParsingException {
43 final Notification keepAlive = new KeepaliveBuilder().build();
44 final byte[] serialized = this.registry.serializeMessage(keepAlive);
45 assertArrayEquals(keepAliveBMsg, serialized);
47 final Notification not = this.registry.parseMessage(Unpooled.copiedBuffer(keepAliveBMsg));
48 assertTrue(not instanceof Keepalive);