BGPCEP-706: Fix BGP Flowspec NumbericOphrand
[bgpcep.git] / bgp / bmp-parser-impl / src / test / java / org / opendaylight / protocol / bmp / parser / message / TerminationHandlerTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bmp.parser.message;
9
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;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import org.junit.Test;
16 import org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException;
17 import org.opendaylight.protocol.util.ByteArray;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev150512.TerminationMessage;
19
20 public class TerminationHandlerTest extends AbstractBmpMessageTest {
21
22     private static final byte[] TERMINATION_MESSAGE = {
23         /*
24          * 03 <- bmp version
25          * 00 00 00 20 <- total length of termination message + common header lenght
26          * 05 <- bmp message type - termination
27          * 00 01 <- type REASON
28          * 00 02 <- length
29          * 00 00 <- reason = 0 (Session administratively closed)
30          * 00 00 <- type STRING
31          * 00 06 <- length
32          * 65 72 72 6F 72 31 <- value error1
33          * 00 00 <- type STRING
34          * 00 06 <- length
35          * 65 72 72 6F 72 31 <- value error1
36          */
37         (byte) 0x03,
38         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x20,
39         (byte) 0x05,
40         (byte) 0x00, (byte) 0x01,
41         (byte) 0x00, (byte) 0x02,
42         (byte) 0x00, (byte) 0x00,
43         (byte) 0x00, (byte) 0x00,
44         (byte) 0x00, (byte) 0x06,
45         (byte) 0x65, (byte) 0x72, (byte) 0x72, (byte) 0x6F, (byte) 0x72, (byte) 0x31,
46         (byte) 0x00, (byte) 0x00,
47         (byte) 0x00, (byte) 0x06,
48         (byte) 0x65, (byte) 0x72, (byte) 0x72, (byte) 0x6F, (byte) 0x72, (byte) 0x31
49     };
50
51     @Test
52     public void testSerializeTerminationMessage() throws BmpDeserializationException {
53         final ByteBuf buffer = Unpooled.buffer();
54         getBmpMessageRegistry().serializeMessage(createTerminationMsg(), buffer);
55         assertArrayEquals(TERMINATION_MESSAGE, ByteArray.readAllBytes(buffer));
56     }
57
58
59     @Test
60     public void testParseTerminationMessage() throws BmpDeserializationException {
61         final TerminationMessage parsedInitMsg = (TerminationMessage) getBmpMessageRegistry().parseMessage(Unpooled.copiedBuffer(TERMINATION_MESSAGE));
62         assertEquals(createTerminationMsg(), parsedInitMsg);
63     }
64 }