import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;
-import com.google.common.collect.Lists;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public void testConnectDeviceCommand() throws Exception {
NetconfConnectDeviceCommand netconfConnectDeviceCommand =
new NetconfConnectDeviceCommand(netconfCommands);
- netconfConnectDeviceCommand.doExecute();
+ netconfConnectDeviceCommand.execute();
verify(netconfCommands, times(0)).connectDevice(any(), any());
- netconfConnectDeviceCommand = new NetconfConnectDeviceCommand(netconfCommands, "192.168.1.1", "7777");
+ netconfConnectDeviceCommand = new NetconfConnectDeviceCommand(netconfCommands, "192.168.1.1", "7777", "user",
+ "pass");
- netconfConnectDeviceCommand.doExecute();
+ netconfConnectDeviceCommand.execute();
doNothing().when(netconfCommands).connectDevice(any(), any());
verify(netconfCommands, times(1)).connectDevice(any(), any());
}
public void testDisconnectDeviceCommand() throws Exception {
NetconfDisconnectDeviceCommand netconfDisconnectDeviceCommand =
new NetconfDisconnectDeviceCommand(netconfCommands);
- netconfDisconnectDeviceCommand.doExecute();
+ netconfDisconnectDeviceCommand.execute();
- verify(netconfCommands, times(0)).connectDevice(any(), any());
+ verify(netconfCommands, times(0)).disconnectDevice(any(), any());
netconfDisconnectDeviceCommand = new NetconfDisconnectDeviceCommand(netconfCommands, "deviceId", null, null);
doReturn(true).when(netconfCommands).disconnectDevice(any());
- netconfDisconnectDeviceCommand.doExecute();
+ netconfDisconnectDeviceCommand.execute();
verify(netconfCommands, times(1)).disconnectDevice(any());
new NetconfDisconnectDeviceCommand(netconfCommands, null, "192.168.1.1", "7777");
doReturn(true).when(netconfCommands).disconnectDevice(any(), any());
- netconfDisconnectDeviceCommand.doExecute();
+ netconfDisconnectDeviceCommand.execute();
verify(netconfCommands, times(1)).disconnectDevice(any(), any());
}
final NetconfListDevicesCommand netconfListDeviceCommand = new NetconfListDevicesCommand(netconfCommands);
doReturn(getDeviceHashMap()).when(netconfCommands).listDevices();
- netconfListDeviceCommand.doExecute();
+ netconfListDeviceCommand.execute();
verify(netconfCommands, times(1)).listDevices();
}
@Test
public void testShowDeviceCommand() throws Exception {
NetconfShowDeviceCommand netconfShowDeviceCommand = new NetconfShowDeviceCommand(netconfCommands);
- netconfShowDeviceCommand.doExecute();
+ netconfShowDeviceCommand.execute();
verify(netconfCommands, times(0)).showDevice(any());
netconfShowDeviceCommand = new NetconfShowDeviceCommand(netconfCommands, "deviceId", null, null);
doReturn(getDeviceHashMap()).when(netconfCommands).showDevice(any());
- netconfShowDeviceCommand.doExecute();
+ 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.doExecute();
+ netconfShowDeviceCommand.execute();
verify(netconfCommands, times(1)).showDevice(any(), any());
}
doReturn("").when(netconfCommands).updateDevice(anyString(), anyString(), anyString(), any());
- netconfUpdateDeviceCommand.doExecute();
+ netconfUpdateDeviceCommand.execute();
- verify(netconfCommands, times(1)).updateDevice(anyString(), anyString(), anyString(),
+ verify(netconfCommands, times(1)).updateDevice(isNull(), isNull(), isNull(),
hashMapArgumentCaptor.capture());
assertTrue(hashMapArgumentCaptor.getValue().containsKey(NetconfConsoleConstants.NETCONF_IP));
assertEquals("192.168.1.1", hashMapArgumentCaptor.getValue().get(NetconfConsoleConstants.NETCONF_IP));
}
- private HashMap getDeviceHashMap() {
+ 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, Lists.newArrayList("192.168.1.1"));
- deviceMap.put(NetconfConsoleConstants.NETCONF_PORT, Lists.newArrayList("7777"));
- deviceMap.put(NetconfConsoleConstants.STATUS, Lists.newArrayList("connecting"));
- deviceMap.put(NetconfConsoleConstants.AVAILABLE_CAPABILITIES, Lists.newArrayList("cap1", "cap2", "cap3"));
+ 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;
}