2 * Copyright (c) 2015 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.bmp.parser.message;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.opendaylight.protocol.bmp.parser.message.TestUtil.createTerminationMsg;
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import org.junit.Test;
17 import org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException;
18 import org.opendaylight.protocol.util.ByteArray;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.TerminationMessage;
21 public class TerminationHandlerTest extends AbstractBmpMessageTest {
23 private static final byte[] TERMINATION_MESSAGE = {
26 * 00 00 00 20 <- total length of termination message + common header lenght
27 * 05 <- bmp message type - termination
28 * 00 01 <- type REASON
30 * 00 00 <- reason = 0 (Session administratively closed)
31 * 00 00 <- type STRING
33 * 65 72 72 6F 72 31 <- value error1
34 * 00 00 <- type STRING
36 * 65 72 72 6F 72 31 <- value error1
39 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x20,
41 (byte) 0x00, (byte) 0x01,
42 (byte) 0x00, (byte) 0x02,
43 (byte) 0x00, (byte) 0x00,
44 (byte) 0x00, (byte) 0x00,
45 (byte) 0x00, (byte) 0x06,
46 (byte) 0x65, (byte) 0x72, (byte) 0x72, (byte) 0x6F, (byte) 0x72, (byte) 0x31,
47 (byte) 0x00, (byte) 0x00,
48 (byte) 0x00, (byte) 0x06,
49 (byte) 0x65, (byte) 0x72, (byte) 0x72, (byte) 0x6F, (byte) 0x72, (byte) 0x31
53 public void testSerializeTerminationMessage() throws BmpDeserializationException {
54 final ByteBuf buffer = Unpooled.buffer();
55 getBmpMessageRegistry().serializeMessage(createTerminationMsg(), buffer);
56 assertArrayEquals(TERMINATION_MESSAGE, ByteArray.readAllBytes(buffer));
61 public void testParseTerminationMessage() throws BmpDeserializationException {
62 final TerminationMessage parsedInitMsg = (TerminationMessage) getBmpMessageRegistry()
63 .parseMessage(Unpooled.copiedBuffer(TERMINATION_MESSAGE));
64 assertEquals(createTerminationMsg(), parsedInitMsg);