2 * Copyright (c) 2016 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.impl;
10 import static org.junit.Assert.assertEquals;
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.rev171207.open.message.bgp.parameters.optional.capabilities.CParameters;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.open.message.bgp.parameters.optional.capabilities.CParametersBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.CParameters1Builder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev171207.mp.capabilities.RouteRefreshCapabilityBuilder;
24 public class RouteRefreshCapabilityHandlerTest {
26 private static final RouteRefreshCapabilityHandler HANDLER = new RouteRefreshCapabilityHandler();
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};
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)));
39 final ByteBuf byteAggregator = Unpooled.buffer(2);
40 HANDLER.serializeCapability(expectedParams, byteAggregator);
41 assertEquals(Unpooled.copiedBuffer(CAP_BYTES), byteAggregator);
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);