aboutsummaryrefslogtreecommitdiffstats
path: root/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2019-02-05 12:16:19 +0000
committerTakamune Cho <takamune.cho@att.com>2019-02-05 14:11:14 +0000
commit5b51c60562b6a42500d502bb13d3ebbc17920b0a (patch)
tree9b6a6c4f691df4d99349f350a64b05e9c5982b56 /appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle
parentd535447594e5812ed7e038f944741b0b38fe73b6 (diff)
Test coverage in netconf-oldconnector
Increased coverage from 0% to 92% for package Issue-ID: APPC-1388 Change-Id: I9f332f799f67937a40c09bdf724701ef80bbad89 Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle')
-rw-r--r--appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java12
-rw-r--r--appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/odlconnector/NetconfClientRestconfImpl.java55
-rw-r--r--appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/NetconfClientFactoryTest.java5
-rw-r--r--appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/NetconfClientTypeTest.java4
-rw-r--r--appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/NetconfConnectionDetailsTest.java20
-rw-r--r--appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/odlconnector/NetconfClientRestconfImplTest.java203
6 files changed, 261 insertions, 38 deletions
diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java
index ce29451d1..70a202865 100644
--- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java
+++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -119,11 +121,11 @@ public class NetconfDataAccessServiceImpl implements NetconfDataAccessService {
@Override
public boolean logDeviceInteraction(String instanceId, String requestId, String creationDate, String logText) {
- String queryString = "INSERT INTO "+ Constants.DEVICE_INTERFACE_LOG_TABLE_NAME+"("+
- Constants.SERVICE_INSTANCE_ID_FIELD_NAME+","+
- Constants.REQUEST_ID_FIELD_NAME+","+
- Constants.CREATION_DATE_FIELD_NAME+","+
- Constants.LOG_FIELD_NAME+") ";
+ String queryString = "INSERT INTO " + Constants.DEVICE_INTERFACE_LOG_TABLE_NAME + "(" +
+ Constants.SERVICE_INSTANCE_ID_FIELD_NAME + "," +
+ Constants.REQUEST_ID_FIELD_NAME + "," +
+ Constants.CREATION_DATE_FIELD_NAME + "," +
+ Constants.LOG_FIELD_NAME + ") ";
queryString += "values(?,?,?,?)";
ArrayList<String> argList = new ArrayList<>();
diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/odlconnector/NetconfClientRestconfImpl.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/odlconnector/NetconfClientRestconfImpl.java
index 4e9ef913b..beb14e359 100644
--- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/odlconnector/NetconfClientRestconfImpl.java
+++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/odlconnector/NetconfClientRestconfImpl.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,59 +53,66 @@ public class NetconfClientRestconfImpl implements NetconfClient, NetconfClientRe
@Override
public void configure(String configuration, String deviceMountPointName, String moduleName, String nodeName) throws APPCException {
- logger.info("Configuring device "+deviceMountPointName+" with configuration "+configuration);
+ logger.info("Configuring device " + deviceMountPointName + " with configuration " + configuration);
- int httpCode = httpClient.putMethod(Constants.PROTOCOL,Constants.CONTROLLER_IP,Constants.CONTROLLER_PORT,getModuleConfigurePath(deviceMountPointName, moduleName, nodeName),configuration,"application/json");
+ int httpCode = httpClient.putMethod(Constants.PROTOCOL,Constants.CONTROLLER_IP,Constants.CONTROLLER_PORT,
+ getModuleConfigurePath(deviceMountPointName, moduleName, nodeName), configuration, "application/json");
if (httpCode != HttpStatus.SC_OK) {
logger.error("Configuration request failed. throwing Exception !");
- throw new APPCException("Error configuring node :"+nodeName + ", of Module :" + moduleName + ", in device :" + deviceMountPointName);
+ throw new APPCException("Error configuring node :" + nodeName + ", of Module :" + moduleName +
+ ", in device :" + deviceMountPointName);
}
}
@Override
public void connect(String deviceMountPointName, String payload) throws APPCException{
- logger.info("Connecting device "+deviceMountPointName);
+ logger.info("Connecting device " + deviceMountPointName);
- int httpCode = httpClient.postMethod(Constants.PROTOCOL,Constants.CONTROLLER_IP,Constants.CONTROLLER_PORT,getConnectPath(),payload,"application/json");
+ int httpCode = httpClient.postMethod(Constants.PROTOCOL, Constants.CONTROLLER_IP, Constants.CONTROLLER_PORT,
+ getConnectPath(), payload, "application/json");
if(httpCode != HttpStatus.SC_NO_CONTENT){
- logger.error("Connect request failed with code "+httpCode+". throwing Exception !");
+ logger.error("Connect request failed with code " + httpCode + ". throwing Exception !");
throw new APPCException("Error connecting device :" + deviceMountPointName);
}
}
@Override
public boolean checkConnection(String deviceMountPointName) throws APPCException {
- logger.info("Checking device "+deviceMountPointName+" connectivity");
+ logger.info("Checking device " + deviceMountPointName + " connectivity");
- String result = httpClient.getMethod(Constants.PROTOCOL,Constants.CONTROLLER_IP,Constants.CONTROLLER_PORT,getCheckConnectivityPath(deviceMountPointName),"application/json");
+ String result = httpClient.getMethod(Constants.PROTOCOL, Constants.CONTROLLER_IP,
+ Constants.CONTROLLER_PORT, getCheckConnectivityPath(deviceMountPointName), "application/json");
return result != null;
}
@Override
public void disconnect(String deviceMountPointName) throws APPCException {
- logger.info("Disconnecting "+deviceMountPointName);
+ logger.info("Disconnecting " + deviceMountPointName);
- int httpCode = httpClient.deleteMethod(Constants.PROTOCOL,Constants.CONTROLLER_IP,Constants.CONTROLLER_PORT,getDisconnectPath(deviceMountPointName),"application/json");
+ int httpCode = httpClient.deleteMethod(Constants.PROTOCOL, Constants.CONTROLLER_IP, Constants.CONTROLLER_PORT,
+ getDisconnectPath(deviceMountPointName), "application/json");
if(httpCode != HttpStatus.SC_OK){
- logger.error("Disconnection of device "+deviceMountPointName+" failed!");
- throw new APPCException("Disconnection of device "+deviceMountPointName+" failed!");
+ logger.error("Disconnection of device " + deviceMountPointName + " failed!");
+ throw new APPCException("Disconnection of device " + deviceMountPointName + " failed!");
}
}
@Override
public String getConfiguration(String deviceMountPointName, String moduleName, String nodeName) throws APPCException{
- logger.info("Getting configuration of device "+deviceMountPointName);
+ logger.info("Getting configuration of device " + deviceMountPointName);
- String result = httpClient.getMethod(Constants.PROTOCOL,Constants.CONTROLLER_IP,Constants.CONTROLLER_PORT,getModuleConfigurePath(deviceMountPointName, moduleName, nodeName),"application/json");
+ String result = httpClient.getMethod(Constants.PROTOCOL, Constants.CONTROLLER_IP, Constants.CONTROLLER_PORT,
+ getModuleConfigurePath(deviceMountPointName, moduleName, nodeName), "application/json");
if (result == null) {
logger.error("Configuration request failed. throwing Exception !");
- throw new APPCException("Error getting configuration of node :"+nodeName + ", of Module :" + moduleName + ", in device :" + deviceMountPointName);
+ throw new APPCException("Error getting configuration of node :" + nodeName + ", of Module :" + moduleName +
+ ", in device :" + deviceMountPointName);
}
return result;
@@ -117,7 +126,7 @@ public class NetconfClientRestconfImpl implements NetconfClient, NetconfClientRe
throw new APPCException("Invalid connection details - null value");
}
this.connectionDetails = connectionDetails;
- this.connect(connectionDetails.getHost(),getPayload());
+ this.connect(connectionDetails.getHost(), getPayload());
}
@Override
@@ -133,7 +142,7 @@ public class NetconfClientRestconfImpl implements NetconfClient, NetconfClientRe
}
Properties props = connectionDetails.getAdditionalProperties();
- if(props == null || !props.containsKey("module.name") || !props.containsKey("node.name")){
+ if(props == null || !props.containsKey("module.name") || !props.containsKey("node.name")) {
throw new APPCException("Invalid properties!");
}
@@ -141,11 +150,13 @@ public class NetconfClientRestconfImpl implements NetconfClient, NetconfClientRe
String nodeName = props.getProperty("node.name");
String deviceMountPointName = connectionDetails.getHost();
- int httpCode = httpClient.putMethod(Constants.PROTOCOL,Constants.CONTROLLER_IP,Constants.CONTROLLER_PORT,getModuleConfigurePath(deviceMountPointName, moduleName, nodeName),configuration,"application/xml");
+ int httpCode = httpClient.putMethod(Constants.PROTOCOL, Constants.CONTROLLER_IP, Constants.CONTROLLER_PORT,
+ getModuleConfigurePath(deviceMountPointName, moduleName, nodeName), configuration, "application/xml");
if (httpCode != HttpStatus.SC_OK) {
logger.error("Configuration request failed. throwing Exception !");
- throw new APPCException("Error configuring node :"+nodeName + ", of Module :" + moduleName + ", in device :" + deviceMountPointName);
+ throw new APPCException("Error configuring node :" + nodeName + ", of Module :" + moduleName +
+ ", in device :" + deviceMountPointName);
}
}
@@ -156,11 +167,12 @@ public class NetconfClientRestconfImpl implements NetconfClient, NetconfClientRe
}
Properties props = connectionDetails.getAdditionalProperties();
- if(props == null || !props.containsKey("module.name") || !props.containsKey("node.name")){
+ if(props == null || !props.containsKey("module.name") || !props.containsKey("node.name")) {
throw new APPCException("Invalid properties!");
}
- return this.getConfiguration(connectionDetails.getHost(),props.getProperty("module.name"),props.getProperty("node.name"));
+ return this.getConfiguration(connectionDetails.getHost(), props.getProperty("module.name"),
+ props.getProperty("node.name"));
}
@Override
@@ -174,7 +186,6 @@ public class NetconfClientRestconfImpl implements NetconfClient, NetconfClientRe
//private methods
private String getModuleConfigurePath(String deviceMountPointName, String moduleName, String nodeName){
-
String deviceSpecificPath = deviceMountPointName + "/yang-ext:mount/" + moduleName + ":" + nodeName;
return Constants.CONFIGURE_PATH + deviceSpecificPath;
diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/NetconfClientFactoryTest.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/NetconfClientFactoryTest.java
index de6be9f88..0d9ba7619 100644
--- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/NetconfClientFactoryTest.java
+++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/NetconfClientFactoryTest.java
@@ -3,6 +3,8 @@
* ONAP : APPC
* ================================================================================
* Copyright (C) 2018 Nokia. All rights reserved.
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,8 +21,9 @@
*/
package org.onap.appc.adapter.netconf;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.onap.appc.adapter.netconf.jsch.NetconfClientJsch;
import org.onap.appc.adapter.netconf.odlconnector.NetconfClientRestconfImpl;
diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/NetconfClientTypeTest.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/NetconfClientTypeTest.java
index 7715e2973..f81d4a487 100644
--- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/NetconfClientTypeTest.java
+++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/NetconfClientTypeTest.java
@@ -3,6 +3,8 @@
* ONAP : APPC
* ================================================================================
* Copyright 2018 TechMahindra
+* ================================================================================
+* Modifications Copyright (C) 2019 Ericsson
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +25,7 @@ import org.junit.Assert;
import org.junit.Test;
public class NetconfClientTypeTest {
- private NetconfClientType netconfClientType=NetconfClientType.RESTCONF;
+ private NetconfClientType netconfClientType = NetconfClientType.RESTCONF;
@Test
public void testName() {
diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/NetconfConnectionDetailsTest.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/NetconfConnectionDetailsTest.java
index c36cc3f90..43b17abb4 100644
--- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/NetconfConnectionDetailsTest.java
+++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/NetconfConnectionDetailsTest.java
@@ -3,6 +3,8 @@
* ONAP : APPC
* ================================================================================
* Copyright 2018 TechMahindra
+* ================================================================================
+* Modifications Copyright (C) 2019 Ericsson
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,7 +36,7 @@ public class NetconfConnectionDetailsTest {
@Before
public void SetUp() {
- netconfConnectionDetails=new NetconfConnectionDetails();
+ netconfConnectionDetails = new NetconfConnectionDetails();
}
@Test
@@ -67,13 +69,13 @@ public class NetconfConnectionDetailsTest {
@Test
public void testNullCapabilities() {
- capabilities=new ArrayList<String>();
+ capabilities = new ArrayList<String>();
Assert.assertNull(netconfConnectionDetails.getCapabilities());
}
@Test
public void testCapabilitiesWithValues() {
- capabilities=new ArrayList<String>();
+ capabilities = new ArrayList<String>();
capabilities.add("capabilities1");
capabilities.add("capabilities2");
netconfConnectionDetails.setCapabilities(capabilities);
@@ -82,7 +84,7 @@ public class NetconfConnectionDetailsTest {
@Test
public void testCapabilities_Size() {
- capabilities=new ArrayList<String>();
+ capabilities = new ArrayList<String>();
capabilities.add("capabilities1");
capabilities.add("capabilities2");
netconfConnectionDetails.setCapabilities(capabilities);
@@ -91,27 +93,27 @@ public class NetconfConnectionDetailsTest {
@Test
public void testAdditionalProperties() {
- additionalProperties=new Properties();
+ additionalProperties = new Properties();
Assert.assertNull(netconfConnectionDetails.getAdditionalProperties());
}
@Test
public void testAdditionalPropertiesWithValues() {
- additionalProperties=new Properties();
+ additionalProperties = new Properties();
additionalProperties.put("A", "a");
additionalProperties.put("B", "b");
netconfConnectionDetails.setAdditionalProperties(additionalProperties);
- Assert.assertEquals("a",netconfConnectionDetails.getAdditionalProperties().get("A"));
+ Assert.assertEquals("a", netconfConnectionDetails.getAdditionalProperties().get("A"));
}
@Test
public void testAdditionalProperties_Size() {
- additionalProperties=new Properties();
+ additionalProperties = new Properties();
additionalProperties.put("A", "a");
additionalProperties.put("B", "b");
additionalProperties.put("C", "c");
netconfConnectionDetails.setAdditionalProperties(additionalProperties);
Assert.assertNotNull(netconfConnectionDetails.getAdditionalProperties());
- Assert.assertEquals(3,additionalProperties.size());
+ Assert.assertEquals(3, additionalProperties.size());
}
}
diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/odlconnector/NetconfClientRestconfImplTest.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/odlconnector/NetconfClientRestconfImplTest.java
new file mode 100644
index 000000000..04d2befa6
--- /dev/null
+++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/odlconnector/NetconfClientRestconfImplTest.java
@@ -0,0 +1,203 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Ericsson
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.adapter.netconf.odlconnector;
+
+import static org.junit.Assert.assertEquals;
+import java.util.Properties;
+import org.apache.http.HttpStatus;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.util.httpClient;
+import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
+import org.onap.appc.adapter.netconf.util.Constants;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.Whitebox;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(httpClient.class)
+public class NetconfClientRestconfImplTest {
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ @Before
+ public void setup() {
+ PowerMockito.mockStatic(httpClient.class);
+ }
+ @Test
+ public void testConfigureNullDetails() throws APPCException {
+ NetconfClientRestconfImpl client = new NetconfClientRestconfImpl();
+ expectedEx.expect(APPCException.class);
+ expectedEx.expectMessage("Invalid connection details - null value");
+ client.configure(null);
+ }
+
+ @Test
+ public void testConfigureNullProperties() throws APPCException {
+ NetconfClientRestconfImpl client = Mockito.spy(new NetconfClientRestconfImpl());
+ expectedEx.expect(APPCException.class);
+ expectedEx.expectMessage("Invalid properties!");
+ Whitebox.setInternalState(client, "connectionDetails", Mockito.mock(NetconfConnectionDetails.class));
+ client.configure(null);
+ }
+
+ @Test
+ public void testConfigureWithError() throws APPCException {
+ PowerMockito.when(httpClient.putMethod(Constants.PROTOCOL, Constants.CONTROLLER_IP, Constants.CONTROLLER_PORT,
+ Constants.CONFIGURE_PATH + "null/yang-ext:mount/MODULE_NAME:NODE_NAME", null, "application/xml"))
+ .thenReturn(HttpStatus.SC_ACCEPTED);
+ NetconfClientRestconfImpl client = Mockito.spy(new NetconfClientRestconfImpl());
+ NetconfConnectionDetails details = new NetconfConnectionDetails();
+ Properties properties = new Properties();
+ properties.setProperty("module.name", "MODULE_NAME");
+ properties.setProperty("node.name", "NODE_NAME");
+ details.setAdditionalProperties(properties);
+ Whitebox.setInternalState(client, "connectionDetails", details);
+ expectedEx.expect(APPCException.class);
+ expectedEx.expectMessage("Error configuring node :NODE_NAME, of Module :MODULE_NAME, in device :null");
+ client.configure(null);
+ }
+
+ @Test
+ public void testConfigure4ArgWithError() throws APPCException {
+ PowerMockito.when(httpClient.putMethod(Constants.PROTOCOL, Constants.CONTROLLER_IP, Constants.CONTROLLER_PORT,
+ Constants.CONFIGURE_PATH + "null/yang-ext:mount/MODULE_NAME:NODE_NAME", null, "application/xml"))
+ .thenReturn(HttpStatus.SC_ACCEPTED);
+ NetconfClientRestconfImpl client = Mockito.spy(new NetconfClientRestconfImpl());
+ expectedEx.expect(APPCException.class);
+ expectedEx.expectMessage("Error configuring node :NODE_NAME, of Module :MODULE_NAME, in device :null");
+ client.configure(null, null, "MODULE_NAME", "NODE_NAME");
+ }
+
+ @Test
+ public void testConnect() throws APPCException {
+ PowerMockito.when(httpClient.putMethod(Constants.PROTOCOL, Constants.CONTROLLER_IP, Constants.CONTROLLER_PORT,
+ Constants.CONFIGURE_PATH + "null/yang-ext:mount/MODULE_NAME:NODE_NAME", null, "application/xml"))
+ .thenReturn(HttpStatus.SC_ACCEPTED);
+ NetconfClientRestconfImpl client = Mockito.spy(new NetconfClientRestconfImpl());
+ NetconfConnectionDetails details = new NetconfConnectionDetails();
+ Properties properties = new Properties();
+ properties.setProperty("module.name", "MODULE_NAME");
+ properties.setProperty("node.name", "NODE_NAME");
+ details.setAdditionalProperties(properties);
+ Whitebox.setInternalState(client, "connectionDetails", details);
+ expectedEx.expect(APPCException.class);
+ expectedEx.expectMessage("Error connecting device :null");
+ client.connect(details);
+ }
+
+ @Test
+ public void testConnectWithNullDetails() throws APPCException {
+ PowerMockito.when(httpClient.putMethod(Constants.PROTOCOL, Constants.CONTROLLER_IP, Constants.CONTROLLER_PORT,
+ Constants.CONFIGURE_PATH + "null/yang-ext:mount/MODULE_NAME:NODE_NAME", null, "application/xml"))
+ .thenReturn(HttpStatus.SC_ACCEPTED);
+ NetconfClientRestconfImpl client = Mockito.spy(new NetconfClientRestconfImpl());
+ expectedEx.expect(APPCException.class);
+ expectedEx.expectMessage("Invalid connection details - null value");
+ client.connect(null);
+ }
+
+ @Test
+ public void testDisconnectNullDetails() throws APPCException {
+ NetconfClientRestconfImpl client = Mockito.spy(new NetconfClientRestconfImpl());
+ expectedEx.expect(APPCException.class);
+ expectedEx.expectMessage("Invalid connection details - null value");
+ client.disconnect();
+ }
+
+ @Test
+ public void testDisconnect() throws APPCException {
+ NetconfClientRestconfImpl client = Mockito.spy(new NetconfClientRestconfImpl());
+ NetconfConnectionDetails details = new NetconfConnectionDetails();
+ Properties properties = new Properties();
+ properties.setProperty("module.name", "MODULE_NAME");
+ properties.setProperty("node.name", "NODE_NAME");
+ details.setAdditionalProperties(properties);
+ Whitebox.setInternalState(client, "connectionDetails", details);
+ expectedEx.expect(APPCException.class);
+ expectedEx.expectMessage("Disconnection of device null failed!");
+ client.disconnect();
+ }
+
+ @Test
+ public void testGetConfigurationNullDetails() throws APPCException {
+ NetconfClientRestconfImpl client = Mockito.spy(new NetconfClientRestconfImpl());
+ expectedEx.expect(APPCException.class);
+ expectedEx.expectMessage("Invalid connection details - null value");
+ client.getConfiguration();
+ }
+
+ @Test
+ public void testGetConfigurationNullProperties() throws APPCException {
+ NetconfClientRestconfImpl client = Mockito.spy(new NetconfClientRestconfImpl());
+ expectedEx.expect(APPCException.class);
+ expectedEx.expectMessage("Invalid properties!");
+ Whitebox.setInternalState(client, "connectionDetails", Mockito.mock(NetconfConnectionDetails.class));
+ client.getConfiguration();
+ }
+
+ @Test
+ public void testGetConfigurationWithError() throws APPCException {
+ PowerMockito.when(httpClient.putMethod(Constants.PROTOCOL, Constants.CONTROLLER_IP, Constants.CONTROLLER_PORT,
+ Constants.CONFIGURE_PATH + "null/yang-ext:mount/MODULE_NAME:NODE_NAME", null, "application/xml"))
+ .thenReturn(HttpStatus.SC_ACCEPTED);
+ NetconfClientRestconfImpl client = Mockito.spy(new NetconfClientRestconfImpl());
+ NetconfConnectionDetails details = new NetconfConnectionDetails();
+ Properties properties = new Properties();
+ properties.setProperty("module.name", "MODULE_NAME");
+ properties.setProperty("node.name", "NODE_NAME");
+ details.setAdditionalProperties(properties);
+ Whitebox.setInternalState(client, "connectionDetails", details);
+ expectedEx.expect(APPCException.class);
+ expectedEx.expectMessage("Error getting configuration of node :NODE_NAME, of Module :MODULE_NAME, in device :null");
+ client.getConfiguration();
+ }
+
+ @Test
+ public void testGetConfigurationSuccess() throws APPCException {
+ PowerMockito.when(httpClient.getMethod(Constants.PROTOCOL, Constants.CONTROLLER_IP, Constants.CONTROLLER_PORT,
+ Constants.CONFIGURE_PATH + "null/yang-ext:mount/MODULE_NAME:NODE_NAME", "application/json"))
+ .thenReturn("TEST");
+ NetconfClientRestconfImpl client = Mockito.spy(new NetconfClientRestconfImpl());
+ NetconfConnectionDetails details = new NetconfConnectionDetails();
+ Properties properties = new Properties();
+ properties.setProperty("module.name", "MODULE_NAME");
+ properties.setProperty("node.name", "NODE_NAME");
+ details.setAdditionalProperties(properties);
+ Whitebox.setInternalState(client, "connectionDetails", details);
+ assertEquals("TEST", client.getConfiguration());
+ }
+
+ @Test
+ public void testCheckConnection() throws APPCException {
+ NetconfClientRestconfImpl client = new NetconfClientRestconfImpl();
+ assertEquals(false, client.checkConnection(null));
+
+ }
+}