Upgrade ietf-{inet,yang}-types to 2013-07-15
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / RouteRefreshCapabilityHandlerTest.java
1 /*
2  * Copyright (c) 2016 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.impl;
9
10 import static org.junit.Assert.assertEquals;
11
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.Unpooled;
14 import org.junit.Test;
15 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
16 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
17 import org.opendaylight.protocol.bgp.parser.impl.message.open.RouteRefreshCapabilityHandler;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.CParameters;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.message.bgp.parameters.optional.capabilities.CParametersBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.CParameters1;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.CParameters1Builder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.mp.capabilities.RouteRefreshCapabilityBuilder;
23
24 public class RouteRefreshCapabilityHandlerTest {
25
26     private static final RouteRefreshCapabilityHandler HANDLER = new RouteRefreshCapabilityHandler();
27
28     private static final byte[] WRONG_BYTES = new byte[] {1, 2};
29     private static final byte[] OK_BYTES = new byte[] {0};
30     private static final byte[] CAP_BYTES = new byte[] {2, 0};
31
32     @Test
33     public void testRRCapHandler() throws BGPDocumentedException, BGPParsingException {
34         final CParameters expectedParams = new CParametersBuilder().addAugmentation(CParameters1.class,new CParameters1Builder().setRouteRefreshCapability(
35             new RouteRefreshCapabilityBuilder().build()).build()).build();
36         assertEquals(expectedParams, HANDLER.parseCapability(Unpooled.copiedBuffer(OK_BYTES)));
37         assertEquals(expectedParams, HANDLER.parseCapability(Unpooled.copiedBuffer(WRONG_BYTES)));
38
39         final ByteBuf byteAggregator = Unpooled.buffer(2);
40         HANDLER.serializeCapability(expectedParams, byteAggregator);
41         assertEquals(Unpooled.copiedBuffer(CAP_BYTES), byteAggregator);
42
43         final CParameters missingCap = new CParametersBuilder().addAugmentation(CParameters1.class,new CParameters1Builder().setRouteRefreshCapability(
44             null).build()).build();
45         final ByteBuf byteAggregator2 = Unpooled.buffer(0);
46         HANDLER.serializeCapability(missingCap, byteAggregator2);
47         assertEquals(Unpooled.copiedBuffer(new byte[]{}), byteAggregator2);
48     }
49 }