Clean up netconf-console 96/108996/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 16 Nov 2023 19:25:55 +0000 (20:25 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 16 Nov 2023 19:53:39 +0000 (20:53 +0100)
This is all-round cleanup of the component, including migration to
JUnit5.

Change-Id: I53275bd2bf4edd794a796938c5f58e1d4763aa8b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
apps/netconf-console/src/main/java/org/opendaylight/netconf/console/api/NetconfCommands.java
apps/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfCommandUtils.java
apps/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfConnectDeviceCommand.java
apps/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfDisconnectDeviceCommand.java
apps/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfListDevicesCommand.java
apps/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfShowDeviceCommand.java
apps/netconf-console/src/main/java/org/opendaylight/netconf/console/commands/NetconfUpdateDeviceCommand.java
apps/netconf-console/src/main/java/org/opendaylight/netconf/console/impl/NetconfCommandsImpl.java
apps/netconf-console/src/test/java/org/opendaylight/netconf/console/commands/NetconfCommandUtilsTest.java
apps/netconf-console/src/test/java/org/opendaylight/netconf/console/commands/NetconfCommandsImplCallsTest.java
apps/netconf-console/src/test/java/org/opendaylight/netconf/console/impl/NetconfCommandsImplTest.java

index bebfed6d0f9bfa0bb6842f43f721c14f34ffc710..06b91711d41ca5e148b6370fe207b4d64348ffbf 100644 (file)
@@ -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.netconf.console.api;
 
 import java.util.List;
@@ -13,7 +12,6 @@ import java.util.Map;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNode;
 
 public interface NetconfCommands {
-
     /**
      * Returns a Hashmap with NETCONF ID as outer key and
      * inner keys representing attributes of a NETCONF device.
index f705c94062021b393c5b1d72aa1618ef0143720b..f11658e94cee4e54827a896ddc06e2b0b998097d 100644 (file)
@@ -5,30 +5,26 @@
  * 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.netconf.console.commands;
 
 import com.google.common.base.Strings;
-import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-public final class NetconfCommandUtils {
-
-    private static final Pattern IP_PATTERN = Pattern.compile(
-            "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
-                    + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
-                    + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
-                    + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
+final class NetconfCommandUtils {
+    private static final Pattern IP_PATTERN = Pattern.compile("^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
+        + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
+        + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\."
+        + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$");
 
     private NetconfCommandUtils() {
-
+        // Hidden on purpose
     }
 
-    public static boolean isPortValid(final String devicePort) {
-        if (Strings.isNullOrEmpty(devicePort)) {
-            return false;
-        }
-        Integer port;
+    static boolean isPortValid(final String devicePort) {
+//        if (Strings.isNullOrEmpty(devicePort)) {
+//            return false;
+//        }
+        final int port;
         try {
             port = Integer.parseInt(devicePort);
         } catch (NumberFormatException e) {
@@ -37,11 +33,10 @@ public final class NetconfCommandUtils {
         return port >= 0 && port <= 65535;
     }
 
-    public static boolean isIpValid(final String deviceIp) {
+    static boolean isIpValid(final String deviceIp) {
         if (Strings.isNullOrEmpty(deviceIp)) {
             return false;
         }
-        Matcher matcher = IP_PATTERN.matcher(deviceIp);
-        return matcher.matches();
+        return IP_PATTERN.matcher(deviceIp).matches();
     }
 }
index 4a874adbdebf90ba9f0bb4554d107bdc30526bde..7e2829fee5eab7db39edb9a508fc028133608467 100644 (file)
@@ -24,7 +24,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev231025.connection.parameters.Protocol.Name;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev231025.connection.parameters.ProtocolBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev231025.connection.parameters.protocol.specification.TlsCase;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev231025.connection.parameters.protocol.specification.TlsCaseBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev231025.connection.parameters.protocol.specification.tls._case.TlsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev231025.credentials.credentials.LoginPwUnencryptedBuilder;
@@ -35,42 +34,22 @@ import org.opendaylight.yangtools.yang.common.Uint16;
 @Service
 @Command(name = "connect-device", scope = "netconf", description = "Connect to a netconf device.")
 public class NetconfConnectDeviceCommand implements Action {
-
     @Reference
     private NetconfCommands service;
 
-    public NetconfConnectDeviceCommand() {
-
-    }
-
-    @VisibleForTesting
-    NetconfConnectDeviceCommand(final NetconfCommands service) {
-        this.service = service;
-    }
-
-    @VisibleForTesting
-    NetconfConnectDeviceCommand(final NetconfCommands service, final String deviceIp, final String devicePort,
-            final String username, final String password) {
-        this.service = requireNonNull(service);
-        this.deviceIp = requireNonNull(deviceIp);
-        this.devicePort = requireNonNull(devicePort);
-        this.username = requireNonNull(username);
-        this.password = requireNonNull(password);
-    }
-
     @Option(name = "-i",
             aliases = { "--ipaddress" },
             description = "IP address of the netconf device",
             required = true,
             multiValued = false)
-    private String deviceIp;
+    String deviceIp;
 
     @Option(name = "-p",
             aliases = { "--port" },
             description = "Port of the netconf device",
             required = true,
             multiValued = false)
-    private String devicePort;
+    String devicePort;
 
     @Option(name = "-U",
             aliases = { "--username" },
@@ -78,7 +57,7 @@ public class NetconfConnectDeviceCommand implements Action {
             required = false,
             censor = true,
             multiValued = false)
-    private String username;
+    String username;
 
     @Option(name = "-P",
             aliases = { "--password" },
@@ -86,35 +65,35 @@ public class NetconfConnectDeviceCommand implements Action {
             required = false,
             censor = true,
             multiValued = false)
-    private String password;
+    String password;
 
     @Option(name = "-t",
             aliases = { "--tcp-only" },
             description = "Type of connection, true for tcp only",
             required = false,
             multiValued = false)
-    private String connectionType = "false";
+    String connectionType = "false";
 
     @Option(name = "-pr",
             aliases = { "--protocol" },
             description = "Which protocol to be used, ssh or tls",
             required = false,
             multiValued = false)
-    private String protocol = "ssh";
+    String protocol = "ssh";
 
     @Option(name = "-ev",
             aliases = { "--excluded-versions" },
             description = "TLS versions not supported by target device",
             required = false,
             multiValued = false)
-    private String excludedTlsVersions;
+    String excludedTlsVersions;
 
     @Option(name = "-sl",
             aliases = { "--schemaless" },
             description = "Schemaless surpport, true for schemaless",
             required = false,
             multiValued = false)
-    private String schemaless = "false";
+    String schemaless = "false";
 
     @Option(name = "-id",
             aliases = { "--identifier" },
@@ -123,8 +102,27 @@ public class NetconfConnectDeviceCommand implements Action {
             multiValued = false)
     private String deviceId;
 
+    public NetconfConnectDeviceCommand() {
+        // Nothing here, uses injection
+    }
+
+    @VisibleForTesting
+    NetconfConnectDeviceCommand(final NetconfCommands service) {
+        this.service = requireNonNull(service);
+    }
+
+    @VisibleForTesting
+    NetconfConnectDeviceCommand(final NetconfCommands service, final String deviceIp, final String devicePort,
+            final String username, final String password) {
+        this.service = requireNonNull(service);
+        this.deviceIp = requireNonNull(deviceIp);
+        this.devicePort = requireNonNull(devicePort);
+        this.username = requireNonNull(username);
+        this.password = requireNonNull(password);
+    }
+
     @Override
-    public Object execute() {
+    public String execute() {
         if (!NetconfCommandUtils.isIpValid(deviceIp) || !NetconfCommandUtils.isPortValid(devicePort)) {
             return "Invalid IP:" + deviceIp + " or Port:" + devicePort + "Please enter a valid entry to proceed.";
         }
@@ -132,16 +130,16 @@ public class NetconfConnectDeviceCommand implements Action {
         final boolean isTcpOnly = connectionType.equals("true");
         final boolean isSchemaless = schemaless.equals("true");
 
-        final NetconfNodeBuilder netconfNodeBuilder = new NetconfNodeBuilder();
-        netconfNodeBuilder.setHost(new Host(new IpAddress(new Ipv4Address(deviceIp))))
-                          .setPort(new PortNumber(Uint16.valueOf(Integer.decode(devicePort))))
-                          .setTcpOnly(isTcpOnly)
-                          .setSchemaless(isSchemaless);
+        final var netconfNodeBuilder = new NetconfNodeBuilder()
+            .setHost(new Host(new IpAddress(new Ipv4Address(deviceIp))))
+            .setPort(new PortNumber(Uint16.valueOf(Integer.decode(devicePort))))
+            .setTcpOnly(isTcpOnly)
+            .setSchemaless(isSchemaless);
 
         if (isTcpOnly || protocol.equalsIgnoreCase("ssh")) {
             if (Strings.isNullOrEmpty(username) || Strings.isNullOrEmpty(password)) {
-                return "Empty Username:" + username + " or Password:" + password
-                        + ". In TCP or SSH mode, you must provide valid username and password.";
+                return "Empty Username:" + username + " or Password:" + password + ". "
+                    + "In TCP or SSH mode, you must provide valid username and password.";
             }
             netconfNodeBuilder.setCredentials(new LoginPwUnencryptedBuilder()
                 .setLoginPasswordUnencrypted(new LoginPasswordUnencryptedBuilder()
@@ -153,23 +151,17 @@ public class NetconfConnectDeviceCommand implements Action {
                 netconfNodeBuilder.setProtocol(new ProtocolBuilder().setName(Name.SSH).build());
             }
         } else if (protocol.equalsIgnoreCase("tls")) {
-            TlsCase tlsCase = null;
-            if (!Strings.isNullOrEmpty(excludedTlsVersions)) {
-                tlsCase = new TlsCaseBuilder()
-                            .setTls(new TlsBuilder()
-                                    .setExcludedVersions(ImmutableSet.copyOf(excludedTlsVersions.split(","))).build())
-                            .build();
-            }
-            netconfNodeBuilder.setProtocol(new ProtocolBuilder()
-                                            .setName(Name.TLS)
-                                            .setSpecification(tlsCase)
-                                            .build());
+            final var tlsCase = Strings.isNullOrEmpty(excludedTlsVersions) ? null : new TlsCaseBuilder()
+                .setTls(new TlsBuilder()
+                    .setExcludedVersions(ImmutableSet.copyOf(excludedTlsVersions.split(",")))
+                    .build())
+                .build();
+            netconfNodeBuilder.setProtocol(new ProtocolBuilder().setName(Name.TLS).setSpecification(tlsCase).build());
         } else {
             return "Invalid protocol: " + protocol + ". Only SSH and TLS are supported.";
         }
 
         service.connectDevice(netconfNodeBuilder.build(), deviceId);
-        final String message = "Netconf connector added succesfully";
-        return message;
+        return "Netconf connector added succesfully";
     }
 }
index 1ad975245f253a2e08f7d0a15d72bd245176ffcc..68a04aae10e3d30bfb4a9643fa6fa476252cb458 100644 (file)
@@ -5,9 +5,10 @@
  * 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.netconf.console.commands;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Strings;
 import org.apache.karaf.shell.api.action.Action;
@@ -20,52 +21,51 @@ import org.opendaylight.netconf.console.api.NetconfCommands;
 @Service
 @Command(name = "disconnect-device", scope = "netconf", description = "Disconnect netconf device.")
 public class NetconfDisconnectDeviceCommand implements Action {
-
     @Reference
     private NetconfCommands service;
 
-    public NetconfDisconnectDeviceCommand() {
-
-    }
-
-    @VisibleForTesting
-    NetconfDisconnectDeviceCommand(final NetconfCommands service) {
-        this.service = service;
-    }
-
-    @VisibleForTesting
-    NetconfDisconnectDeviceCommand(final NetconfCommands service, final String deviceId, final String deviceIp,
-                                   final String devicePort) {
-        this.service = service;
-        this.deviceId = deviceId;
-        this.deviceIp = deviceIp;
-        this.devicePort = devicePort;
-    }
-
     @Option(name = "-i",
             aliases = { "--ipaddress" },
             description = "IP address of the netconf device",
             required = false,
             multiValued = false)
-    private String deviceIp;
+    String deviceIp;
 
     @Option(name = "-p",
             aliases = { "--port" },
             description = "Port of the netconf device",
             required = false,
             multiValued = false)
-    private String devicePort;
+    String devicePort;
 
     @Option(name = "-id",
             aliases = { "--identifier" },
             description = "Node Identifier of the netconf device",
             required = false,
             multiValued = false)
-    private String deviceId;
+    String deviceId;
+
+    public NetconfDisconnectDeviceCommand() {
+        // Nothing here, uses injection
+    }
+
+    @VisibleForTesting
+    NetconfDisconnectDeviceCommand(final NetconfCommands service) {
+        this.service = requireNonNull(service);
+    }
+
+    @VisibleForTesting
+    NetconfDisconnectDeviceCommand(final NetconfCommands service, final String deviceId, final String deviceIp,
+            final String devicePort) {
+        this.service = requireNonNull(service);
+        this.deviceId = deviceId;
+        this.deviceIp = deviceIp;
+        this.devicePort = devicePort;
+    }
 
     @Override
-    public Object execute() {
-        boolean status = false;
+    public String execute() {
+        final boolean status;
         if (!Strings.isNullOrEmpty(deviceId)) {
             status = service.disconnectDevice(deviceId);
         } else {
@@ -74,8 +74,7 @@ public class NetconfDisconnectDeviceCommand implements Action {
             }
             status = service.disconnectDevice(deviceIp, devicePort);
         }
-        final String message = status ? "Netconf connector disconnected succesfully"
+        return status ? "Netconf connector disconnected succesfully"
                 : "Failed to disconnect netconf connector. Refer to karaf.log for details.";
-        return message;
     }
 }
index 445037be04749a15921e2fd2876f11ec29ee3e80..90c93d30bc44031f141ad6d31eae2ad3ec97ee3f 100644 (file)
@@ -8,25 +8,22 @@
 package org.opendaylight.netconf.console.commands;
 
 import com.google.common.annotations.VisibleForTesting;
-import java.util.Map;
 import org.apache.karaf.shell.api.action.Action;
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.apache.karaf.shell.support.table.ShellTable;
-import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.netconf.console.api.NetconfCommands;
 import org.opendaylight.netconf.console.utils.NetconfConsoleConstants;
 
 @Service
 @Command(name = "list-devices", scope = "netconf", description = "List all netconf devices in the topology.")
 public class NetconfListDevicesCommand implements Action {
-
     @Reference
     private NetconfCommands service;
 
     public NetconfListDevicesCommand() {
-
+        // Nothing here, uses injection
     }
 
     @VisibleForTesting
@@ -35,26 +32,22 @@ public class NetconfListDevicesCommand implements Action {
     }
 
     @Override
-    public Object execute() {
-        final Map<String, Map<String, String>> allDevices = service.listDevices();
-        printDevicesList(allDevices);
-        return null;
-    }
-
     @SuppressWarnings("checkstyle:RegexpSinglelineJava")
-    private static void printDevicesList(final @NonNull Map<String, Map<String, String>> allDevices) {
-        final ShellTable table = new ShellTable();
+    public Object execute() {
+        final var table = new ShellTable();
         table.column(NetconfConsoleConstants.NETCONF_ID).alignLeft();
         table.column(NetconfConsoleConstants.NETCONF_IP).alignLeft();
         table.column(NetconfConsoleConstants.NETCONF_PORT).alignLeft();
         table.column(NetconfConsoleConstants.STATUS).alignLeft();
 
-        for (final Map<String, String> attributes : allDevices.values()) {
-            table.addRow().addContent(attributes.get(NetconfConsoleConstants.NETCONF_ID),
-                    attributes.get(NetconfConsoleConstants.NETCONF_IP),
-                    attributes.get(NetconfConsoleConstants.NETCONF_PORT),
-                    attributes.get(NetconfConsoleConstants.STATUS));
+        for (var attributes : service.listDevices().values()) {
+            table.addRow().addContent(
+                attributes.get(NetconfConsoleConstants.NETCONF_ID),
+                attributes.get(NetconfConsoleConstants.NETCONF_IP),
+                attributes.get(NetconfConsoleConstants.NETCONF_PORT),
+                attributes.get(NetconfConsoleConstants.STATUS));
         }
         table.print(System.out);
+        return null;
     }
 }
index 57d03d0b89be8fd4ad4c6c3659f7156821a00583..ad6670722b150ebc658d6cb01530da6bcede6480 100644 (file)
@@ -7,11 +7,12 @@
  */
 package org.opendaylight.netconf.console.commands;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Strings;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 import org.apache.karaf.shell.api.action.Action;
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Option;
@@ -25,100 +26,89 @@ import org.opendaylight.netconf.console.utils.NetconfConsoleConstants;
 @Service
 @Command(name = "show-device", scope = "netconf", description = "Shows netconf device attributes.")
 public class NetconfShowDeviceCommand implements Action {
-
     @Reference
     private NetconfCommands service;
 
-    public NetconfShowDeviceCommand() {
-
-    }
-
-    @VisibleForTesting
-    NetconfShowDeviceCommand(final NetconfCommands service) {
-        this.service = service;
-    }
-
-    @VisibleForTesting
-    NetconfShowDeviceCommand(final NetconfCommands service, final String deviceId, final String deviceIp,
-                             final String devicePort) {
-        this.service = service;
-        this.deviceId = deviceId;
-        this.deviceIp = deviceIp;
-        this.devicePort = devicePort;
-    }
-
     @Option(name = "-id",
             aliases = { "--identifier" },
             description = "Node Identifier of the netconf device",
             required = false,
             multiValued = false)
-    private String deviceId;
+    String deviceId;
 
     @Option(name = "-i",
             aliases = { "--ipaddress" },
             description = "IP address of the netconf device",
             required = false,
             multiValued = false)
-    private String deviceIp;
+    String deviceIp;
 
     @Option(name = "-p",
             aliases = { "--port" },
             description = "Port of the netconf device",
             required = false,
             multiValued = false)
-    private String devicePort;
+    String devicePort;
 
-    @Override
-    public Object execute() {
+    public NetconfShowDeviceCommand() {
+        // Nothing here, uses injection
+    }
+
+    @VisibleForTesting
+    NetconfShowDeviceCommand(final NetconfCommands service) {
+        this.service = requireNonNull(service);
+    }
 
+    @VisibleForTesting
+    NetconfShowDeviceCommand(final NetconfCommands service, final String deviceId, final String deviceIp,
+            final String devicePort) {
+        this.service = requireNonNull(service);
+        this.deviceId = deviceId;
+        this.deviceIp = deviceIp;
+        this.devicePort = devicePort;
+    }
+
+    @Override
+    public String execute() {
         if ((Strings.isNullOrEmpty(deviceIp) || Strings.isNullOrEmpty(devicePort)) && Strings.isNullOrEmpty(deviceId)) {
             return "You must provide either the device Ip and the device Port or the device Id";
         }
-
-        Map<String, Map<String, List<String>>> devices = null;
-
         if (!Strings.isNullOrEmpty(deviceId)) {
-            devices = service.showDevice(deviceId);
-            printDeviceData(devices);
-            return null;
+            return printDeviceData(service.showDevice(deviceId));
         }
-
         if (!NetconfCommandUtils.isIpValid(deviceIp)
                 || devicePort != null && !NetconfCommandUtils.isPortValid(devicePort)) {
             return "Invalid IP:" + deviceIp + " or Port:" + devicePort + "Please enter a valid entry to proceed.";
         }
-
-        devices = service.showDevice(deviceIp, devicePort);
-        printDeviceData(devices);
-        return null;
+        return printDeviceData(service.showDevice(deviceIp, devicePort));
     }
 
     @SuppressWarnings("checkstyle:RegexpSinglelineJava")
-    private static void printDeviceData(final @NonNull Map<String, Map<String, List<String>>> devices) {
-        final ShellTable table = new ShellTable();
+    private static String printDeviceData(final @NonNull Map<String, Map<String, List<String>>> devices) {
+        final var table = new ShellTable();
         table.column(NetconfConsoleConstants.NETCONF_ID).alignLeft();
         table.column(NetconfConsoleConstants.NETCONF_IP).alignLeft();
         table.column(NetconfConsoleConstants.NETCONF_PORT).alignLeft();
         table.column(NetconfConsoleConstants.STATUS).alignLeft();
         table.column(NetconfConsoleConstants.AVAILABLE_CAPABILITIES).alignLeft();
 
-        for (final Entry<String, Map<String, List<String>>> entry : devices.entrySet()) {
-            final String nodeId = entry.getKey();
-            final Map<String, List<String>> device = entry.getValue();
+        for (var entry : devices.entrySet()) {
+            final var nodeId = entry.getKey();
+            final var device = entry.getValue();
             table.addRow().addContent(nodeId,
-                    device.get(NetconfConsoleConstants.NETCONF_IP).get(NetconfConsoleConstants.DEFAULT_INDEX),
-                    device.get(NetconfConsoleConstants.NETCONF_PORT).get(NetconfConsoleConstants.DEFAULT_INDEX),
-                    device.get(NetconfConsoleConstants.STATUS).get(NetconfConsoleConstants.DEFAULT_INDEX),
-                    device.get(NetconfConsoleConstants.AVAILABLE_CAPABILITIES)
-                            .get(NetconfConsoleConstants.DEFAULT_INDEX));
+                device.get(NetconfConsoleConstants.NETCONF_IP).get(NetconfConsoleConstants.DEFAULT_INDEX),
+                device.get(NetconfConsoleConstants.NETCONF_PORT).get(NetconfConsoleConstants.DEFAULT_INDEX),
+                device.get(NetconfConsoleConstants.STATUS).get(NetconfConsoleConstants.DEFAULT_INDEX),
+                device.get(NetconfConsoleConstants.AVAILABLE_CAPABILITIES) .get(NetconfConsoleConstants.DEFAULT_INDEX));
             formatCapabilities(device, table, NetconfConsoleConstants.AVAILABLE_CAPABILITIES);
         }
         table.print(System.out);
+        return null;
     }
 
     private static void formatCapabilities(final Map<String, List<String>> device, final ShellTable table,
             final String capabilityName) {
-        for (final String availableCapability : device.get(capabilityName)) {
+        for (var availableCapability : device.get(capabilityName)) {
             // First row is already added to table with the first available capability
             // Process rows other than the first to only have remaining available capabilities
             if (!Strings.isNullOrEmpty(availableCapability)
index 9d0581b8a47e4862f143b690e34e2a4378246f32..95eb9e794cab323593b6a2fb6b1ca4ee71b11dff 100644 (file)
@@ -5,12 +5,12 @@
  * 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.netconf.console.commands;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.annotations.VisibleForTesting;
 import java.util.HashMap;
-import java.util.Map;
 import org.apache.karaf.shell.api.action.Action;
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Option;
@@ -22,26 +22,15 @@ import org.opendaylight.netconf.console.utils.NetconfConsoleConstants;
 @Service
 @Command(name = "update-device", scope = "netconf", description = "Update netconf device attributes.")
 public class NetconfUpdateDeviceCommand implements Action {
-
     @Reference
     private NetconfCommands service;
 
-    public NetconfUpdateDeviceCommand() {
-
-    }
-
-    @VisibleForTesting
-    NetconfUpdateDeviceCommand(final NetconfCommands service, final String newIp) {
-        this.service = service;
-        this.newIp = newIp;
-    }
-
     @Option(name = "-id",
             aliases = { "--nodeId" },
             description = "NETCONF node ID of the netconf device",
             required = true,
             multiValued = false)
-    private String deviceId;
+    String deviceId;
 
     @Option(name = "-U",
             aliases = { "--username" },
@@ -49,7 +38,7 @@ public class NetconfUpdateDeviceCommand implements Action {
             required = true,
             censor = true,
             multiValued = false)
-    private String username;
+    String username;
 
     @Option(name = "-P",
             aliases = { "--password" },
@@ -57,59 +46,70 @@ public class NetconfUpdateDeviceCommand implements Action {
             required = true,
             censor = true,
             multiValued = false)
-    private String password;
+    String password;
 
     @Option(name = "-ni",
             aliases = { "--new-ipaddress" },
             description = "New IP address of NETCONF device",
             required = false,
             multiValued = false)
-    private String newIp;
+    String newIp;
 
     @Option(name = "-np",
             aliases = { "--new-port" },
             description = "New Port of NETCONF device",
             required = false,
             multiValued = false)
-    private String newPort;
+    String newPort;
 
     @Option(name = "-nU",
             aliases = { "--new-username" },
             description = "New Username for NETCONF connection",
             required = false,
             multiValued = false)
-    private String newUsername;
+    String newUsername;
 
     @Option(name = "-nP",
             aliases = { "--new-password" },
             description = "New Password for NETCONF connection",
             required = false,
             multiValued = false)
-    private String newPassword;
+    String newPassword;
 
     @Option(name = "-t",
             aliases = { "--tcp-only" },
             description = "Type of connection, true for tcp only",
             required = false,
             multiValued = false)
-    private String newConnectionType = "false";
+    String newConnectionType = "false";
 
     @Option(name = "-sl",
             aliases = { "--schemaless" },
             description = "Schemaless surpport, true for schemaless",
             required = false,
             multiValued = false)
-    private String newSchemaless = "false";
+    String newSchemaless = "false";
+
+    public NetconfUpdateDeviceCommand() {
+        // Nothing here, uses injection
+    }
+
+    @VisibleForTesting
+    NetconfUpdateDeviceCommand(final NetconfCommands service, final String newIp) {
+        this.service = requireNonNull(service);
+        this.newIp = requireNonNull(newIp);
+    }
 
     @Override
     public Object execute() {
-        Map<String, String> updated = new HashMap<>();
+        final var updated = new HashMap<String, String>();
         updated.put(NetconfConsoleConstants.NETCONF_IP, newIp);
         updated.put(NetconfConsoleConstants.NETCONF_PORT, newPort);
         updated.put(NetconfConsoleConstants.USERNAME, newUsername);
         updated.put(NetconfConsoleConstants.PASSWORD, newPassword);
         updated.put(NetconfConsoleConstants.TCP_ONLY, newConnectionType);
-        updated.put(NetconfConsoleConstants.SCHEMALESS,newSchemaless);
+        updated.put(NetconfConsoleConstants.SCHEMALESS, newSchemaless);
+        // FIXME: what is the intent here?
         updated.values().remove(null);
 
         if (updated.isEmpty()) {
index 514bb305df2d71e4e18deed63150a0ba53ceee56..e0a3b42718c1e0780e811519dfe983fc92a87bec 100644 (file)
@@ -40,7 +40,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev231025.cr
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNodeBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.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;
@@ -68,15 +67,15 @@ public class NetconfCommandsImpl implements NetconfCommands {
 
     @Override
     public Map<String, Map<String, String>> listDevices() {
-        final Topology topology = NetconfConsoleUtils.read(LogicalDatastoreType.OPERATIONAL,
-                NetconfIidFactory.NETCONF_TOPOLOGY_IID, dataBroker);
+        final var topology = NetconfConsoleUtils.read(LogicalDatastoreType.OPERATIONAL,
+            NetconfIidFactory.NETCONF_TOPOLOGY_IID, dataBroker);
         if (topology == null) {
             return new HashMap<>();
         }
-        final Map<String, Map<String, String>> netconfNodes = new HashMap<>();
-        for (final Node node : topology.nonnullNode().values()) {
-            final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
-            final Map<String, String> attributes = new HashMap<>();
+        final var netconfNodes = new HashMap<String, Map<String, String>>();
+        for (var node : topology.nonnullNode().values()) {
+            final var netconfNode = node.augmentation(NetconfNode.class);
+            final var attributes = new HashMap<String, String>();
             attributes.put(NetconfConsoleConstants.NETCONF_ID, node.getNodeId().getValue());
             attributes.put(NetconfConsoleConstants.NETCONF_IP,
                     netconfNode.getHost().getIpAddress().getIpv4Address().getValue());
index 0c19ce22d7998497b1d0d640ab5845a3dcdabe9e..b6939ab9fa765b2ef50a8fe3331df670a042704b 100644 (file)
@@ -5,46 +5,29 @@
  * 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.netconf.console.commands;
 
-import static junit.framework.TestCase.assertFalse;
-import static junit.framework.TestCase.assertTrue;
-
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
-public class NetconfCommandUtilsTest {
+import org.junit.jupiter.api.Test;
 
+class NetconfCommandUtilsTest {
     @Test
-    public void testIsPortValid() {
-        final boolean portTrue = NetconfCommandUtils.isPortValid("65535");
-        final boolean portTrue2 = NetconfCommandUtils.isPortValid("0");
-
-        final boolean portFalse = NetconfCommandUtils.isPortValid("123x");
-        final boolean portFalse2 = NetconfCommandUtils.isPortValid("65536");
-        final boolean portFalse3 = NetconfCommandUtils.isPortValid("");
-
-        assertTrue(portTrue);
-        assertTrue(portTrue2);
-        assertFalse(portFalse);
-        assertFalse(portFalse2);
-        assertFalse(portFalse3);
-
+    void testIsPortValid() {
+        assertTrue(NetconfCommandUtils.isPortValid("65535"));
+        assertTrue(NetconfCommandUtils.isPortValid("0"));
+        assertFalse(NetconfCommandUtils.isPortValid("123x"));
+        assertFalse(NetconfCommandUtils.isPortValid("65536"));
+        assertFalse(NetconfCommandUtils.isPortValid(""));
     }
 
     @Test
-    public void testIsIpValid() {
-        final boolean ipTrue = NetconfCommandUtils.isIpValid("0.0.0.0");
-        final boolean ipTrue2 = NetconfCommandUtils.isIpValid("255.255.255.255");
-
-        final boolean ipFalse = NetconfCommandUtils.isIpValid("256.1.1.1");
-        final boolean ipFalse2 = NetconfCommandUtils.isIpValid("123.145.12.x");
-        final boolean ipFalse3 = NetconfCommandUtils.isIpValid("");
-
-        assertTrue(ipTrue);
-        assertTrue(ipTrue2);
-        assertFalse(ipFalse);
-        assertFalse(ipFalse2);
-        assertFalse(ipFalse3);
+    void testIsIpValid() {
+        assertTrue(NetconfCommandUtils.isIpValid("0.0.0.0"));
+        assertTrue(NetconfCommandUtils.isIpValid("255.255.255.255"));
+        assertFalse(NetconfCommandUtils.isIpValid("256.1.1.1"));
+        assertFalse(NetconfCommandUtils.isIpValid("123.145.12.x"));
+        assertFalse(NetconfCommandUtils.isIpValid(""));
     }
 }
index 76735116858d1cc3bf58f03a6091d2dca3d49db7..a9c0156598b3e08ebcaf9291e2cbda46070e69ad 100644 (file)
  * 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.netconf.console.commands;
 
-import static junit.framework.TestCase.assertEquals;
-import static junit.framework.TestCase.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.isNull;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
-import java.util.Arrays;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.netconf.console.api.NetconfCommands;
 import org.opendaylight.netconf.console.utils.NetconfConsoleConstants;
 
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class NetconfCommandsImplCallsTest {
-
+@ExtendWith(MockitoExtension.class)
+class NetconfCommandsImplCallsTest {
     @Mock
     private NetconfCommands netconfCommands;
 
     @Test
-    public void testConnectDeviceCommand() throws Exception {
-        NetconfConnectDeviceCommand netconfConnectDeviceCommand =
-                new NetconfConnectDeviceCommand(netconfCommands);
-        netconfConnectDeviceCommand.execute();
+    void testConnectDeviceCommand() throws Exception {
+        var netconfConnectDeviceCommand = new NetconfConnectDeviceCommand(netconfCommands);
+        assertEquals("Invalid IP:null or Port:nullPlease enter a valid entry to proceed.",
+            netconfConnectDeviceCommand.execute());
         verify(netconfCommands, times(0)).connectDevice(any(), any());
 
         netconfConnectDeviceCommand = new NetconfConnectDeviceCommand(netconfCommands, "192.168.1.1", "7777", "user",
             "pass");
 
-        netconfConnectDeviceCommand.execute();
+        assertEquals("Netconf connector added succesfully", netconfConnectDeviceCommand.execute());
         verify(netconfCommands, times(1)).connectDevice(any(), any());
     }
 
     @Test
-    public void testDisconnectDeviceCommand() throws Exception {
-        NetconfDisconnectDeviceCommand netconfDisconnectDeviceCommand =
-                new NetconfDisconnectDeviceCommand(netconfCommands);
-        netconfDisconnectDeviceCommand.execute();
+    void testDisconnectDeviceCommand() throws Exception {
+        var netconfDisconnectDeviceCommand = new NetconfDisconnectDeviceCommand(netconfCommands);
+        assertEquals("Invalid IP:null or Port:nullPlease enter a valid entry to proceed.",
+            netconfDisconnectDeviceCommand.execute());
 
         verify(netconfCommands, times(0)).disconnectDevice(any(), any());
 
         netconfDisconnectDeviceCommand = new NetconfDisconnectDeviceCommand(netconfCommands, "deviceId", null, null);
 
         doReturn(true).when(netconfCommands).disconnectDevice(any());
-        netconfDisconnectDeviceCommand.execute();
+        assertEquals("Netconf connector disconnected succesfully", netconfDisconnectDeviceCommand.execute());
 
         verify(netconfCommands, times(1)).disconnectDevice(any());
 
-        netconfDisconnectDeviceCommand =
-                new NetconfDisconnectDeviceCommand(netconfCommands, null, "192.168.1.1", "7777");
-
+        netconfDisconnectDeviceCommand = new NetconfDisconnectDeviceCommand(netconfCommands, null, "192.168.1.1",
+            "7777");
         doReturn(true).when(netconfCommands).disconnectDevice(any(), any());
-        netconfDisconnectDeviceCommand.execute();
+        assertEquals("Netconf connector disconnected succesfully", netconfDisconnectDeviceCommand.execute());
 
         verify(netconfCommands, times(1)).disconnectDevice(any(), any());
     }
 
     @Test
-    public void testListDeviceCommand() throws Exception {
-        final NetconfListDevicesCommand netconfListDeviceCommand = new NetconfListDevicesCommand(netconfCommands);
+    void testListDeviceCommand() throws Exception {
+        final var netconfListDeviceCommand = new NetconfListDevicesCommand(netconfCommands);
         doReturn(getDeviceHashMap()).when(netconfCommands).listDevices();
 
-        netconfListDeviceCommand.execute();
+        assertNull(netconfListDeviceCommand.execute());
 
         verify(netconfCommands, times(1)).listDevices();
     }
 
     @Test
-    public void testShowDeviceCommand() throws Exception {
-        NetconfShowDeviceCommand netconfShowDeviceCommand = new NetconfShowDeviceCommand(netconfCommands);
-        netconfShowDeviceCommand.execute();
+    void testShowDeviceCommand() throws Exception {
+        var netconfShowDeviceCommand = new NetconfShowDeviceCommand(netconfCommands);
+        assertEquals("You must provide either the device Ip and the device Port or the device Id",
+            netconfShowDeviceCommand.execute());
 
         verify(netconfCommands, times(0)).showDevice(any());
 
         netconfShowDeviceCommand = new NetconfShowDeviceCommand(netconfCommands, "deviceId", null, null);
 
         doReturn(getDeviceHashMap()).when(netconfCommands).showDevice(any());
-        netconfShowDeviceCommand.execute();
+        assertNull(netconfShowDeviceCommand.execute());
 
         verify(netconfCommands, times(1)).showDevice(any());
 
         netconfShowDeviceCommand = new NetconfShowDeviceCommand(netconfCommands, null, "192.168.1.1", "7777");
 
         doReturn(getDeviceHashMap()).when(netconfCommands).showDevice(any(), any());
-        netconfShowDeviceCommand.execute();
+        assertNull(netconfShowDeviceCommand.execute());
 
         verify(netconfCommands, times(1)).showDevice(any(), any());
     }
 
     @Test
     @SuppressWarnings("unchecked")
-    public void testUpdateDeviceCommand() throws Exception {
-        final NetconfUpdateDeviceCommand netconfUpdateDeviceCommand =
-                new NetconfUpdateDeviceCommand(netconfCommands, "192.168.1.1");
+    void testUpdateDeviceCommand() throws Exception {
+        final var netconfUpdateDeviceCommand = new NetconfUpdateDeviceCommand(netconfCommands, "192.168.1.1");
+        doReturn("").when(netconfCommands).updateDevice(isNull(), isNull(), isNull(), any());
 
-        final ArgumentCaptor<HashMap> hashMapArgumentCaptor = ArgumentCaptor.forClass(HashMap.class);
-
-        doReturn("").when(netconfCommands).updateDevice(isNull(), isNull(), isNull(), any(HashMap.class));
-
-        netconfUpdateDeviceCommand.execute();
+        assertEquals("", netconfUpdateDeviceCommand.execute());
 
+        final var hashMapArgumentCaptor = ArgumentCaptor.forClass(Map.class);
         verify(netconfCommands, times(1)).updateDevice(isNull(), isNull(), isNull(),
                 hashMapArgumentCaptor.capture());
 
@@ -123,15 +117,11 @@ public class NetconfCommandsImplCallsTest {
         assertEquals("192.168.1.1", hashMapArgumentCaptor.getValue().get(NetconfConsoleConstants.NETCONF_IP));
     }
 
-    private static HashMap<String, Map<String, List<String>>> getDeviceHashMap() {
-        final HashMap<String, Map<String, List<String>>> devices = new HashMap<>();
-        final HashMap<String, List<String>> deviceMap = new HashMap<>();
-        deviceMap.put(NetconfConsoleConstants.NETCONF_IP, Arrays.asList("192.168.1.1"));
-        deviceMap.put(NetconfConsoleConstants.NETCONF_PORT, Arrays.asList("7777"));
-        deviceMap.put(NetconfConsoleConstants.STATUS, Arrays.asList("connecting"));
-        deviceMap.put(NetconfConsoleConstants.AVAILABLE_CAPABILITIES, Arrays.asList("cap1", "cap2", "cap3"));
-        devices.put("device", deviceMap);
-        return devices;
+    private static Map<String, Map<String, List<String>>> getDeviceHashMap() {
+        return Map.of("device", Map.of(
+            NetconfConsoleConstants.NETCONF_IP, List.of("192.168.1.1"),
+            NetconfConsoleConstants.NETCONF_PORT, List.of("7777"),
+            NetconfConsoleConstants.STATUS, List.of("connecting"),
+            NetconfConsoleConstants.AVAILABLE_CAPABILITIES, List.of("cap1", "cap2", "cap3")));
     }
-
 }
index e0fe00ce8fc8d6a4ffe518fa6a33ce8f88c51220..c9c1ff985247dfd702864b55fd89557c1feb0495 100644 (file)
@@ -7,28 +7,17 @@
  */
 package org.opendaylight.netconf.console.impl;
 
-import static junit.framework.TestCase.assertFalse;
-import static junit.framework.TestCase.assertTrue;
-import static org.junit.Assert.assertEquals;
-
-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 static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
-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.junit.jupiter.api.Test;
 import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.WriteTransaction;
 import org.opendaylight.mdsal.binding.dom.adapter.test.ConcurrentDataBrokerTestCustomizer;
 import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeContext;
 import org.opendaylight.mdsal.binding.runtime.spi.BindingRuntimeHelpers;
@@ -41,7 +30,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 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.PortNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev231025.ConnectionOper.ConnectionStatus;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev231025.connection.oper.AvailableCapabilities;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev231025.connection.oper.AvailableCapabilitiesBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev231025.connection.oper.available.capabilities.AvailableCapability;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev231025.connection.oper.available.capabilities.AvailableCapabilityBuilder;
@@ -50,101 +38,93 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev22
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.network.topology.topology.topology.types.TopologyNetconf;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
-import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
 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.yangtools.yang.binding.util.BindingMap;
 import org.opendaylight.yangtools.yang.common.Uint16;
 
-public class NetconfCommandsImplTest {
+class NetconfCommandsImplTest {
     private static final String NODE_ID = "NodeID";
     private static final String IP = "192.168.1.1";
     private static final int PORT = 1234;
     private static final ConnectionStatus CONN_STATUS = ConnectionStatus.Connected;
     private static final String CAP_PREFIX = "prefix";
 
-    private static BindingRuntimeContext RUNTIME_CONTEXT;
-
-    private DataBroker dataBroker;
-    private NetconfCommandsImpl netconfCommands;
-
-    @BeforeClass
-    public static void beforeClass() {
-        RUNTIME_CONTEXT = BindingRuntimeHelpers.createRuntimeContext(TopologyNetconf.class);
-    }
+    private static BindingRuntimeContext RUNTIME_CONTEXT =
+        BindingRuntimeHelpers.createRuntimeContext(TopologyNetconf.class);
 
-    @AfterClass
-    public static void afterClass() {
-        RUNTIME_CONTEXT = null;
-    }
+    private final DataBroker dataBroker;
+    private final NetconfCommandsImpl netconfCommands;
 
-    @Before
-    public void setUp() throws Exception {
-        ConcurrentDataBrokerTestCustomizer customizer = new ConcurrentDataBrokerTestCustomizer(true);
+    NetconfCommandsImplTest() {
+        final var customizer = new ConcurrentDataBrokerTestCustomizer(true);
         dataBroker = customizer.createDataBroker();
         customizer.updateSchema(RUNTIME_CONTEXT);
-
         netconfCommands = new NetconfCommandsImpl(dataBroker);
     }
 
     @Test
-    public void testListDevice() throws TimeoutException, InterruptedException, ExecutionException {
+    void testListDevice() throws Exception {
         createTopology(LogicalDatastoreType.OPERATIONAL);
 
-        final Map<?, ?> map = netconfCommands.listDevices();
+        final var map = netconfCommands.listDevices();
+        // FIXME: WHAT?!
         map.containsKey(NetconfConsoleConstants.NETCONF_ID);
         assertTrue(map.containsKey(NODE_ID));
 
-        final Map<?, ?> mapNode = (Map<?, ?>) map.get(NODE_ID);
+        final var mapNode = map.get(NODE_ID);
         assertBaseNodeAttributes(mapNode);
     }
 
     @Test
-    public void testShowDevice() throws TimeoutException, InterruptedException, ExecutionException {
+    void testShowDevice() throws Exception {
         createTopology(LogicalDatastoreType.OPERATIONAL);
 
-        final Map<?, ?> mapCorrect = netconfCommands.showDevice(IP, String.valueOf(PORT));
+        final var mapCorrect = netconfCommands.showDevice(IP, String.valueOf(PORT));
+        // FIXME: WHAT?!
         mapCorrect.containsKey(NetconfConsoleConstants.NETCONF_ID);
         assertTrue(mapCorrect.containsKey(NODE_ID));
 
-        assertBaseNodeAttributesImmutableList((Map<?, ?>) mapCorrect.get(NODE_ID));
+        assertBaseNodeAttributesList(mapCorrect.get(NODE_ID));
 
-        final Map<?, ?> mapWrongPort = netconfCommands.showDevice(IP, "1");
+        final var mapWrongPort = netconfCommands.showDevice(IP, "1");
         assertFalse(mapWrongPort.containsKey(NODE_ID));
 
-        final Map<?, ?> mapWrongIP = netconfCommands.showDevice("1.1.1.1", String.valueOf(PORT));
+        final var mapWrongIP = netconfCommands.showDevice("1.1.1.1", String.valueOf(PORT));
         assertFalse(mapWrongIP.containsKey(NODE_ID));
 
-        final Map<?, ?> mapId = netconfCommands.showDevice(NODE_ID);
+        final var mapId = netconfCommands.showDevice(NODE_ID);
         assertTrue(mapId.containsKey(NODE_ID));
-        assertBaseNodeAttributesImmutableList((Map<?, ?>) mapId.get(NODE_ID));
+        assertBaseNodeAttributesList(mapId.get(NODE_ID));
     }
 
     @Test
-    public void testConnectDisconnectDevice() throws InterruptedException, TimeoutException, ExecutionException {
-        final NetconfNode netconfNode = new NetconfNodeBuilder()
-                .setPort(new PortNumber(Uint16.valueOf(7777)))
-                .setHost(new Host(new IpAddress(new Ipv4Address("10.10.1.1"))))
-                .build();
+    void testConnectDisconnectDevice() throws Exception {
+        final var netconfNode = new NetconfNodeBuilder()
+            .setPort(new PortNumber(Uint16.valueOf(7777)))
+            .setHost(new Host(new IpAddress(new Ipv4Address("10.10.1.1"))))
+            .build();
 
         createTopology(LogicalDatastoreType.CONFIGURATION);
         netconfCommands.connectDevice(netconfNode, "netconf-ID");
 
         Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> {
-            final Topology topology = NetconfConsoleUtils.read(LogicalDatastoreType.CONFIGURATION,
+            final var topology = NetconfConsoleUtils.read(LogicalDatastoreType.CONFIGURATION,
                     NetconfIidFactory.NETCONF_TOPOLOGY_IID, dataBroker);
-            final Collection<Node> nodes = topology.nonnullNode().values();
+            final var nodes = topology.nonnullNode().values();
             if (nodes.size() != 2) {
                 return false;
             }
 
-            final Optional<Node> storedNode = nodes.stream().filter(node ->
-                    node.key().getNodeId().getValue().equals("netconf-ID")).findFirst();
+            final var storedNode = nodes.stream()
+                .filter(node -> node.key().getNodeId().getValue().equals("netconf-ID"))
+                .findFirst();
 
             assertTrue(storedNode.isPresent());
 
-            NetconfNode storedNetconfNode = storedNode.orElseThrow().augmentation(NetconfNode.class);
+            final var storedNetconfNode = storedNode.orElseThrow().augmentation(NetconfNode.class);
             assertEquals(7777, storedNetconfNode.getPort().getValue().longValue());
             assertEquals("10.10.1.1", storedNetconfNode.getHost().getIpAddress().getIpv4Address().getValue());
             return true;
@@ -153,84 +133,79 @@ public class NetconfCommandsImplTest {
         netconfCommands.disconnectDevice("netconf-ID");
 
         Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> {
-            final Topology topologyDeleted = NetconfConsoleUtils.read(LogicalDatastoreType.CONFIGURATION,
+            final var topologyDeleted = NetconfConsoleUtils.read(LogicalDatastoreType.CONFIGURATION,
                     NetconfIidFactory.NETCONF_TOPOLOGY_IID, dataBroker);
-            final Collection<Node> nodesDeleted = topologyDeleted.nonnullNode().values();
+            final var nodesDeleted = topologyDeleted.nonnullNode().values();
             if (nodesDeleted.size() != 1) {
                 return false;
             }
 
-            final Optional<Node> storedNodeDeleted = nodesDeleted.stream().filter(node ->
-                    node.key().getNodeId().getValue().equals("netconf-ID")).findFirst();
-
-            assertFalse(storedNodeDeleted.isPresent());
+            assertEquals(Optional.empty(), nodesDeleted.stream()
+                .filter(node -> node.key().getNodeId().getValue().equals("netconf-ID"))
+                .findFirst());
             return true;
         });
     }
 
     @Test
-    public void testUpdateDevice() throws TimeoutException, InterruptedException, ExecutionException {
+    void testUpdateDevice() throws Exception {
         //We need both, read data from OPERATIONAL DS and update data in CONFIGURATIONAL DS
         createTopology(LogicalDatastoreType.OPERATIONAL);
         createTopology(LogicalDatastoreType.CONFIGURATION);
 
-        final Map<String, String> update = new HashMap<>();
-        update.put(NetconfConsoleConstants.NETCONF_IP, "7.7.7.7");
-        update.put(NetconfConsoleConstants.TCP_ONLY, "true");
-        update.put(NetconfConsoleConstants.SCHEMALESS, "true");
-
-        netconfCommands.updateDevice(NODE_ID, "admin", "admin", update);
+        netconfCommands.updateDevice(NODE_ID, "admin", "admin", Map.of(
+            NetconfConsoleConstants.NETCONF_IP, "7.7.7.7",
+            NetconfConsoleConstants.TCP_ONLY, "true",
+            NetconfConsoleConstants.SCHEMALESS, "true"));
 
         Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> {
-            final Topology topology = NetconfConsoleUtils.read(LogicalDatastoreType.CONFIGURATION,
+            final var topology = NetconfConsoleUtils.read(LogicalDatastoreType.CONFIGURATION,
                     NetconfIidFactory.NETCONF_TOPOLOGY_IID, dataBroker);
-            final Collection<Node> nodes = topology.nonnullNode().values();
+            final var nodes = topology.nonnullNode().values();
             if (nodes.size() != 1) {
                 return false;
             }
 
-            final Optional<Node> storedNode = nodes.stream().filter(node ->
-                    node.key().getNodeId().getValue().equals(NODE_ID)).findFirst();
+            final var storedNode = nodes.stream()
+                .filter(node -> node.key().getNodeId().getValue().equals(NODE_ID))
+                .findFirst();
             assertTrue(storedNode.isPresent());
 
-            NetconfNode storedNetconfNode = storedNode.orElseThrow().augmentation(NetconfNode.class);
+            final var storedNetconfNode = storedNode.orElseThrow().augmentation(NetconfNode.class);
             assertEquals("7.7.7.7", storedNetconfNode.getHost().getIpAddress().getIpv4Address().getValue());
             return true;
         });
     }
 
-    private void createTopology(final LogicalDatastoreType dataStoreType)
-            throws TimeoutException, InterruptedException, ExecutionException {
-        final Node node = getNetconfNode(NODE_ID, IP, PORT, CONN_STATUS, CAP_PREFIX);
-
-        final Topology topology = new TopologyBuilder()
-                .withKey(new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName())))
-                .setTopologyId(new TopologyId(TopologyNetconf.QNAME.getLocalName()))
-                .setNode(ImmutableMap.of(node.key(), node)).build();
+    private void createTopology(final LogicalDatastoreType dataStoreType) throws Exception {
+        final var node = getNetconfNode(NODE_ID, IP, PORT, CONN_STATUS, CAP_PREFIX);
+        final var topology = new TopologyBuilder()
+            .withKey(new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName())))
+            .setTopologyId(new TopologyId(TopologyNetconf.QNAME.getLocalName()))
+            .setNode(BindingMap.of(node))
+            .build();
 
-        final WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
+        final var writeTransaction = dataBroker.newWriteOnlyTransaction();
         writeTransaction.put(dataStoreType, NetconfIidFactory.NETCONF_TOPOLOGY_IID, topology);
         writeTransaction.commit().get(2, TimeUnit.SECONDS);
     }
 
     private static Node getNetconfNode(final String nodeIdent, final String ip, final int portNumber,
             final ConnectionStatus cs, final String notificationCapabilityPrefix) {
-
-        final Host host = new Host(new IpAddress(new Ipv4Address(ip)));
-        final PortNumber port = new PortNumber(Uint16.valueOf(portNumber));
-
-        final List<AvailableCapability> avCapList = new ArrayList<>();
-        avCapList.add(new AvailableCapabilityBuilder()
-                .setCapabilityOrigin(AvailableCapability.CapabilityOrigin.UserDefined)
-                .setCapability(notificationCapabilityPrefix + "_availableCapabilityString1").build());
-        final AvailableCapabilities avCaps =
-                new AvailableCapabilitiesBuilder().setAvailableCapability(avCapList).build();
-
         return new NodeBuilder()
-                .setNodeId(new NodeId(nodeIdent))
-                .addAugmentation(new NetconfNodeBuilder()
-                    .setConnectionStatus(cs).setHost(host).setPort(port).setAvailableCapabilities(avCaps).build())
-                .build();
+            .setNodeId(new NodeId(nodeIdent))
+            .addAugmentation(new NetconfNodeBuilder()
+                .setConnectionStatus(cs)
+                .setHost(new Host(new IpAddress(new Ipv4Address(ip))))
+                .setPort(new PortNumber(Uint16.valueOf(portNumber)))
+                .setAvailableCapabilities(new AvailableCapabilitiesBuilder()
+                    .setAvailableCapability(List.of(new AvailableCapabilityBuilder()
+                        .setCapabilityOrigin(AvailableCapability.CapabilityOrigin.UserDefined)
+                        .setCapability(notificationCapabilityPrefix + "_availableCapabilityString1")
+                        .build()))
+                    .build())
+                .build())
+            .build();
     }
 
     private static void assertBaseNodeAttributes(final Map<?, ?> mapNode) {
@@ -245,15 +220,15 @@ public class NetconfCommandsImplTest {
         assertEquals(CONN_STATUS.name().toLowerCase(), mapNode.get(NetconfConsoleConstants.STATUS));
     }
 
-    private static void assertBaseNodeAttributesImmutableList(final Map<?, ?> mapNode) {
+    private static void assertBaseNodeAttributesList(final Map<?, ?> mapNode) {
         assertTrue(mapNode.containsKey(NetconfConsoleConstants.NETCONF_ID));
         assertTrue(mapNode.containsKey(NetconfConsoleConstants.NETCONF_IP));
         assertTrue(mapNode.containsKey(NetconfConsoleConstants.NETCONF_PORT));
         assertTrue(mapNode.containsKey(NetconfConsoleConstants.STATUS));
 
-        assertEquals(ImmutableList.of(NODE_ID), mapNode.get(NetconfConsoleConstants.NETCONF_ID));
-        assertEquals(ImmutableList.of(IP), mapNode.get(NetconfConsoleConstants.NETCONF_IP));
-        assertEquals(ImmutableList.of(String.valueOf(PORT)), mapNode.get(NetconfConsoleConstants.NETCONF_PORT));
-        assertEquals(ImmutableList.of(CONN_STATUS.name()), mapNode.get(NetconfConsoleConstants.STATUS));
+        assertEquals(List.of(NODE_ID), mapNode.get(NetconfConsoleConstants.NETCONF_ID));
+        assertEquals(List.of(IP), mapNode.get(NetconfConsoleConstants.NETCONF_IP));
+        assertEquals(List.of(String.valueOf(PORT)), mapNode.get(NetconfConsoleConstants.NETCONF_PORT));
+        assertEquals(List.of(CONN_STATUS.name()), mapNode.get(NetconfConsoleConstants.STATUS));
     }
 }