Code clean up
[bgpcep.git] / bgp / extensions / evpn / src / test / java / org / opendaylight / protocol / bgp / evpn / impl / esi / types / LacpParserTest.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.MAC;
13 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.MAC_MODEL;
14 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.PORT;
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.LACP_MAC_NID;
19 import static org.opendaylight.protocol.bgp.evpn.impl.esi.types.EsiModelUtil.PK_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.rev180329.esi.Esi;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.esi.ArbitraryCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.esi.LacpAutoGeneratedCase;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.esi.LacpAutoGeneratedCaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.esi.lacp.auto.generated._case.LacpAutoGenerated;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev180329.esi.esi.lacp.auto.generated._case.LacpAutoGeneratedBuilder;
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 LacpParserTest {
36     private static final byte[] VALUE = {(byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f, (byte) 0xf7,
37         (byte) 0x02, (byte) 0x02, (byte) 0x00};
38     private static final byte[] RESULT = {(byte) 0x01, (byte) 0xf2, (byte) 0x0c, (byte) 0xdd, (byte) 0x80, (byte) 0x9f,
39         (byte) 0xf7, (byte) 0x02, (byte) 0x02, (byte) 0x00};
40     private LacpParser parser;
41
42     @Before
43     public void setUp() {
44         this.parser = new LacpParser();
45     }
46
47     @Test
48     public void parserTest() {
49         final ByteBuf buff = Unpooled.buffer(VALUE_SIZE);
50
51         final LacpAutoGeneratedCase lanAuto = new LacpAutoGeneratedCaseBuilder()
52                 .setLacpAutoGenerated(new LacpAutoGeneratedBuilder()
53                         .setCeLacpMacAddress(MAC).setCeLacpPortKey(PORT).build()).build();
54         this.parser.serializeEsi(lanAuto, buff);
55         assertArrayEquals(RESULT, ByteArray.getAllBytes(buff));
56
57         final Esi acResult = this.parser.parseEsi(Unpooled.wrappedBuffer(VALUE));
58         assertEquals(lanAuto, acResult);
59
60         final ContainerNode cont = createContBuilder(new NodeIdentifier(LacpAutoGenerated.QNAME))
61                 .addChild(createValueBuilder(MAC_MODEL, LACP_MAC_NID).build())
62                 .addChild(createValueBuilder(PORT, PK_NID).build())
63                 .build();
64         final Esi acmResult = this.parser.serializeEsi(cont);
65         assertEquals(lanAuto, acmResult);
66     }
67
68     @Test(expected = IllegalArgumentException.class)
69     public void wrongCaseTest() {
70         this.parser.serializeEsi(new ArbitraryCaseBuilder().build(), null);
71     }
72 }