Cleanup deprecation warnings in bgp/extensions/evpn
[bgpcep.git] / bgp / extensions / evpn / src / test / java / org / opendaylight / protocol / bgp / evpn / impl / nlri / EvpnNlriAttributesParserTest.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.nlri;
9
10 import static java.util.Collections.singletonList;
11 import static org.opendaylight.protocol.bgp.evpn.impl.EvpnTestUtil.RD;
12
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import java.util.ArrayList;
16 import org.junit.Assert;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.protocol.bgp.evpn.impl.esi.types.ESIActivator;
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.destination.EvpnDestinationBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type.DestinationEvpnCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.update.attributes.mp.reach.nlri.advertized.routes.destination.type.destination.evpn._case.DestinationEvpnBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.Attributes;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes1Builder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.Attributes2Builder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlri;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpReachNlriBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlri;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.MpUnreachNlriBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutes;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.reach.nlri.AdvertizedRoutesBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutes;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.update.attributes.mp.unreach.nlri.WithdrawnRoutesBuilder;
37
38 public class EvpnNlriAttributesParserTest {
39     private EvpnNlriParser parser;
40
41     @Before
42     public void setUp() {
43         ESIActivator.registerEsiTypeParsers(new ArrayList<>());
44         NlriActivator.registerNlriParsers(new ArrayList<>());
45         this.parser = new EvpnNlriParser();
46     }
47
48     @Test
49     public void testAttributes1() throws BGPParsingException {
50         final ByteBuf buffer = Unpooled.buffer();
51         final Attributes att = new AttributesBuilder()
52                 .addAugmentation(new Attributes1Builder().setMpReachNlri(createReach()).build())
53                 .build();
54         this.parser.serializeAttribute(att, buffer);
55         Assert.assertArrayEquals(IncMultEthTagRParserTest.RESULT, ByteArray.getAllBytes(buffer));
56     }
57
58     private static MpReachNlri createReach() {
59         final MpReachNlriBuilder mpReachExpected = new MpReachNlriBuilder();
60         final AdvertizedRoutes wd = new AdvertizedRoutesBuilder().setDestinationType(new DestinationEvpnCaseBuilder()
61             .setDestinationEvpn(new DestinationEvpnBuilder().setEvpnDestination(
62                     singletonList(new EvpnDestinationBuilder()
63                             .setRouteDistinguisher(RD)
64                             .setEvpnChoice(IncMultEthTagRParserTest.createIncMultiCase())
65                             .build())).build()).build()).build();
66         return mpReachExpected.setAdvertizedRoutes(wd).build();
67     }
68
69     @Test
70     public void testAttributes2() throws BGPParsingException {
71         final ByteBuf buffer = Unpooled.buffer();
72         final Attributes att = new AttributesBuilder()
73                 .addAugmentation(new Attributes2Builder().setMpUnreachNlri(createUnreach()).build())
74                 .build();
75         this.parser.serializeAttribute(att, buffer);
76         Assert.assertArrayEquals(IncMultEthTagRParserTest.RESULT, ByteArray.getAllBytes(buffer));
77     }
78
79     private static MpUnreachNlri createUnreach() {
80         final MpUnreachNlriBuilder mpReachExpected = new MpUnreachNlriBuilder();
81         final WithdrawnRoutes wd = new WithdrawnRoutesBuilder()
82             .setDestinationType(new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang
83                 .bgp.evpn.rev200120.update.attributes.mp.unreach.nlri.withdrawn.routes.destination.type
84                     .DestinationEvpnCaseBuilder().setDestinationEvpn(new org.opendaylight.yang.gen.v1.urn
85                         .opendaylight.params.xml.ns.yang.bgp.evpn.rev200120.update.attributes.mp.unreach.nlri.withdrawn
86                      .routes.destination.type.destination.evpn._case.DestinationEvpnBuilder()
87                         .setEvpnDestination(singletonList(new EvpnDestinationBuilder()
88                             .setRouteDistinguisher(RD).setEvpnChoice(IncMultEthTagRParserTest.createIncMultiCase())
89                             .build()))
90                         .build())
91                 .build())
92             .build();
93         return mpReachExpected.setWithdrawnRoutes(wd).build();
94     }
95
96 }