1 package org.opendaylight.yangtools.it.yang.runtime.tests;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertTrue;
9 import org.junit.Before;
10 import org.junit.Test;
11 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId;
12 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
13 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopologyBuilder;
14 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.Source;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.link.attributes.SourceBuilder;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkBuilder;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.LinkKey;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.opendaylight.yangtools.yang.binding.util.DataObjectReadingUtil;
28 import com.google.common.base.Optional;
29 import com.google.common.collect.ImmutableList;
31 public class BindingReadingTest {
33 private static final TopologyId TOPOLOGY_FOO_ID = new TopologyId("foo:topo");
34 private static final TopologyId TOPOLOGY_BAR_ID = new TopologyId("bar:topo");
35 private static final TopologyId TOPOLOGY_BAZ_ID = new TopologyId("baz:topo");
36 private static final LinkId LINK_BAR_ID = new LinkId("bar:link:1");
37 private static final NodeId SOURCE_NODE_ID = new NodeId("node:id");
38 private static final TpId SOURCE_TP_ID = new TpId("source:tp");
39 private static final InstanceIdentifier<NetworkTopology> NETWORK_TOPOLOGY_PATH = InstanceIdentifier.builder(
40 NetworkTopology.class).toInstance();
41 private NetworkTopology topologyModel;
42 private Link linkModel;
44 private static final InstanceIdentifier<Topology> TOPOLOGY_PATH =InstanceIdentifier.builder(NETWORK_TOPOLOGY_PATH) //
45 .child(Topology.class, new TopologyKey(TOPOLOGY_BAR_ID)) //
48 private static final InstanceIdentifier<Source> ABSOLUTE_SOURCE_PATH = InstanceIdentifier.builder(TOPOLOGY_PATH)
49 .child(Link.class, new LinkKey(LINK_BAR_ID)) //
50 .child(Source.class) //
54 private static final InstanceIdentifier<Source> WILDCARDED_SOURCE_PATH = InstanceIdentifier.builder(NETWORK_TOPOLOGY_PATH)
55 .child(Topology.class) //
56 .child(Link.class, new LinkKey(LINK_BAR_ID)) //
57 .child(Source.class) //
62 public void createTopology() {
63 linkModel = new LinkBuilder() //
64 .setLinkId(LINK_BAR_ID) //
65 .setSource(new SourceBuilder() //
66 .setSourceNode(SOURCE_NODE_ID) //
67 .setSourceTp(SOURCE_TP_ID) //
70 topologyModel = new NetworkTopologyBuilder().setTopology(ImmutableList.<Topology> builder() //
71 .add(new TopologyBuilder() //
72 .setTopologyId(TOPOLOGY_FOO_ID) //
73 .setServerProvided(true) //
75 .add(new TopologyBuilder() //
76 .setTopologyId(TOPOLOGY_BAR_ID) //
77 .setServerProvided(false) //
78 .setLink(ImmutableList.<Link> builder() //
82 .add(new TopologyBuilder() //
84 .add(new TopologyBuilder() //
85 .setTopologyId(TOPOLOGY_BAZ_ID).build()) //
91 public void testContainerRead() {
92 Optional<Source> source = DataObjectReadingUtil.readData(linkModel, Source.class);
93 assertNotNull(source);
94 assertEquals(linkModel.getSource(), source.get());
98 public void testInstanceIdentifierRead() {
99 Map<InstanceIdentifier<Source>, Source> source = DataObjectReadingUtil.readData(topologyModel, NETWORK_TOPOLOGY_PATH, ABSOLUTE_SOURCE_PATH);
100 assertNotNull(source);
101 Source potentialSource = source.get(ABSOLUTE_SOURCE_PATH);
102 assertEquals(linkModel.getSource(), potentialSource);
106 public void testInstanceIdentifierReadWildcarded() {
107 Topology topology = DataObjectReadingUtil.readData(topologyModel, NETWORK_TOPOLOGY_PATH, TOPOLOGY_PATH).get(TOPOLOGY_PATH);
108 Map<InstanceIdentifier<Source>, Source> source = DataObjectReadingUtil.readData(topology, TOPOLOGY_PATH, WILDCARDED_SOURCE_PATH);
109 assertNotNull(source);
110 Source potentialSource = source.get(ABSOLUTE_SOURCE_PATH);
111 assertEquals(linkModel.getSource(), potentialSource);
115 public void testInstanceIdentifierReadNonExistingValue() {
116 InstanceIdentifier<Source> sourcePath = InstanceIdentifier.builder(NETWORK_TOPOLOGY_PATH) //
117 .child(Topology.class, new TopologyKey(TOPOLOGY_BAZ_ID)) //
118 .child(Link.class, new LinkKey(LINK_BAR_ID)) //
119 .child(Source.class) //
121 Map<InstanceIdentifier<Source>, Source> source = DataObjectReadingUtil.readData(topologyModel, NETWORK_TOPOLOGY_PATH, sourcePath);
122 assertNotNull(source);
123 assertTrue(source.isEmpty());