YANG revision dates mass-update
[bgpcep.git] / bgp / extensions / evpn / src / test / java / org / opendaylight / protocol / bgp / evpn / impl / esi / types / ASGenParserTest.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.esi.types;
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.AS_MODEL;
13 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.AS_NUMBER;
14 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.LD;
15 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.VALUE_SIZE;
16 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.createContBuilder;
17 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.createValueBuilder;
18 import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.AS_NID;
19 import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.LD_NID;
20
21 import io.netty.buffer.ByteBuf;
22 import io.netty.buffer.Unpooled;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.opendaylight.protocol.util.ByteArray;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.Esi;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.ArbitraryCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.AsGeneratedCase;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.AsGeneratedCaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.as.generated._case.AsGenerated;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.esi.esi.as.generated._case.AsGeneratedBuilder;
32 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
33 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
34
35 public final class ASGenParserTest {
36     private static final byte[] VALUE = {(byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x02,
37         (byte) 0x02, (byte) 0x02, (byte) 0x00};
38     private static final byte[] RESULT = {(byte) 0x05, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x02,
39         (byte) 0x02, (byte) 0x02, (byte) 0x02, (byte) 0x00};
40     private ASGenParser parser;
41
42     @Before
43     public void setUp() {
44         this.parser = new ASGenParser();
45     }
46
47     @Test
48     public void parserTest() {
49         final ByteBuf buff = Unpooled.buffer(VALUE_SIZE);
50
51         final AsGeneratedCase asGen = new AsGeneratedCaseBuilder().setAsGenerated(new AsGeneratedBuilder()
52                 .setAs(AS_NUMBER).setLocalDiscriminator(LD).build()).build();
53         this.parser.serializeEsi(asGen, buff);
54         assertArrayEquals(RESULT, ByteArray.getAllBytes(buff));
55
56         final Esi acResult = this.parser.parseEsi(Unpooled.wrappedBuffer(VALUE));
57         assertEquals(asGen, acResult);
58
59         final ContainerNode cont = createContBuilder(new NodeIdentifier(AsGenerated.QNAME))
60                 .addChild(createValueBuilder(AS_MODEL, AS_NID).build())
61             .addChild(createValueBuilder(LD, LD_NID).build()).build();
62         final Esi acmResult = this.parser.serializeEsi(cont);
63         assertEquals(asGen, acmResult);
64     }
65
66     @Test(expected = IllegalArgumentException.class)
67     public void wrongCaseTest() {
68         this.parser.serializeEsi(new ArbitraryCaseBuilder().build(), null);
69     }
70 }