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;
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;
+ 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 = InstanceIdentifier.builder(NETWORK_TOPOLOGY_PATH) //
.child(Topology.class, new TopologyKey(TOPOLOGY_BAR_ID)) //
.build();
- private static final InstanceIdentifier<Source> ABSOLUTE_SOURCE_PATH = InstanceIdentifier.builder(TOPOLOGY_PATH)
+ private static final InstanceIdentifier<Link> LINK_BAR_PATH = InstanceIdentifier.builder(NETWORK_TOPOLOGY_PATH) //
+ .child(Topology.class, new TopologyKey(TOPOLOGY_BAR_ID)) //
.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<Link> WILDCARDED_LINK_PATH = InstanceIdentifier
+ .builder(NETWORK_TOPOLOGY_PATH) //
.child(Topology.class) //
+ .child(Link.class) //
+ .build();
+
+ private static final InstanceIdentifier<Source> ABSOLUTE_SOURCE_PATH = InstanceIdentifier.builder(TOPOLOGY_BAR_PATH)
.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).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() //
.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) //
.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(); //
}
@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);
@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);
.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());
+ }
+
+ }
+
}