Mass-convert all compontents to use -no-zone addresses
[bgpcep.git] / bgp / topology-provider / src / test / java / org / opendaylight / bgpcep / bgp / topology / provider / LinkstateTopologyBuilderTest.java
index e11e46112f9ebdd2dc3e2358e0de6b9a78a86c4b..ca484e624f751fe82db7b590a9e1c92dda011964 100755 (executable)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.bgpcep.bgp.topology.provider;
 
 import static org.junit.Assert.assertEquals;
@@ -14,7 +13,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.RETURNS_SMART_NULLS;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
@@ -28,22 +27,21 @@ import static org.opendaylight.protocol.util.CheckUtil.readDataOperational;
 
 import com.google.common.collect.Lists;
 import io.netty.buffer.Unpooled;
-import java.math.BigInteger;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.binding.api.WriteTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.AdministrativeGroup;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.Identifier;
@@ -53,6 +51,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.link
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.LinkstateSubsequentAddressFamily;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.ProtocolId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.TopologyIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.bgp.rib.rib.loc.rib.tables.routes.LinkstateRoutesCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.attribute.UnreservedBandwidthBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.attribute.UnreservedBandwidthKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev180329.linkstate.object.type.link._case.LinkDescriptorsBuilder;
@@ -97,6 +96,10 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.IgpNodeAttributes;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.nt.l3.unicast.igp.topology.rev131021.igp.node.attributes.igp.node.attributes.Prefix;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
 public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
 
@@ -105,13 +108,13 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
     private static final String ROUTER_1_ID = "127.0.0.1";
     private static final String ROUTER_2_ID = "127.0.0.2";
     private static final String NODE_1_PREFIX = "127.0.1.1/32";
-    private static final AsNumber NODE_1_AS = new AsNumber(1L);
-    private static final AsNumber NODE_2_AS = new AsNumber(2L);
+    private static final AsNumber NODE_1_AS = new AsNumber(Uint32.ONE);
+    private static final AsNumber NODE_2_AS = new AsNumber(Uint32.TWO);
     private static final String NODE_1_ISIS_ID = "bgpls://IsisLevel2:1/type=node&as=1&router=0000.0102.0304";
     private static final String NODE_2_ISIS_ID = "bgpls://IsisLevel2:1/type=node&as=2";
     private static final String NODE_1_OSPF_ID = "bgpls://Ospf:1/type=node&as=1&router=0000.0102.0304";
     private static final String NODE_2_OSPF_ID = "bgpls://Ospf:1/type=node&as=2";
-    private static final Identifier IDENTIFIER = new Identifier(new BigInteger("1"));
+    private static final Identifier IDENTIFIER = new Identifier(Uint64.ONE);
     private static final long LISTENER_RESTART_TIME = 20000;
     private static final int LISTENER_ENFORCE_COUNTER = 2;
 
@@ -128,8 +131,8 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
         final InstanceIdentifier<Tables> path = LOC_RIB_REF.getInstanceIdentifier().builder().child(LocRib.class)
             .child(Tables.class, new TablesKey(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class))
             .build();
-        this.linkstateRouteIID = path.builder().child((Class) LinkstateRoutes.class)
-            .child(LinkstateRoute.class, new LinkstateRouteKey(new PathId(0L), LINKSTATE_ROUTE_KEY))
+        this.linkstateRouteIID = path.builder().child(LinkstateRoutesCase.class, LinkstateRoutes.class)
+            .child(LinkstateRoute.class, new LinkstateRouteKey(new PathId(Uint32.ZERO), LINKSTATE_ROUTE_KEY))
                 .build();
 
     }
@@ -141,11 +144,11 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
     }
 
     @Test
