YANG revision dates mass-update
[bgpcep.git] / bgp / extensions / evpn / src / test / java / org / opendaylight / protocol / bgp / evpn / impl / extended / communities / MACMobExtComTest.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.evpn.impl.extended.communities;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.COMMUNITY_VALUE_SIZE;
13 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.LD;
14
15 import io.netty.buffer.ByteBuf;
16 import io.netty.buffer.Unpooled;
17 import org.junit.Before;
18 import org.junit.Test;
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.evpn.rev200120.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.DefaultGatewayExtendedCommunityCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.MacMobilityExtendedCommunityCase;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.evpn.routes.evpn.routes.evpn.route.attributes.extended.communities.extended.community.MacMobilityExtendedCommunityCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.mac.mobility.extended.community.MacMobilityExtendedCommunityBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.ExtendedCommunity;
27
28 public class MACMobExtComTest {
29     private static final byte[] RESULT = {(byte) 0x01, (byte) 0x00, (byte) 0x02, (byte) 0x02, (byte) 0x02, (byte) 0x02};
30     private MACMobExtCom parser;
31
32     @Before
33     public void setUp() {
34         this.parser = new MACMobExtCom();
35     }
36
37     @Test
38     public void parserTest() throws BGPParsingException, BGPDocumentedException {
39         final ByteBuf buff = Unpooled.buffer(COMMUNITY_VALUE_SIZE);
40
41         final MacMobilityExtendedCommunityCase expected = new MacMobilityExtendedCommunityCaseBuilder()
42                 .setMacMobilityExtendedCommunity(new MacMobilityExtendedCommunityBuilder()
43                         .setStatic(true).setSeqNumber(LD).build()).build();
44         this.parser.serializeExtendedCommunity(expected, buff);
45         assertArrayEquals(RESULT, ByteArray.getAllBytes(buff));
46
47         final ExtendedCommunity result = this.parser.parseExtendedCommunity(Unpooled.wrappedBuffer(RESULT));
48         assertEquals(expected, result);
49     }
50
51     @Test(expected = IllegalArgumentException.class)
52     public void wrongCaseTest() {
53         this.parser.serializeExtendedCommunity(new DefaultGatewayExtendedCommunityCaseBuilder().build(), null);
54     }
55
56     @Test
57     public void testSubtype() {
58         assertEquals(0, this.parser.getSubType());
59     }
60 }