summaryrefslogtreecommitdiffstats
path: root/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java')
-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
4 files changed, 221 insertions, 11 deletions
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));
+
+ }
+}