Fix most bgp-parser-spi checkstyle violations
[bgpcep.git] / bgp / parser-spi / src / test / java / org / opendaylight / protocol / bgp / parser / spi / pojo / UnrecognizedAttributesTest.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.bgp.parser.spi.pojo;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13
14 import io.netty.buffer.Unpooled;
15 import java.util.List;
16 import org.junit.Rule;
17 import org.junit.Test;
18 import org.junit.rules.ExpectedException;
19 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
20 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
21 import org.opendaylight.protocol.util.ByteArray;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.UnrecognizedAttributes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.UnrecognizedAttributesKey;
24
25 public class UnrecognizedAttributesTest {
26
27     private static final int UNRECOGNIZED_ATTRIBUTE_COUNT = 1;
28     private static final int FIRST_ATTRIBUTE = 0;
29     private static final short NON_EXISTENT_TYPE = 0;
30     private static final int NON_VALUE_BYTES = 3;
31
32     private static final SimpleAttributeRegistry SIMPLE_ATTR_REG = new SimpleAttributeRegistry();
33
34     @Rule
35     public ExpectedException expException = ExpectedException.none();
36
37     @Test
38     public void testUnrecognizedAttributesWithoutOptionalFlag() throws BGPDocumentedException, BGPParsingException {
39         this.expException.expect(BGPDocumentedException.class);
40         this.expException.expectMessage("Well known attribute not recognized.");
41         SIMPLE_ATTR_REG.parseAttributes(
42             Unpooled.wrappedBuffer(new byte[] { 0x03, 0x00, 0x05, 0x01, 0x02, 0x03, 0x04, 0x05 }), null);
43     }
44
45     @Test
46     public void testUnrecognizedAttributes() throws BGPDocumentedException, BGPParsingException {
47         final byte[] attributeBytes = { (byte)0xe0, 0x00, 0x05, 0x01, 0x02, 0x03, 0x04, 0x05 };
48         final List<UnrecognizedAttributes> unrecogAttribs = SIMPLE_ATTR_REG.parseAttributes(
49             Unpooled.wrappedBuffer(attributeBytes), null).getAttributes().getUnrecognizedAttributes();
50         assertEquals(UNRECOGNIZED_ATTRIBUTE_COUNT, unrecogAttribs.size());
51         final UnrecognizedAttributes unrecogAttrib = unrecogAttribs.get(FIRST_ATTRIBUTE);
52         final UnrecognizedAttributesKey expectedAttribKey =
53             new UnrecognizedAttributesKey(unrecogAttrib.getType());
54
55         assertTrue(unrecogAttrib.isPartial());
56         assertTrue(unrecogAttrib.isTransitive());
57         assertArrayEquals(ByteArray.cutBytes(attributeBytes, NON_VALUE_BYTES), unrecogAttrib.getValue());
58         assertEquals(NON_EXISTENT_TYPE, unrecogAttrib.getType().shortValue());
59         assertEquals(expectedAttribKey, unrecogAttrib.key());
60     }
61 }