-    public void testLinkstateTopologyBuilderTopologyTypes() throws ReadFailedException {
+    public void testLinkstateTopologyBuilderTopologyTypes() throws InterruptedException, ExecutionException {
         readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
-            assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight
+            assertNotNull(topology.getTopologyTypes().augmentation(org.opendaylight.yang.gen.v1.urn.opendaylight
                     .params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class));
-            assertNotNull(topology.getTopologyTypes().getAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight
+            assertNotNull(topology.getTopologyTypes().augmentation(org.opendaylight.yang.gen.v1.urn.opendaylight
                     .params.xml.ns.yang.odl.bgp.topology.types.rev160524.TopologyTypes1.class)
                     .getBgpLinkstateTopology());
             return topology;
@@ -153,24 +156,24 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
     }
 
     @Test
-    public void testIsisLinkstateTopologyBuilder() throws ReadFailedException {
+    public void testIsisLinkstateTopologyBuilder() throws InterruptedException, ExecutionException {
         // create node
         updateLinkstateRoute(createLinkstateNodeRoute(ProtocolId.IsisLevel2, "node1", NODE_1_AS, ROUTER_1_ID));
         readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
             assertEquals(1, topology.getNode().size());
             final Node node1 = topology.getNode().get(0);
             assertEquals(NODE_1_ISIS_ID, node1.getNodeId().getValue());
-            final IgpNodeAttributes igpNode1 = node1.getAugmentation(Node1.class).getIgpNodeAttributes();
+            final IgpNodeAttributes igpNode1 = node1.augmentation(Node1.class).getIgpNodeAttributes();
             assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
             assertEquals("node1", igpNode1.getName().getValue());
-            final IgpNodeAttributes1 igpNodeAttributes1 = igpNode1.getAugmentation(IgpNodeAttributes1.class);
+            final IgpNodeAttributes1 igpNodeAttributes1 = igpNode1.augmentation(IgpNodeAttributes1.class);
             assertEquals("0000.0102.0304", igpNodeAttributes1.getIsisNodeAttributes().getIso().getIsoSystemId()
                     .getValue());
             assertEquals(ROUTER_1_ID, igpNodeAttributes1.getIsisNodeAttributes().getTed().getTeRouterIdIpv4()
                     .getValue());
             assertEquals("47.0000.0000.0000.0000.0102.0304", igpNodeAttributes1.getIsisNodeAttributes()
                     .getNet().get(0).getValue());
-            assertNull(igpNode1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf
+            assertNull(igpNode1.augmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf
                     .topology.rev131021.IgpNodeAttributes1.class));
             return topology;
         });
@@ -188,11 +191,11 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
                     + "=2&mt=1", link1.getLinkId().getValue());
             assertEquals(NODE_1_ISIS_ID, link1.getSource().getSourceNode().getValue());
             assertEquals(NODE_2_ISIS_ID, link1.getDestination().getDestNode().getValue());
-            final IgpLinkAttributes igpLink1 = link1.getAugmentation(Link1.class).getIgpLinkAttributes();
+            final IgpLinkAttributes igpLink1 = link1.augmentation(Link1.class).getIgpLinkAttributes();
             assertEquals("link1", igpLink1.getName());
-            assertEquals((short) 1, igpLink1.getAugmentation(IgpLinkAttributes1.class).getIsisLinkAttributes()
+            assertEquals((short) 1, igpLink1.augmentation(IgpLinkAttributes1.class).getIsisLinkAttributes()
                     .getMultiTopologyId().shortValue());
-            assertNull(igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf
+            assertNull(igpLink1.augmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.ospf
                     .topology.rev131021.IgpLinkAttributes1.class));
             return topology;
         });
@@ -203,7 +206,7 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
                 NODE_1_AS, ROUTER_2_ID));
         readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
             assertEquals(1, topology.getNode().size());
-            final IgpNodeAttributes igpNode2 = topology.getNode().get(0).getAugmentation(Node1.class)
+            final IgpNodeAttributes igpNode2 = topology.getNode().get(0).augmentation(Node1.class)
                     .getIgpNodeAttributes();
             assertEquals(ROUTER_2_ID, igpNode2.getRouterId().get(0).getIpv4Address().getValue());
             assertEquals("updated-node", igpNode2.getName().getValue());
@@ -215,25 +218,25 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
         wTx.delete(LogicalDatastoreType.OPERATIONAL, this.linkstateRouteIID);
         wTx.commit();
         readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
-            assertEquals(0, topology.getNode().size());
-            assertEquals(0, topology.getLink().size());
+            assertNull(topology.getNode());
+            assertNull(topology.getLink());
             return topology;
         });
     }
 
     @Test
