Create common parent for extensions families
[bgpcep.git] / bgp / extensions / evpn / src / test / java / org / opendaylight / protocol / bgp / evpn / impl / esi / types / ArbitraryParserTest.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.VALUE_SIZE;
13 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.createContBuilder;
14 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.createValueBuilder;
15 import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.ARB_NID;
16
17 import io.netty.buffer.ByteBuf;
18 import io.netty.buffer.Unpooled;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.opendaylight.protocol.util.ByteArray;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.Esi;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.esi.ArbitraryCase;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.esi.ArbitraryCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.esi.AsGeneratedCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.esi.arbitrary._case.Arbitrary;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.esi.arbitrary._case.ArbitraryBuilder;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
29 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
30
31 public final class ArbitraryParserTest {
32     private static final byte[] ARB_VALUE = {(byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05,
33         (byte) 0x06, (byte) 0x07, (byte) 0x08, (byte) 0x09};
34     private static final byte[] ARB_RESULT = {(byte) 0x00, (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04,
35         (byte) 0x05, (byte) 0x06, (byte) 0x07, (byte) 0x08, (byte) 0x09};
36     private ArbitraryParser parser;
37
38     @Before
39     public void setUp() {
40         this.parser = new ArbitraryParser();
41     }
42
43     @Test
44     public void parserTest() {
45         final ByteBuf buff = Unpooled.buffer(VALUE_SIZE);
46
47         final ArbitraryCase arbitrary = new ArbitraryCaseBuilder().setArbitrary(new ArbitraryBuilder()
48                 .setArbitrary(ARB_VALUE).build()).build();
49         this.parser.serializeEsi(arbitrary, buff);
50         assertArrayEquals(ARB_RESULT, ByteArray.getAllBytes(buff));
51
52         final Esi acResult = this.parser.parseEsi(Unpooled.wrappedBuffer(ARB_VALUE));
53         assertEquals(arbitrary, acResult);
54
55         final ContainerNode cont = createContBuilder(new NodeIdentifier(Arbitrary.QNAME))
56                 .addChild(createValueBuilder(ARB_VALUE, ARB_NID).build()).build();
57         final Esi acmResult = this.parser.serializeEsi(cont);
58         assertEquals(arbitrary, acmResult);
59     }
60
61     @Test(expected = IllegalArgumentException.class)
62     public void wrongCaseTest() {
63         this.parser.serializeEsi(new AsGeneratedCaseBuilder().build(), null);
64     }
65 }