Shift Builder<P> from toInstance() to build()
[yangtools.git] / integration-test / yang-runtime-tests / src / test / java / org / opendaylight / yangtools / it / yang / runtime / tests / BindingReadingTest.java
index 9220afc5985a9b0ce5142cf9fca03616d538a2cf..89c67c81af9b3739022f2451a1a3d115c67a69af 100644 (file)
@@ -1,9 +1,11 @@
 package org.opendaylight.yangtools.it.yang.runtime.tests;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.util.HashSet;
 import java.util.Map;
 
 import org.junit.Before;
@@ -37,27 +39,41 @@ public class BindingReadingTest {
     private static final NodeId SOURCE_NODE_ID = new NodeId("node:id");
     private static final TpId SOURCE_TP_ID = new TpId("source:tp");
     private static final InstanceIdentifier<NetworkTopology> NETWORK_TOPOLOGY_PATH = InstanceIdentifier.builder(
-            NetworkTopology.class).toInstance();
-    private NetworkTopology topologyModel;
+            NetworkTopology.class).build();
+    private NetworkTopology networkModel;
     private Link linkModel;
 
-    private static final InstanceIdentifier<Topology> TOPOLOGY_PATH =InstanceIdentifier.builder(NETWORK_TOPOLOGY_PATH) //
+    private static final InstanceIdentifier<Topology> TOPOLOGY_BAR_PATH = NETWORK_TOPOLOGY_PATH //
+            .child(Topology.class, new TopologyKey(TOPOLOGY_BAR_ID));
+
+    private static final InstanceIdentifier<Link> LINK_BAR_PATH = NETWORK_TOPOLOGY_PATH.builder() //
             .child(Topology.class, new TopologyKey(TOPOLOGY_BAR_ID)) //
+            .child(Link.class, new LinkKey(LINK_BAR_ID)) //
+            .build();
+
+    private static final InstanceIdentifier<Link> WILDCARDED_LINK_PATH = NETWORK_TOPOLOGY_PATH.builder() //
+            .child(Topology.class) //
+            .child(Link.class) //
             .build();
 
-    private static final InstanceIdentifier<Source> ABSOLUTE_SOURCE_PATH = InstanceIdentifier.builder(TOPOLOGY_PATH)
+    private static final InstanceIdentifier<Source> ABSOLUTE_SOURCE_PATH = TOPOLOGY_BAR_PATH.builder() //
             .child(Link.class, new LinkKey(LINK_BAR_ID)) //
             .child(Source.class) //
             .build();
 
-
-    private static final InstanceIdentifier<Source> WILDCARDED_SOURCE_PATH = InstanceIdentifier.builder(NETWORK_TOPOLOGY_PATH)
+    private static final InstanceIdentifier<Source> WILDCARDED_SOURCE_PATH = NETWORK_TOPOLOGY_PATH.builder() //
             .child(Topology.class) //
             .child(Link.class, new LinkKey(LINK_BAR_ID)) //
             .child(Source.class) //
             .build();
 
