Add import for netconf-node-optional
[netconf.git] / netconf / netconf-console / src / test / java / org / opendaylight / netconf / console / impl / NetconfCommandsImplTest.java
index a70e629b6e1847985f78d8e6a10b2de0d2cd6f65..03f7331720a5984ac21b536e2ed6f6c1fa0307cb 100644 (file)
@@ -14,7 +14,9 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -23,7 +25,9 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import org.awaitility.Awaitility;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.WriteTransaction;
@@ -51,7 +55,8 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.common.Uint16;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class NetconfCommandsImplTest {
@@ -63,20 +68,28 @@ public class NetconfCommandsImplTest {
             NetconfNodeConnectionStatus.ConnectionStatus.Connected;
     private static final String CAP_PREFIX = "prefix";
 
+    private static EffectiveModelContext SCHEMA_CONTEXT;
+
     private DataBroker dataBroker;
-    private SchemaContext schemaContext;
     private NetconfCommandsImpl netconfCommands;
 
-    @Before
-    public void setUp() throws Exception {
-        schemaContext = YangParserTestUtils.parseYangResources(NetconfCommandsImplTest.class,
+    @BeforeClass
+    public static void beforeClass() {
+        SCHEMA_CONTEXT = YangParserTestUtils.parseYangResources(NetconfCommandsImplTest.class,
             "/schemas/network-topology@2013-10-21.yang", "/schemas/ietf-inet-types@2013-07-15.yang",
-            "/schemas/yang-ext.yang", "/schemas/netconf-node-topology.yang");
-        schemaContext.getModules();
+            "/schemas/yang-ext.yang", "/schemas/netconf-node-topology.yang", "/schemas/netconf-node-optional.yang");
+    }
 
+    @AfterClass
+    public static void afterClass() {
+        SCHEMA_CONTEXT = null;
+    }
+
+    @Before
+    public void setUp() throws Exception {
         ConcurrentDataBrokerTestCustomizer customizer = new ConcurrentDataBrokerTestCustomizer(true);
         dataBroker = customizer.createDataBroker();
-        customizer.updateSchema(schemaContext);
+        customizer.updateSchema(SCHEMA_CONTEXT);
 
         netconfCommands = new NetconfCommandsImpl(dataBroker);
     }
@@ -117,7 +130,8 @@ public class NetconfCommandsImplTest {
     @Test
     public void testConnectDisconnectDevice() throws InterruptedException, TimeoutException, ExecutionException {
         final NetconfNode netconfNode = new NetconfNodeBuilder()
-                .setPort(new PortNumber(7777)).setHost(HostBuilder.getDefaultInstance("10.10.1.1")).build();
+                .setPort(new PortNumber(Uint16.valueOf(7777))).setHost(HostBuilder.getDefaultInstance("10.10.1.1"))
+                .build();
 
         createTopology(LogicalDatastoreType.CONFIGURATION);
         netconfCommands.connectDevice(netconfNode, "netconf-ID");
@@ -125,7 +139,7 @@ public class NetconfCommandsImplTest {
         Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> {
             final Topology topology = NetconfConsoleUtils.read(LogicalDatastoreType.CONFIGURATION,
                     NetconfIidFactory.NETCONF_TOPOLOGY_IID, dataBroker);
-            final List<Node> nodes = topology.getNode();
+            final Collection<Node> nodes = topology.nonnullNode().values();
             if (nodes.size() != 2) {
                 return false;
             }
@@ -146,7 +160,7 @@ public class NetconfCommandsImplTest {
         Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> {
             final Topology topologyDeleted = NetconfConsoleUtils.read(LogicalDatastoreType.CONFIGURATION,
                     NetconfIidFactory.NETCONF_TOPOLOGY_IID, dataBroker);
-            final List<Node> nodesDeleted = topologyDeleted.getNode();
+            final Collection<Node> nodesDeleted = topologyDeleted.nonnullNode().values();
             if (nodesDeleted.size() != 1) {
                 return false;
             }
@@ -175,7 +189,7 @@ public class NetconfCommandsImplTest {
         Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> {
             final Topology topology = NetconfConsoleUtils.read(LogicalDatastoreType.CONFIGURATION,
                     NetconfIidFactory.NETCONF_TOPOLOGY_IID, dataBroker);
-            final List<Node> nodes = topology.getNode();
+            final Collection<Node> nodes = topology.nonnullNode().values();
             if (nodes.size() != 1) {
                 return false;
             }
@@ -202,13 +216,12 @@ public class NetconfCommandsImplTest {
 
     private void createTopology(final LogicalDatastoreType dataStoreType)
             throws TimeoutException, InterruptedException, ExecutionException {
-        final List<Node> nodes = new ArrayList<>();
         final Node node = getNetconfNode(NODE_ID, IP, PORT, CONN_STATUS, CAP_PREFIX);
-        nodes.add(node);
 
         final Topology topology = new TopologyBuilder()
                 .withKey(new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName())))
-                .setTopologyId(new TopologyId(TopologyNetconf.QNAME.getLocalName())).setNode(nodes).build();
+                .setTopologyId(new TopologyId(TopologyNetconf.QNAME.getLocalName()))
+                .setNode(ImmutableMap.of(node.key(), node)).build();
 
         final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
         writeTransaction.put(dataStoreType, NetconfIidFactory.NETCONF_TOPOLOGY_IID, topology);
@@ -219,7 +232,7 @@ public class NetconfCommandsImplTest {
             final NetconfNodeConnectionStatus.ConnectionStatus cs, final String notificationCapabilityPrefix) {
 
         final Host host = HostBuilder.getDefaultInstance(ip);
-        final PortNumber port = new PortNumber(portNumber);
+        final PortNumber port = new PortNumber(Uint16.valueOf(portNumber));
 
         final List<AvailableCapability> avCapList = new ArrayList<>();
         avCapList.add(new AvailableCapabilityBuilder()
@@ -228,15 +241,14 @@ public class NetconfCommandsImplTest {
         final AvailableCapabilities avCaps =
                 new AvailableCapabilitiesBuilder().setAvailableCapability(avCapList).build();
 
-        final NetconfNode nn = new NetconfNodeBuilder().setConnectionStatus(cs).setHost(host).setPort(port)
-                .setAvailableCapabilities(avCaps).build();
         final NodeId nodeId = new NodeId(nodeIdent);
         final NodeKey nk = new NodeKey(nodeId);
-        final NodeBuilder nb = new NodeBuilder();
-        nb.withKey(nk);
-        nb.setNodeId(nodeId);
-        nb.addAugmentation(NetconfNode.class, nn);
-        return nb.build();
+        return new NodeBuilder()
+                .withKey(nk)
+                .setNodeId(nodeId)
+                .addAugmentation(new NetconfNodeBuilder()
+                    .setConnectionStatus(cs).setHost(host).setPort(port).setAvailableCapabilities(avCaps).build())
+                .build();
     }
 
     private static void assertBaseNodeAttributes(final Map<?, ?> mapNode) {