-    public void testOspfLinkstateTopologyBuilder() throws ReadFailedException {
+    public void testOspfLinkstateTopologyBuilder() throws InterruptedException, ExecutionException {
         // create node
         updateLinkstateRoute(createLinkstateNodeRoute(ProtocolId.Ospf, "node1", NODE_1_AS, ROUTER_1_ID));
         readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
             assertEquals(1, topology.getNode().size());
             final Node node1 = topology.getNode().get(0);
             assertEquals(NODE_1_OSPF_ID, node1.getNodeId().getValue());
-            final IgpNodeAttributes igpNode1 = node1.getAugmentation(Node1.class).getIgpNodeAttributes();
+            final IgpNodeAttributes igpNode1 = node1.augmentation(Node1.class).getIgpNodeAttributes();
             assertEquals(ROUTER_1_ID, igpNode1.getRouterId().get(0).getIpv4Address().getValue());
             assertEquals("node1", igpNode1.getName().getValue());
-            assertNull(igpNode1.getAugmentation(IgpNodeAttributes1.class));
-            assertEquals(ROUTER_1_ID, igpNode1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns
+            assertNull(igpNode1.augmentation(IgpNodeAttributes1.class));
+            assertEquals(ROUTER_1_ID, igpNode1.augmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns
                     .yang.ospf.topology.rev131021.IgpNodeAttributes1.class).getOspfNodeAttributes().getTed()
                     .getTeRouterIdIpv4().getValue());
             return topology;
@@ -243,8 +246,8 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
         updateLinkstateRoute(createLinkstatePrefixRoute(ProtocolId.Ospf, NODE_1_AS, NODE_1_PREFIX,
                 500L, ROUTER_1_ID));
         readDataOperational(getDataBroker(), this.linkstateTopoBuilder.getInstanceIdentifier(), topology -> {
-            final IgpNodeAttributes igpNode2 = topology.getNode().get(0)
-                    .getAugmentation(Node1.class).getIgpNodeAttributes();
+            final IgpNodeAttributes igpNode2 = topology.getNode().get(0).augmentation(Node1.class)
+                    .getIgpNodeAttributes();
             assertEquals(1, igpNode2.getPrefix().size());
             final Prefix prefix = igpNode2.getPrefix().get(0);
             assertEquals(NODE_1_PREFIX, prefix.getPrefix().getIpv4Prefix().getValue());
@@ -265,13 +268,13 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
                     link1.getLinkId().getValue());
             assertEquals(NODE_1_OSPF_ID, link1.getSource().getSourceNode().getValue());
             assertEquals(NODE_2_OSPF_ID, link1.getDestination().getDestNode().getValue());
-            final IgpLinkAttributes igpLink1 = link1.getAugmentation(Link1.class).getIgpLinkAttributes();
+            final IgpLinkAttributes igpLink1 = link1.augmentation(Link1.class).getIgpLinkAttributes();
             assertEquals("link1", igpLink1.getName());
-            assertNull(igpLink1.getAugmentation(IgpLinkAttributes1.class));
-            assertEquals((short) 1, igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang
+            assertNull(igpLink1.augmentation(IgpLinkAttributes1.class));
+            assertEquals((short) 1, igpLink1.augmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang
                     .ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getMultiTopologyId()
                     .shortValue());
-            assertEquals(2, igpLink1.getAugmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns
+            assertEquals(2, igpLink1.augmentation(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns
                     .yang.ospf.topology.rev131021.IgpLinkAttributes1.class).getOspfLinkAttributes().getTed().getSrlg()
                     .getSrlgValues().size());
             return topology;
@@ -357,7 +360,7 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
 
     private void updateLinkstateRoute(final LinkstateRoute data) {
         final WriteTransaction wTx = getDataBroker().newWriteOnlyTransaction();
-        wTx.put(LogicalDatastoreType.OPERATIONAL, this.linkstateRouteIID, data, true);
+        wTx.mergeParentStructurePut(LogicalDatastoreType.OPERATIONAL, this.linkstateRouteIID, data);
         wTx.commit();
     }
 
@@ -394,10 +397,15 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
             .setAttributes(new AttributesBuilder()
                 .setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build())
                 .addAugmentation(Attributes1.class, new Attributes1Builder()
-                        .setLinkStateAttribute(new PrefixAttributesCaseBuilder().setPrefixAttributes(
-                                new PrefixAttributesBuilder().setOspfForwardingAddress(new IpAddress(
-                                        new Ipv4Address(ospfFwdAddress))).setPrefixMetric(new IgpMetric(igpMetric))
-                                        .build()).build()).build()).build()).build();
+                        .setLinkStateAttribute(new PrefixAttributesCaseBuilder()
+                            .setPrefixAttributes(new PrefixAttributesBuilder()
+                                .setOspfForwardingAddress(new IpAddressNoZone(new Ipv4AddressNoZone(ospfFwdAddress)))
+                                .setPrefixMetric(new IgpMetric(Uint32.valueOf(igpMetric)))
+                                .build())
+                            .build())
+                        .build())
+                .build())
+            .build();
     }
 
     private static LinkstateRoute createLinkstateLinkRoute(final ProtocolId protocolId, final AsNumber localAs,
@@ -411,23 +419,27 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
                                         .build()).build()).build())
                         .setRemoteNodeDescriptors(new RemoteNodeDescriptorsBuilder().setAsNumber(remoteAs).build())
                         .setLinkDescriptors(new LinkDescriptorsBuilder()
-                                .setMultiTopologyId(new TopologyIdentifier(1)).build()).build())
+                                .setMultiTopologyId(new TopologyIdentifier(Uint16.ONE)).build()).build())
                 .setAttributes(new AttributesBuilder()
                         .setOrigin(new OriginBuilder().setValue(BgpOrigin.Igp).build())
                         .addAugmentation(Attributes1.class, new Attributes1Builder()
-                                .setLinkStateAttribute(new LinkAttributesCaseBuilder().setLinkAttributes(
-                                new LinkAttributesBuilder().setSharedRiskLinkGroups(
-                                        Lists.newArrayList(new SrlgId(5L), new SrlgId(15L)))
-                                        .setAdminGroup(new AdministrativeGroup(0L))
+                                .setLinkStateAttribute(new LinkAttributesCaseBuilder()
+                                    .setLinkAttributes(new LinkAttributesBuilder()
+                                        .setSharedRiskLinkGroups(Lists.newArrayList(
+                                            new SrlgId(Uint32.valueOf(5)), new SrlgId(Uint32.valueOf(15))))
+                                        .setAdminGroup(new AdministrativeGroup(Uint32.ZERO))
                                         .setMaxLinkBandwidth(
                                                 new Bandwidth(new byte[]{0x00, 0x00, (byte) 0xff, (byte) 0xff}))
                                         .setMaxReservableBandwidth(
                                                 new Bandwidth(new byte[]{0x00, 0x00, (byte) 0xff, (byte) 0x1f}))
                                         .setUnreservedBandwidth(Lists.newArrayList(new UnreservedBandwidthBuilder()
-                                                .setKey(new UnreservedBandwidthKey((short) 1))
+                                                .withKey(new UnreservedBandwidthKey(Uint8.ONE))
                                                 .setBandwidth(new Bandwidth(new byte[]{0x00, 0x00, 0x00, (byte) 0xff}))
                                                 .build()))
-                                        .setTeMetric(new TeMetric(100L)).setLinkName(linkName).build()).build())
+                                        .setTeMetric(new TeMetric(Uint32.valueOf(100)))
+                                        .setLinkName(linkName)
+                                        .build())
+                                    .build())
                                 .build())
                         .build())
                 .build();
@@ -436,7 +448,7 @@ public class LinkstateTopologyBuilderTest extends AbstractTopologyBuilderTest {
     private static LinkstateRouteBuilder createBaseBuilder(final ProtocolId protocolId) {
         return new LinkstateRouteBuilder()
             .setIdentifier(IDENTIFIER)
-            .setKey(new LinkstateRouteKey(new PathId(0L), LINKSTATE_ROUTE_KEY))
+            .withKey(new LinkstateRouteKey(new PathId(Uint32.ZERO), LINKSTATE_ROUTE_KEY))
             .setRouteKey(LINKSTATE_ROUTE_KEY)
             .setProtocolId(protocolId);
     }