-
+    /**
+     *
+     * Creates network topology model with three topologies:
+     * foo,bar and baz.
+     * Where bar has 1 link, and baz has 2 links.
+     *
+     */
     @Before
     public void createTopology() {
         linkModel = new LinkBuilder() //
@@ -67,7 +83,7 @@ public class BindingReadingTest {
                         .setSourceTp(SOURCE_TP_ID) //
                         .build()) //
                 .build();
-        topologyModel = new NetworkTopologyBuilder().setTopology(ImmutableList.<Topology> builder() //
+        networkModel = new NetworkTopologyBuilder().setTopology(ImmutableList.<Topology> builder() //
                 .add(new TopologyBuilder() //
                         .setTopologyId(TOPOLOGY_FOO_ID) //
                         .setServerProvided(true) //
@@ -82,7 +98,12 @@ public class BindingReadingTest {
                 .add(new TopologyBuilder() //
                         .build())//
                 .add(new TopologyBuilder() //
-                        .setTopologyId(TOPOLOGY_BAZ_ID).build()) //
+                        .setTopologyId(TOPOLOGY_BAZ_ID)//
+                        .setLink(ImmutableList.<Link> builder() //
+                                .add(new LinkBuilder().setLinkId(new LinkId("link:2")).build()) //
+                                .add(new LinkBuilder().setLinkId(new LinkId("link:3")).build()) //
+                                .build()) //
+                        .build()) //
                 .build()) //
                 .build(); //
     }
@@ -96,7 +117,8 @@ public class BindingReadingTest {
 
     @Test
     public void testInstanceIdentifierRead() {
-        Map<InstanceIdentifier<Source>, Source> source = DataObjectReadingUtil.readData(topologyModel, NETWORK_TOPOLOGY_PATH, ABSOLUTE_SOURCE_PATH);
+        Map<InstanceIdentifier<Source>, Source> source = DataObjectReadingUtil.readData(networkModel,
+                NETWORK_TOPOLOGY_PATH, ABSOLUTE_SOURCE_PATH);
         assertNotNull(source);
         Source potentialSource = source.get(ABSOLUTE_SOURCE_PATH);
         assertEquals(linkModel.getSource(), potentialSource);
@@ -104,8 +126,10 @@ public class BindingReadingTest {
 
     @Test
     public void testInstanceIdentifierReadWildcarded() {
-        Topology topology = DataObjectReadingUtil.readData(topologyModel, NETWORK_TOPOLOGY_PATH, TOPOLOGY_PATH).get(TOPOLOGY_PATH);
-        Map<InstanceIdentifier<Source>, Source> source = DataObjectReadingUtil.readData(topology, TOPOLOGY_PATH, WILDCARDED_SOURCE_PATH);
+        Topology topology = DataObjectReadingUtil.readData(networkModel, NETWORK_TOPOLOGY_PATH, TOPOLOGY_BAR_PATH).get(
+                TOPOLOGY_BAR_PATH);
+        Map<InstanceIdentifier<Source>, Source> source = DataObjectReadingUtil.readData(topology, TOPOLOGY_BAR_PATH,
+                WILDCARDED_SOURCE_PATH);
         assertNotNull(source);
         Source potentialSource = source.get(ABSOLUTE_SOURCE_PATH);
         assertEquals(linkModel.getSource(), potentialSource);
@@ -113,14 +137,40 @@ public class BindingReadingTest {
 
     @Test
     public void testInstanceIdentifierReadNonExistingValue() {
-        InstanceIdentifier<Source> sourcePath = InstanceIdentifier.builder(NETWORK_TOPOLOGY_PATH) //
+        InstanceIdentifier<Source> sourcePath = NETWORK_TOPOLOGY_PATH.builder() //
                 .child(Topology.class, new TopologyKey(TOPOLOGY_BAZ_ID)) //
                 .child(Link.class, new LinkKey(LINK_BAR_ID)) //
                 .child(Source.class) //
                 .build();
-        Map<InstanceIdentifier<Source>, Source> source = DataObjectReadingUtil.readData(topologyModel, NETWORK_TOPOLOGY_PATH, sourcePath);
+        Map<InstanceIdentifier<Source>, Source> source = DataObjectReadingUtil.readData(networkModel,
+                NETWORK_TOPOLOGY_PATH, sourcePath);
         assertNotNull(source);
         assertTrue(source.isEmpty());
     }
 
+    @Test
+    public void testWildcardedListRead() {
+        Topology topology = DataObjectReadingUtil.readData(networkModel, NETWORK_TOPOLOGY_PATH, TOPOLOGY_BAR_PATH).get(TOPOLOGY_BAR_PATH);
+
+        Map<InstanceIdentifier<Link>, Link> potentialLinks = DataObjectReadingUtil.readData(topology, TOPOLOGY_BAR_PATH, WILDCARDED_LINK_PATH);
+        assertFalse(potentialLinks.isEmpty());
+        assertEquals(1, potentialLinks.size());
+        assertEquals(linkModel, potentialLinks.get(LINK_BAR_PATH));
+    }
+
+    @Test
+    public void testTwoWildcardsListRead() {
+
+        Map<InstanceIdentifier<Link>, Link> potentialLinks = DataObjectReadingUtil.readData(networkModel, NETWORK_TOPOLOGY_PATH, WILDCARDED_LINK_PATH);
+        assertFalse(potentialLinks.isEmpty());
+        assertEquals(3, potentialLinks.size());
+        assertEquals(linkModel, potentialLinks.get(LINK_BAR_PATH));
+        HashSet<Link> allLinks = new HashSet<>(potentialLinks.values());
+        assertEquals(3, allLinks.size());
+        for(InstanceIdentifier<Link> key : potentialLinks.keySet()) {
+            assertFalse("Returned instance identifier must not be wildcarded.", key.isWildcarded());
+        }
+
+    }
+
 }