summaryrefslogtreecommitdiffstats
path: root/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test
diff options
context:
space:
mode:
authorSingal, Kapil (ks220y) <ks220y@att.com>2021-04-26 13:41:57 -0400
committerKAPIL SINGAL <ks220y@att.com>2021-04-27 14:30:34 +0000
commit7b25afd7fbb945686f5444e05e5e15716052b027 (patch)
tree98be595154b40b9cd07776800f6ea8a5020e1e86 /adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test
parent70ac2b906e4e80f817185542a649f188fc9178b0 (diff)
Moving Netconf-adaptor from APPC to CCSDK SLI
Issue-ID: CCSDK-3198 Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com> Change-Id: I638d57729d100211325f4e3121970d6737b9a50c
Diffstat (limited to 'adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test')
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/NetconfClientFactoryTest.java50
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/NetconfClientTypeTest.java41
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/NetconfConnectionDetailsTest.java118
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/OperationalStateValidatorTest.java200
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/TestConnectionDetails.java46
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/TestVnfType.java42
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/VNFOperationalStateValidatorImplTest.java51
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/exception/DataAccessExceptionTest.java64
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/exception/NetconfDAOExceptionTest.java64
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/internal/TestNetconfAdaptor.java88
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/internal/TestNetconfAdaptor2.java103
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/internal/TestNetconfDataAccessServiceImpl.java139
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestGetRunningConfig.java59
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestJSchLogger.java55
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestModifyConfig.java92
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestModifyConfigMock.java92
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestModifyConfigRouterMock.java90
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestNetconfClientJsch.java191
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestOperationalStates.java86
-rw-r--r--adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/odlconnector/NetconfClientRestconfImplTest.java207
20 files changed, 1878 insertions, 0 deletions
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/NetconfClientFactoryTest.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/NetconfClientFactoryTest.java
new file mode 100644
index 000000000..b3a1d8edb
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/NetconfClientFactoryTest.java
@@ -0,0 +1,50 @@
+/*
+ * ============LICENSE_START=======================================================
+ * 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.
+ * 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.ccsdk.sli.adaptors.netconf;
+
+import org.junit.Test;
+import org.onap.ccsdk.sli.adaptors.netconf.jsch.NetconfClientJsch;
+import org.onap.ccsdk.sli.adaptors.netconf.odlconnector.NetconfClientRestconfImpl;
+
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+public class NetconfClientFactoryTest {
+
+ @Test
+ public void getNetconfClient_shouldCreateRestClient_forRestClientType() {
+ NetconfClient netconfClient = new NetconfClientFactory().getNetconfClient(NetconfClientType.RESTCONF);
+ assertTrue(netconfClient instanceof NetconfClientRestconfImpl);
+ }
+
+ @Test
+ public void getNetconfClient_shouldCreateJschClient_forSshClientType() {
+ NetconfClient netconfClient = new NetconfClientFactory().getNetconfClient(NetconfClientType.SSH);
+ assertTrue(netconfClient instanceof NetconfClientJsch);
+ }
+
+ @Test
+ public void getNetconfClient_shouldReturnNullForInvalidClientType() {
+ NetconfClient netconfClient = new NetconfClientFactory().getNetconfClient(null);
+ assertNull(netconfClient);
+ }
+} \ No newline at end of file
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/NetconfClientTypeTest.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/NetconfClientTypeTest.java
new file mode 100644
index 000000000..cd862f9d9
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/NetconfClientTypeTest.java
@@ -0,0 +1,41 @@
+/*
+* ============LICENSE_START=======================================================
+* 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.
+* 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.ccsdk.sli.adaptors.netconf;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class NetconfClientTypeTest {
+ private NetconfClientType netconfClientType = NetconfClientType.RESTCONF;
+
+ @Test
+ public void testName() {
+ Assert.assertEquals("RESTCONF", netconfClientType.name());
+ }
+
+ @Test
+ public void testEquals() {
+ Assert.assertTrue(netconfClientType.equals(NetconfClientType.RESTCONF));
+ Assert.assertFalse(netconfClientType.equals(null));
+ }
+
+}
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/NetconfConnectionDetailsTest.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/NetconfConnectionDetailsTest.java
new file mode 100644
index 000000000..2d0bea92c
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/NetconfConnectionDetailsTest.java
@@ -0,0 +1,118 @@
+/*
+* ============LICENSE_START=======================================================
+* 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.
+* 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.ccsdk.sli.adaptors.netconf;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class NetconfConnectionDetailsTest {
+ private NetconfConnectionDetails netconfConnectionDetails;
+ private List<String> capabilities;
+ private Properties additionalProperties;
+
+ @Before
+ public void SetUp() {
+ netconfConnectionDetails = new NetconfConnectionDetails();
+ }
+
+ @Test
+ public void testGetHost() {
+ netconfConnectionDetails.setHost("host1");
+ Assert.assertNotNull(netconfConnectionDetails.getHost());
+ Assert.assertEquals("host1", netconfConnectionDetails.getHost());
+ }
+
+ @Test
+ public void testGetPort() {
+ netconfConnectionDetails.setPort(123);
+ Assert.assertNotNull(netconfConnectionDetails.getPort());
+ Assert.assertEquals(123, netconfConnectionDetails.getPort());
+ }
+
+ @Test
+ public void testGetUsername() {
+ netconfConnectionDetails.setUsername("ABC");
+ Assert.assertNotNull(netconfConnectionDetails.getUsername());
+ Assert.assertEquals("ABC", netconfConnectionDetails.getUsername());
+ }
+
+ @Test
+ public void testGetPassword() {
+ netconfConnectionDetails.setPassword("pass1");
+ Assert.assertNotNull(netconfConnectionDetails.getPassword());
+ Assert.assertEquals("pass1", netconfConnectionDetails.getPassword());
+ }
+
+ @Test
+ public void testNullCapabilities() {
+ capabilities = new ArrayList<String>();
+ Assert.assertNull(netconfConnectionDetails.getCapabilities());
+ }
+
+ @Test
+ public void testCapabilitiesWithValues() {
+ capabilities = new ArrayList<String>();
+ capabilities.add("capabilities1");
+ capabilities.add("capabilities2");
+ netconfConnectionDetails.setCapabilities(capabilities);
+ Assert.assertTrue(capabilities.contains("capabilities2"));
+ }
+
+ @Test
+ public void testCapabilities_Size() {
+ capabilities = new ArrayList<String>();
+ capabilities.add("capabilities1");
+ capabilities.add("capabilities2");
+ netconfConnectionDetails.setCapabilities(capabilities);
+ Assert.assertEquals(2, capabilities.size());
+ }
+
+ @Test
+ public void testAdditionalProperties() {
+ additionalProperties = new Properties();
+ Assert.assertNull(netconfConnectionDetails.getAdditionalProperties());
+ }
+
+ @Test
+ public void testAdditionalPropertiesWithValues() {
+ additionalProperties = new Properties();
+ additionalProperties.put("A", "a");
+ additionalProperties.put("B", "b");
+ netconfConnectionDetails.setAdditionalProperties(additionalProperties);
+ Assert.assertEquals("a", netconfConnectionDetails.getAdditionalProperties().get("A"));
+ }
+
+ @Test
+ public void testAdditionalProperties_Size() {
+ 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());
+ }
+}
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/OperationalStateValidatorTest.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/OperationalStateValidatorTest.java
new file mode 100644
index 000000000..8b60373b1
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/OperationalStateValidatorTest.java
@@ -0,0 +1,200 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * 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.
+ * 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.ccsdk.sli.adaptors.netconf;
+
+import org.junit.Test;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+
+public class OperationalStateValidatorTest {
+
+ @Test
+ public void testVNFValidResponse() {
+ String validResponse = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"101\">\n" +
+ " <data>\n" +
+ " <ManagedElement xmlns=\"urn:org:onap:appc:Test\">\n" +
+ " <managedElementId>1</managedElementId>\n" +
+ " <VnfFunction xmlns=\"urn:org:onap:appc:Test\">\n" +
+ " <id>1</id>\n" +
+ " <ProcessorManagement>\n" +
+ " <id>1</id>\n" +
+ " <MatedPair>\n" +
+ " <id>1</id>\n" +
+ " <operationalState>ENABLED</operationalState>\n" +
+ " <PayloadProcessor>\n" +
+ " <id>processor_0_5</id>\n" +
+ " <operationalState>ENABLED</operationalState>\n" +
+ " </PayloadProcessor>\n" +
+ " <PayloadProcessor>\n" +
+ " <id>processor_0_7</id>\n" +
+ " <operationalState>ENABLED</operationalState>\n" +
+ " </PayloadProcessor>\n" +
+ " </MatedPair>\n" +
+ " <SystemController>\n" +
+ " <id>SC-1</id>\n" +
+ " <operationalState>ENABLED</operationalState>\n" +
+ " </SystemController>\n" +
+ " <SystemController>\n" +
+ " <id>SC-2</id>\n" +
+ " <operationalState>ENABLED</operationalState>\n" +
+ " </SystemController>\n" +
+ " </ProcessorManagement>\n" +
+ " </VnfFunction>\n" +
+ " </ManagedElement>\n" +
+ " </data>\n" +
+ "</rpc-reply>";
+ OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(VnfType.VNF);
+ assertValidResponse(validResponse, operationalStateValidator);
+ }
+
+ void assertInvalidResponse(String response, OperationalStateValidator operationalStateValidator) {
+ try {
+ operationalStateValidator.validateResponse(response);
+ fail("invalid response passed without exception!!!");
+ } catch (SvcLogicException e) {
+ assertNotNull(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testVNFInvalidResponses() {
+
+ OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(VnfType.VNF);
+ assertInvalidResponse(null, operationalStateValidator);
+
+ assertInvalidResponse("", operationalStateValidator);
+
+ String response = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
+ assertInvalidResponse(response, operationalStateValidator);
+
+ response = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"101\">\n" +
+ "</rpc-reply>";
+ assertInvalidResponse(response, operationalStateValidator);
+
+ response = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"101\">\n" +
+ " <data>\n" +
+ " <ManagedElement xmlns=\"urn:org:onap:appc:Test\">\n" +
+ " <managedElementId>1</managedElementId>\n" +
+ " <VnfFunction xmlns=\"urn:org:onap:appc:Test\">\n" +
+ " <id>1</id>\n" +
+ " <ProcessorManagement>\n" +
+ " <id>1</id>\n" +
+ " <MatedPair>\n" +
+ " <id>1</id>\n" +
+ " <operationalState>ENABLED</operationalState>\n" +
+ " <PayloadProcessor>\n" +
+ " <id>processor_0_5</id>\n" +
+ " <operationalState>ENABLED</operationalState>\n" +
+ " </PayloadProcessor>\n" +
+ " <PayloadProcessor>\n" +
+ " <id>processor_0_7</id>\n" +
+ " <operationalState>ENABLED</operationalState>\n" +
+ " </PayloadProcessor>\n" +
+ " </MatedPair>\n" +
+ " <SystemController>\n" +
+ " <id>SC-1</id>\n" +
+ " <operationalState>ENABLED</operationalState>\n" +
+ " </SystemController>\n" +
+ " <SystemController>\n" +
+ " <id>SC-2</id>\n" +
+ " <operationalState></operationalState>\n" +
+ " </SystemController>\n" +
+ " </ProcessorManagement>\n" +
+ " </VnfFunction>\n" +
+ " </ManagedElement>\n" +
+ " </data>\n" +
+ "</rpc-reply>";
+ assertInvalidResponse(response, operationalStateValidator);
+ }
+
+ void assertValidResponse(String response, OperationalStateValidator operationalStateValidator) {
+ try {
+ operationalStateValidator.validateResponse(response);
+ } catch (SvcLogicException e) {
+ fail("Got unexpected exception. Validation failed. " + e.getMessage());
+ }
+ }
+
+ @Test
+ public void testMockValidResponse() {
+ String response = "valid";
+ OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator("mock");
+ assertValidResponse(response, operationalStateValidator);
+
+ response = "";
+ assertValidResponse(response, operationalStateValidator);
+
+ response = null;
+ assertValidResponse(response, operationalStateValidator);
+ }
+
+ @Test
+ public void testMockInValidResponse() {
+ String response = "anything InValid anything.. ";
+ OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(VnfType.MOCK);
+ assertInvalidResponse(response, operationalStateValidator);
+ }
+
+ @Test
+ public void testGetOperationalStateValidatorForInValidVnfType() {
+ try{
+ OperationalStateValidatorFactory.getOperationalStateValidator("wrongVnfType");
+ fail("invalid vnfType without exception!!!");
+ } catch (Exception e) {
+ assertNotNull(e.getMessage());
+ }
+ }
+
+ @Test
+ public void testGetOperationalStateValidatorForValidVnfType() {
+ String vnfType = VnfType.VNF.name().toLowerCase();
+ assertGettingValidatorForValidVnf(vnfType);
+
+ vnfType = VnfType.VNF.name().toUpperCase();
+ assertGettingValidatorForValidVnf(vnfType);
+
+ vnfType = VnfType.MOCK.name().toLowerCase();
+ assertGettingValidatorForValidVnf(vnfType);
+
+ vnfType = VnfType.MOCK.name().toUpperCase();
+ assertGettingValidatorForValidVnf(vnfType);
+ }
+
+ void assertGettingValidatorForValidVnf(String vnfType) {
+ try{
+ OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(vnfType);
+ assertNotNull(operationalStateValidator);
+ } catch (Exception e) {
+ fail("valid vnfType throw exception!!!");
+ }
+ }
+}
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/TestConnectionDetails.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/TestConnectionDetails.java
new file mode 100644
index 000000000..9720732bf
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/TestConnectionDetails.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.ccsdk.sli.adaptors.netconf;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestConnectionDetails {
+
+ @Test
+ public void testGetSetMethods() {
+ ConnectionDetails connectionDetails = new ConnectionDetails();
+ connectionDetails.setHost("host1");
+ assertEquals("host1", connectionDetails.getHost());
+
+ connectionDetails.setPort(123);
+ assertEquals(123, connectionDetails.getPort());
+
+ connectionDetails.setUsername("myname");
+ assertEquals("myname", connectionDetails.getUsername());
+
+ connectionDetails.setPassword("mypassword");
+ assertEquals("mypassword", connectionDetails.getPassword());
+ }
+
+}
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/TestVnfType.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/TestVnfType.java
new file mode 100644
index 000000000..7c6373046
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/TestVnfType.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 IBM.
+ * ================================================================================
+ * 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.ccsdk.sli.adaptors.netconf;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestVnfType {
+ private VnfType vnfType;
+
+ @Before
+ public void setUp() {
+ vnfType = VnfType.VNF;
+ }
+
+ @Test
+ public void testGetFamilyType() {
+ assertEquals(VnfType.VNF, vnfType.getFamilyType());
+ }
+
+}
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/VNFOperationalStateValidatorImplTest.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/VNFOperationalStateValidatorImplTest.java
new file mode 100644
index 000000000..098118252
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/VNFOperationalStateValidatorImplTest.java
@@ -0,0 +1,51 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 IBM.
+ * ================================================================================
+ * 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.ccsdk.sli.adaptors.netconf;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class VNFOperationalStateValidatorImplTest {
+
+ private VNFOperationalStateValidatorImpl vnfOperationalStateValidatorImpl;
+
+ @Before
+ public void setUp()
+ {
+ vnfOperationalStateValidatorImpl= new VNFOperationalStateValidatorImpl();
+ }
+
+ @Test
+ public void testGetVnfType()
+ {
+ assertEquals(VnfType.VNF, vnfOperationalStateValidatorImpl.getVnfType());
+ }
+
+ @Test
+ public void testgetConfigurationFileName()
+ {
+ assertEquals("VnfGetOperationalStates", vnfOperationalStateValidatorImpl.getConfigurationFileName());
+ }
+
+}
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/exception/DataAccessExceptionTest.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/exception/DataAccessExceptionTest.java
new file mode 100644
index 000000000..45fecf4f7
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/exception/DataAccessExceptionTest.java
@@ -0,0 +1,64 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : APPC
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* 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.ccsdk.sli.adaptors.netconf.exception;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DataAccessExceptionTest {
+
+ @Test
+ public void testConstructorNoArgument() throws Exception {
+ DataAccessException dataAccessException = new DataAccessException();
+ Assert.assertTrue(dataAccessException.getCause() == null);
+ Assert.assertTrue(dataAccessException.getLocalizedMessage() == null);
+ Assert.assertTrue(dataAccessException.getMessage() == null);
+ }
+
+ @Test
+ public void testConstructorWithMessage() throws Exception {
+ String message = "testing message";
+ DataAccessException dataAccessException = new DataAccessException(message);
+ Assert.assertTrue(dataAccessException.getCause() == null);
+ Assert.assertEquals(message, dataAccessException.getLocalizedMessage());
+ Assert.assertEquals(message, dataAccessException.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithThrowable() throws Exception {
+ String message = "testing message";
+ Throwable throwable = new Throwable(message);
+ DataAccessException dataAccessException = new DataAccessException(throwable);
+ Assert.assertEquals(throwable, dataAccessException.getCause());
+ Assert.assertTrue(dataAccessException.getLocalizedMessage().contains(message));
+ Assert.assertTrue(dataAccessException.getMessage().contains(message));
+ }
+
+ @Test
+ public void testConstructorWithMessageAndThrowable() throws Exception {
+ String message = "testing message";
+ String tMessage = "throwable message";
+ Throwable throwable = new Throwable(tMessage);
+ DataAccessException dataAccessException = new DataAccessException(message, throwable);
+ Assert.assertEquals(throwable, dataAccessException.getCause());
+ Assert.assertTrue(dataAccessException.getLocalizedMessage().contains(message));
+ Assert.assertTrue(dataAccessException.getMessage().contains(message));
+ }
+}
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/exception/NetconfDAOExceptionTest.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/exception/NetconfDAOExceptionTest.java
new file mode 100644
index 000000000..70fb2eeb5
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/exception/NetconfDAOExceptionTest.java
@@ -0,0 +1,64 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : APPC
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* 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.ccsdk.sli.adaptors.netconf.exception;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class NetconfDAOExceptionTest {
+
+ @Test
+ public void testConstructorNoArgument() throws Exception {
+ NetconfDAOException netconfDAOException = new NetconfDAOException();
+ Assert.assertTrue(netconfDAOException.getCause() == null);
+ Assert.assertTrue(netconfDAOException.getLocalizedMessage() == null);
+ Assert.assertTrue(netconfDAOException.getMessage() == null);
+ }
+
+ @Test
+ public void testConstructorWithMessage() throws Exception {
+ String message = "testing message";
+ NetconfDAOException netconfDAOException = new NetconfDAOException(message);
+ Assert.assertTrue(netconfDAOException.getCause() == null);
+ Assert.assertEquals(message, netconfDAOException.getLocalizedMessage());
+ Assert.assertEquals(message, netconfDAOException.getMessage());
+ }
+
+ @Test
+ public void testConstructorWithThrowable() throws Exception {
+ String message = "testing message";
+ Throwable throwable = new Throwable(message);
+ NetconfDAOException netconfDAOException = new NetconfDAOException(throwable);
+ Assert.assertEquals(throwable, netconfDAOException.getCause());
+ Assert.assertTrue(netconfDAOException.getLocalizedMessage().contains(message));
+ Assert.assertTrue(netconfDAOException.getMessage().contains(message));
+ }
+
+ @Test
+ public void testConstructorWithMessageAndThrowable() throws Exception {
+ String message = "testing message";
+ String tMessage = "throwable message";
+ Throwable throwable = new Throwable(tMessage);
+ NetconfDAOException netconfDAOException = new NetconfDAOException(message, throwable);
+ Assert.assertEquals(throwable, netconfDAOException.getCause());
+ Assert.assertTrue(netconfDAOException.getLocalizedMessage().contains(message));
+ Assert.assertTrue(netconfDAOException.getMessage().contains(message));
+ }
+}
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/internal/TestNetconfAdaptor.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/internal/TestNetconfAdaptor.java
new file mode 100644
index 000000000..757d767dd
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/internal/TestNetconfAdaptor.java
@@ -0,0 +1,88 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.ccsdk.sli.adaptors.netconf.internal;
+
+import java.io.IOException;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestNetconfAdaptor {
+
+ private static final String EOM = "]]>]]>";
+
+ @Test
+ public void testReceiveMessage() throws IOException {
+ PipedOutputStream pos = new PipedOutputStream();
+ PipedInputStream is = new PipedInputStream(pos);
+
+ PipedInputStream pis = new PipedInputStream();
+ PipedOutputStream os = new PipedOutputStream(pis);
+
+ NetconfAdaptor netconfAdaptor = new NetconfAdaptor(is, os);
+
+ String request = "Hello, netconf!";
+ pos.write(request.getBytes());
+ pos.write(EOM.getBytes());
+ String response = netconfAdaptor.receiveMessage();
+ Assert.assertNotNull(response);
+ Assert.assertEquals(request, response.trim());
+ }
+
+ @Test
+ public void testSendMessage() throws IOException {
+ PipedOutputStream pos = new PipedOutputStream();
+ PipedInputStream is = new PipedInputStream(pos);
+
+ PipedInputStream pis = new PipedInputStream();
+ PipedOutputStream os = new PipedOutputStream(pis);
+
+ NetconfAdaptor netconfAdaptor = new NetconfAdaptor(is, os);
+
+ String request = "Hello, netconf!";
+ netconfAdaptor.sendMessage(request);
+ byte[] bytes = new byte[request.length()+EOM.length()+2];
+ int count = pis.read(bytes);
+ String response = new String(bytes, 0, count);
+ Assert.assertNotNull(response);
+ Assert.assertTrue(response.endsWith(EOM));
+ response = response.substring(0, response.length() - EOM.length()).trim();
+ Assert.assertEquals(request, response);
+ }
+
+ @Test
+ public void testSendReceive() throws IOException {
+ PipedOutputStream os = new PipedOutputStream();
+ PipedInputStream is = new PipedInputStream(os);
+
+ NetconfAdaptor netconfAdaptor = new NetconfAdaptor(is, os);
+
+ String request = "Hello, netconf!";
+ netconfAdaptor.sendMessage(request);
+ String response = netconfAdaptor.receiveMessage();
+ Assert.assertNotNull(response);
+ Assert.assertEquals(request, response.trim());
+ }
+}
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/internal/TestNetconfAdaptor2.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/internal/TestNetconfAdaptor2.java
new file mode 100644
index 000000000..b276a0875
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/internal/TestNetconfAdaptor2.java
@@ -0,0 +1,103 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Samsung
+ * ================================================================================
+ * 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.ccsdk.sli.adaptors.netconf.internal;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestNetconfAdaptor2 {
+
+ private static final String EOM = "]]>]]>";
+
+ @Test (expected = IOException.class)
+ public void testReceiveMessage() throws IOException {
+ PipedOutputStream pos = new PipedOutputStream();
+ PipedInputStream is = new PipedInputStream(pos);
+
+ PipedInputStream pis = new PipedInputStream();
+ PipedOutputStream os = new PipedOutputStream(pis);
+
+ NetconfAdaptor2 netconfAdaptor = new NetconfAdaptor2(is, os);
+
+ String request = "Hello, netconf!";
+ pos.write(request.getBytes());
+ pos.write(EOM.getBytes());
+ String response = netconfAdaptor.receiveMessage();
+ Assert.assertNotNull(response);
+ Assert.assertEquals(request, response.trim());
+ }
+
+ @Test (expected = IOException.class)
+ public void testSendMessage() throws IOException {
+ PipedOutputStream pos = new PipedOutputStream();
+ PipedInputStream is = new PipedInputStream(pos);
+
+ PipedInputStream pis = new PipedInputStream();
+ PipedOutputStream os = new PipedOutputStream(pis);
+
+ NetconfAdaptor2 netconfAdaptor = new NetconfAdaptor2(is, os);
+
+ String request = "Hello, netconf!";
+ netconfAdaptor.sendMessage(request);
+ byte[] bytes = new byte[request.length()+EOM.length()+2];
+ int count = pis.read(bytes);
+ String response = new String(bytes, 0, count);
+ Assert.assertNotNull(response);
+ Assert.assertTrue(response.endsWith(EOM));
+ response = response.substring(0, response.length() - EOM.length()).trim();
+ Assert.assertEquals(request, response);
+ }
+
+ @Test (expected = IOException.class)
+ public void testSendReceive() throws IOException {
+ PipedOutputStream os = new PipedOutputStream();
+ PipedInputStream is = new PipedInputStream(os);
+
+ NetconfAdaptor2 netconfAdaptor = new NetconfAdaptor2(is, os);
+
+ String request = "Hello, netconf!";
+ netconfAdaptor.sendMessage(request);
+ String response = netconfAdaptor.receiveMessage();
+ Assert.assertNotNull(response);
+ Assert.assertEquals(request, response.trim());
+ }
+
+ @Test
+ public void testDefaultSendReceive() throws IOException {
+
+ NetconfAdaptor2 netconfAdaptor = new NetconfAdaptor2();
+
+ String request = "Hello, netconf!";
+ netconfAdaptor.sendMessage(request);
+
+ InputStream in = netconfAdaptor.getIn();
+ OutputStream out = netconfAdaptor.getOut();
+
+ Assert.assertNotNull(in);
+ Assert.assertNotNull(out);
+ }
+} \ No newline at end of file
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/internal/TestNetconfDataAccessServiceImpl.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/internal/TestNetconfDataAccessServiceImpl.java
new file mode 100644
index 000000000..0c5d49d2f
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/internal/TestNetconfDataAccessServiceImpl.java
@@ -0,0 +1,139 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Samsung
+ * ================================================================================
+ * 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.
+ * 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.ccsdk.sli.adaptors.netconf.internal;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.ArrayList;
+import java.util.logging.Logger;
+import javax.sql.rowset.CachedRowSet;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.ccsdk.sli.adaptors.netconf.NetconfAdaptorConstants;
+import org.onap.ccsdk.sli.adaptors.netconf.NetconfConnectionDetails;
+import org.onap.ccsdk.sli.core.dblib.DbLibService;
+
+public class TestNetconfDataAccessServiceImpl {
+ NetconfDataAccessServiceImpl netconfDataAccessService;
+ private String schema;
+ private DbLibService dbLibServiceMocked;
+
+ @Before
+ public void SetUp() {
+ schema = "test-netconf-adaptor";
+ dbLibServiceMocked = new DbLibService() {
+ @Override
+ public CachedRowSet getData(String s, ArrayList<String> arrayList, String s1) throws SQLException {
+ CachedRowSet cachedRowSetMocked = Mockito.mock(CachedRowSet.class);
+ Mockito.when(cachedRowSetMocked.first()).thenReturn(true);
+ Mockito.when(cachedRowSetMocked.getString(NetconfAdaptorConstants.FILE_CONTENT_TABLE_FIELD_NAME)).thenReturn("File_Content");
+ return cachedRowSetMocked;
+ }
+
+ @Override
+ public boolean writeData(String s, ArrayList<String> arrayList, String s1) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public boolean isActive() {
+ return false;
+ }
+
+ @Override
+ public Connection getConnection() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Connection getConnection(String username, String password) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public <T> T unwrap(Class<T> iface) throws SQLException {
+ return null;
+ }
+
+ @Override
+ public boolean isWrapperFor(Class<?> iface) throws SQLException {
+ return false;
+ }
+
+ @Override
+ public PrintWriter getLogWriter() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public void setLogWriter(PrintWriter out) throws SQLException {
+
+ }
+
+ @Override
+ public int getLoginTimeout() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public void setLoginTimeout(int seconds) throws SQLException {
+
+ }
+
+ @Override
+ public Logger getParentLogger() throws SQLFeatureNotSupportedException {
+ return null;
+ }
+ };
+
+ netconfDataAccessService = new NetconfDataAccessServiceImpl();
+ netconfDataAccessService.setSchema(schema);
+ netconfDataAccessService.setDbLibService(dbLibServiceMocked);
+ }
+
+ @Test
+ public void testRetrieveConfigFileName() throws IOException {
+ String response = netconfDataAccessService.retrieveConfigFileName("test");
+ Assert.assertEquals("File_Content", response);
+ }
+
+ @Test
+ public void testRetrieveNetconfConnectionDetails() throws IOException {
+ NetconfConnectionDetails netconfConnectionDetails = new NetconfConnectionDetails();
+ boolean response = netconfDataAccessService.retrieveNetconfConnectionDetails("test", netconfConnectionDetails);
+ Assert.assertEquals(true, response);
+ }
+
+ @Test
+ public void testLogDeviceInteraction() throws IOException {
+ boolean response = netconfDataAccessService.logDeviceInteraction("test", "",
+ "", "");
+ Assert.assertEquals(true, response);
+ }
+}
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestGetRunningConfig.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestGetRunningConfig.java
new file mode 100644
index 000000000..2ad873f54
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestGetRunningConfig.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.ccsdk.sli.adaptors.netconf.jsch;
+
+import java.util.Collections;
+import java.util.List;
+import org.onap.ccsdk.sli.adaptors.netconf.NetconfConnectionDetails;
+
+public class TestGetRunningConfig {
+
+ private static final String HOST = "192.168.1.2";
+ private static final String USER = "test";
+ private static final String PSWD = "test123";
+ private static final int PORT = 830;
+ private static final List<String> CAPABILITIES = Collections.singletonList("<capability>urn:org:onap:appc:capability:1.1.0</capability>");
+
+ public static void main(String[] args) {
+ try {
+ NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
+ connectionDetails.setHost(HOST);
+ connectionDetails.setPort(PORT);
+ connectionDetails.setUsername(USER);
+ connectionDetails.setPassword(PSWD);
+ connectionDetails.setCapabilities(CAPABILITIES);
+ NetconfClientJsch netconfClientJsch = new NetconfClientJsch();
+ netconfClientJsch.connect(connectionDetails);
+ try {
+ System.out.println("=> Running get configuration...");
+ String configuration = netconfClientJsch.getConfiguration();
+ System.out.println("=> Configuration:\n" + configuration);
+ } finally {
+ netconfClientJsch.disconnect();
+ }
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestJSchLogger.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestJSchLogger.java
new file mode 100644
index 000000000..0a7bd5203
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestJSchLogger.java
@@ -0,0 +1,55 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Samsung
+ * ================================================================================
+ * 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.ccsdk.sli.adaptors.netconf.jsch;
+
+import java.io.IOException;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+
+public class TestJSchLogger {
+
+
+ @Test
+ public void testIsEnabled() throws IOException {
+ JSchLogger jSchLogger = new JSchLogger();
+
+ boolean response = jSchLogger.isEnabled(2);
+
+ Assert.assertEquals(true, response);
+ }
+
+ @Test
+ public void testLog() throws IOException {
+ JSchLogger jSchLogger = new JSchLogger();
+
+ jSchLogger.log(0, "test-debug");
+ jSchLogger.log(1, "test-info");
+ jSchLogger.log(2, "test-warn");
+ jSchLogger.log(3, "test-error");
+ jSchLogger.log(4, "test-fatal");
+ jSchLogger.log(5, "test-other");
+ assertNotNull(jSchLogger);
+
+ }
+}
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestModifyConfig.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestModifyConfig.java
new file mode 100644
index 000000000..aaa74f5c9
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestModifyConfig.java
@@ -0,0 +1,92 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.ccsdk.sli.adaptors.netconf.jsch;
+
+import java.util.Collections;
+import java.util.List;
+import org.onap.ccsdk.sli.adaptors.netconf.NetconfConnectionDetails;
+
+public class TestModifyConfig {
+
+ private static final String HOST = "192.168.1.2";
+ private static final String USER = "test";
+ private static final String PSWD = "test123";
+ private static final int PORT = 830;
+ private static final List<String> CAPABILITIES = Collections.singletonList("<capability>urn:org:onap:appc:capability:1.1.0</capability>");
+ private static final String CONFIG =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">\n" +
+ " <edit-config>\n" +
+ " <target>\n" +
+ " <running />\n" +
+ " </target>\n" +
+ " <default-operation>merge</default-operation>\n" +
+ " <config xmlns:xc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
+ " <ManagedElement xmlns=\"urn:org.onap.appc:Test\">\n" +
+ " <managedElementId>1</managedElementId>\n" +
+ " <VnfFunction xmlns=\"urn:org:onap:appc:VnfFunction\">\n" +
+ " <id>1</id>\n" +
+ " <Interfaces>\n" +
+ " <id>1</id>\n" +
+ " <DiaRealmRf>\n" +
+ " <realm>example.com</realm>\n" +
+ " <reconnectTimer>60</reconnectTimer>\n" +
+ " </DiaRealmRf>\n" +
+ " </Interfaces>\n" +
+ " </VnfFunction>\n" +
+ " </ManagedElement>\n" +
+ " </config>\n" +
+ " </edit-config>\n" +
+ "</rpc>";
+
+ public static void main(String[] args) {
+ try {
+ NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
+ connectionDetails.setHost(HOST);
+ connectionDetails.setPort(PORT);
+ connectionDetails.setUsername(USER);
+ connectionDetails.setPassword(PSWD);
+ connectionDetails.setCapabilities(CAPABILITIES);
+ NetconfClientJsch netconfClientJsch = new NetconfClientJsch();
+ netconfClientJsch.connect(connectionDetails);
+ try {
+ System.out.println("=> Running get configuration...");
+ String configuration = netconfClientJsch.getConfiguration();
+ System.out.println("=> Configuration:\n" + configuration);
+
+ System.out.println("=> Reconfiguring device...");
+ String outMessage = netconfClientJsch.exchangeMessage(CONFIG);
+ System.out.println("=> Reconfiguration response:\n" + outMessage);
+
+ System.out.println("=> Running get configuration...");
+ configuration = netconfClientJsch.getConfiguration();
+ System.out.println("=> Configuration:\n" + configuration);
+ } finally {
+ netconfClientJsch.disconnect();
+ }
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestModifyConfigMock.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestModifyConfigMock.java
new file mode 100644
index 000000000..eb6473854
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestModifyConfigMock.java
@@ -0,0 +1,92 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.ccsdk.sli.adaptors.netconf.jsch;
+
+import java.util.Collections;
+import java.util.List;
+import org.onap.ccsdk.sli.adaptors.netconf.NetconfConnectionDetails;
+
+public class TestModifyConfigMock {
+
+ private static final String HOST = "192.168.1.2";
+ private static final String USER = "test";
+ private static final String PSWD = "test123";
+ private static final int PORT = 830;
+ private static final List<String> CAPABILITIES = Collections.singletonList("<capability>urn:org:onap:appc:capability:1.1.0</capability>");
+ private static final String CONFIG =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">\n" +
+ " <edit-config>\n" +
+ " <target>\n" +
+ " <running />\n" +
+ " </target>\n" +
+ " <default-operation>merge</default-operation>\n" +
+ " <config xmlns:xc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
+ " <ManagedElement xmlns=\"urn:org.onap.appc:Test\">\n" +
+ " <managedElementId>1</managedElementId>\n" +
+ " <VnfFunction xmlns=\"urn:org:onap:appc:VnfFunction\">\n" +
+ " <id>1</id>\n" +
+ " <Interfaces>\n" +
+ " <id>1</id>\n" +
+ " <DiaRealmRf>\n" +
+ " <realm>example.com</realm>\n" +
+ " <reconnectTimer>60</reconnectTimer>\n" +
+ " </DiaRealmRf>\n" +
+ " </Interfaces>\n" +
+ " </VnfFunction>\n" +
+ " </ManagedElement>\n" +
+ " </config>\n" +
+ " </edit-config>\n" +
+ "</rpc>";
+
+ public static void main(String[] args) {
+ try {
+ NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
+ connectionDetails.setHost(HOST);
+ connectionDetails.setPort(PORT);
+ connectionDetails.setUsername(USER);
+ connectionDetails.setPassword(PSWD);
+ connectionDetails.setCapabilities(CAPABILITIES);
+ NetconfClientJsch netconfClientJsch = new NetconfClientJsch();
+ netconfClientJsch.connect(connectionDetails);
+ try {
+ System.out.println("=> Running get configuration...");
+ String configuration = netconfClientJsch.getConfiguration();
+ System.out.println("=> Configuration:\n" + configuration);
+
+ System.out.println("=> Reconfiguring device...");
+ String outMessage = netconfClientJsch.exchangeMessage(CONFIG);
+ System.out.println("=> Reconfiguration response:\n" + outMessage);
+
+ System.out.println("=> Running get configuration...");
+ configuration = netconfClientJsch.getConfiguration();
+ System.out.println("=> Configuration:\n" + configuration);
+ } finally {
+ netconfClientJsch.disconnect();
+ }
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestModifyConfigRouterMock.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestModifyConfigRouterMock.java
new file mode 100644
index 000000000..7c209b9c2
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestModifyConfigRouterMock.java
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.ccsdk.sli.adaptors.netconf.jsch;
+
+import java.util.Collections;
+import java.util.List;
+import org.onap.ccsdk.sli.adaptors.netconf.NetconfConnectionDetails;
+
+public class TestModifyConfigRouterMock {
+
+ private static final String HOST = "10.147.27.50"; // yuma netconf simulator
+ private static final int PORT = 830;
+ private static final String USER = "admin";
+ private static final String PSWD = "admin";
+ private static final List<String> CAPABILITIES = Collections.emptyList();
+ private static final String CONFIG =
+ "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
+ " <edit-config>\n" +
+ " <target>\n" +
+ " <candidate/>\n" +
+ " </target>\n" +
+ " <config xmlns:xc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
+ " <router xmlns=\"urn:sdnhub:odl:tutorial:router\">\n" +
+ " <ospf>\n" +
+ " <process-id>1</process-id>\n" +
+ " <networks>\n" +
+ " <subnet-ip>100.100.100.0/24</subnet-ip>\n" +
+ " <area-id>10</area-id>\n" +
+ " </networks>\n" +
+ " </ospf>\n" +
+ " <bgp>\n" +
+ " <as-number>1000</as-number>\n" +
+ " <router-id>10.10.1.1</router-id>\n" +
+ " <neighbors>\n" +
+ " <as-number>2000</as-number>\n" +
+ " <peer-ip>10.10.1.2</peer-ip>\n" +
+ " </neighbors>\n" +
+ " </bgp>\n" +
+ " </router>\n" +
+ " </config>\n" +
+ " </edit-config>\n" +
+ "</rpc>\n";
+
+ public static void main(String[] args) {
+ try {
+ NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
+ connectionDetails.setHost(HOST);
+ connectionDetails.setPort(PORT);
+ connectionDetails.setUsername(USER);
+ connectionDetails.setPassword(PSWD);
+ connectionDetails.setCapabilities(CAPABILITIES);
+ NetconfClientJsch netconfClientJsch = new NetconfClientJsch();
+ netconfClientJsch.connect(connectionDetails);
+ try {
+ System.out.println("=> Running get configuration...");
+ String configuration = netconfClientJsch.getConfiguration();
+ System.out.println("=> Configuration:\n" + configuration);
+
+ System.out.println("=> Reconfiguring device...");
+ String outMessage = netconfClientJsch.exchangeMessage(CONFIG);
+ System.out.println("=> Reconfiguration response:\n" + outMessage);
+ } finally {
+ netconfClientJsch.disconnect();
+ }
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestNetconfClientJsch.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestNetconfClientJsch.java
new file mode 100644
index 000000000..22d3ec482
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestNetconfClientJsch.java
@@ -0,0 +1,191 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 Samsung
+ * ================================================================================
+ * Modifications Copyright (C) 2018 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.ccsdk.sli.adaptors.netconf.jsch;
+
+import com.jcraft.jsch.ChannelSubsystem;
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.Session;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mockito;
+import org.onap.ccsdk.sli.adaptors.netconf.NetconfConnectionDetails;
+import org.onap.ccsdk.sli.adaptors.netconf.internal.NetconfAdaptor;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.powermock.reflect.Whitebox;
+
+import static org.hamcrest.CoreMatchers.allOf;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.isA;
+import static org.hamcrest.beans.HasPropertyWithValue.hasProperty;
+import static org.junit.Assert.assertEquals;
+
+public class TestNetconfClientJsch {
+
+ NetconfClientJsch netconfClientJsch;
+ private ChannelSubsystem mockChannel;
+ private NetconfAdaptor mockNetconfAdaptor;
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ @Before
+ public void SetUp() {
+ netconfClientJsch = Mockito.spy(new NetconfClientJsch());
+ }
+
+ private void setupForConnectTests() throws JSchException, IOException {
+ Session mockSession = Mockito.mock(Session.class);
+ JSch mockJSch = Mockito.mock(JSch.class);
+ mockChannel = Mockito.mock(ChannelSubsystem.class);
+ InputStream mockInputStream = Mockito.mock(InputStream.class);
+ OutputStream mockOutputStream = Mockito.mock(OutputStream.class);
+ mockNetconfAdaptor = Mockito.mock(NetconfAdaptor.class);
+ Mockito.doReturn(mockJSch).when(netconfClientJsch).getJSch();
+ Mockito.doReturn(mockSession).when(mockJSch).getSession(Mockito.anyString(),
+ Mockito.anyString(), Mockito.anyInt());
+ Mockito.doReturn(mockChannel).when(mockSession).openChannel("subsystem");
+ Mockito.doReturn(mockInputStream).when(mockChannel).getInputStream();
+ Mockito.doReturn(mockOutputStream).when(mockChannel).getOutputStream();
+ Mockito.doReturn(mockNetconfAdaptor).when(netconfClientJsch)
+ .getNetconfAdaptor(Mockito.any(InputStream.class), Mockito.any(OutputStream.class));
+ }
+
+ @Test
+ public void testConnect() throws SvcLogicException, IOException, JSchException {
+ setupForConnectTests();
+ Mockito.doReturn("<hello>").when(mockNetconfAdaptor).receiveMessage();
+ NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
+ connectionDetails.setHost("test");
+ connectionDetails.setPort(8080);
+ connectionDetails.setUsername("test");
+ connectionDetails.setPassword("test");
+ List<String> capabilities = Collections.singletonList(
+ "<capability>urn:ietf:params:netconf:base:1.1</capability>\r\n");
+ connectionDetails.setCapabilities(capabilities);
+ Properties additionalProperties = new Properties();
+ additionalProperties.setProperty("testKey1", "testParam1");
+ connectionDetails.setAdditionalProperties(additionalProperties);
+ netconfClientJsch.connect(connectionDetails);
+ Mockito.verify(mockNetconfAdaptor).sendMessage(
+ Mockito.contains("<capability>urn:ietf:params:netconf:base:1.1</capability>"));
+ }
+
+ @Test
+ public void testConnectNullMessage() throws JSchException, IOException, SvcLogicException {
+ setupForConnectTests();
+ NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
+ expectedEx.expect(SvcLogicException.class);
+ //expectedEx.expectMessage("Cannot establish connection to server");
+ netconfClientJsch.connect(connectionDetails);
+ }
+
+ @Test
+ public void testConnectNullMessageNonNullResponse()
+ throws JSchException, IOException, SvcLogicException {
+ setupForConnectTests();
+ Mockito.doReturn("NOT NULL RESPONSE").when(mockNetconfAdaptor).receiveMessage();
+ Mockito.doThrow(new JSchException()).when(mockChannel).connect(10000);
+ NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectCause(allOf(isA(RuntimeException.class),
+ hasProperty("message", is("Error closing netconf device"))));
+ netconfClientJsch.connect(connectionDetails);
+ }
+
+ @Test
+ public void testConnectErrorMessage() throws JSchException, IOException, SvcLogicException {
+ setupForConnectTests();
+ Mockito.doReturn("<rpc-error>").when(mockNetconfAdaptor).receiveMessage();
+ NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx
+ .expectCause(allOf(isA(RuntimeException.class),
+ hasProperty("cause", allOf(isA(IOException.class),
+ hasProperty("message",
+ containsString("Error response from netconf device:")),
+ hasProperty("message", containsString("<rpc-error>"))
+ ))));
+ netconfClientJsch.connect(connectionDetails);
+ }
+
+ @Test
+ public void testConnectWithSuccessfulDisconnect()
+ throws JSchException, IOException, SvcLogicException {
+ setupForConnectTests();
+ Mockito.doThrow(new JSchException()).when(mockChannel).connect(10000);
+ Mockito.doReturn("<ok/>").when(mockNetconfAdaptor).receiveMessage();
+ NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectCause(allOf(isA(SvcLogicException.class),
+ hasProperty("message", is(JSchException.class.getName()))));
+ netconfClientJsch.connect(connectionDetails);
+ }
+
+ @Test
+ public void testGetConfiguration() throws IOException, SvcLogicException {
+ mockNetconfAdaptor = Mockito.mock(NetconfAdaptor.class);
+ Whitebox.setInternalState(netconfClientJsch, "netconfAdaptor", mockNetconfAdaptor);
+ Mockito.doReturn("TEST RETURN VALUE").when(mockNetconfAdaptor).receiveMessage();
+ assertEquals("TEST RETURN VALUE", netconfClientJsch.getConfiguration());
+ }
+
+ @Test
+ public void testGetConfigurationExceptionFlow() throws IOException, SvcLogicException {
+ mockNetconfAdaptor = Mockito.mock(NetconfAdaptor.class);
+ Whitebox.setInternalState(netconfClientJsch, "netconfAdaptor", mockNetconfAdaptor);
+ Mockito.doThrow(new IOException()).when(mockNetconfAdaptor).receiveMessage();
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage(IOException.class.getName());
+ netconfClientJsch.getConfiguration();
+ }
+
+ @Test
+ public void testConfigure() throws IOException, SvcLogicException {
+ mockNetconfAdaptor = Mockito.mock(NetconfAdaptor.class);
+ Whitebox.setInternalState(netconfClientJsch, "netconfAdaptor", mockNetconfAdaptor);
+ Mockito.doReturn("<ok/>").when(mockNetconfAdaptor).receiveMessage();
+ netconfClientJsch.configure(null);
+ Mockito.verify(netconfClientJsch).exchangeMessage(null);
+ }
+
+ @Test
+ public void testConfigureExceptionFlow() throws IOException, SvcLogicException {
+ mockNetconfAdaptor = Mockito.mock(NetconfAdaptor.class);
+ Whitebox.setInternalState(netconfClientJsch, "netconfAdaptor", mockNetconfAdaptor);
+ Mockito.doThrow(new IOException()).when(mockNetconfAdaptor).receiveMessage();
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage(IOException.class.getName());
+ netconfClientJsch.configure(null);
+ }
+}
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestOperationalStates.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestOperationalStates.java
new file mode 100644
index 000000000..128d68347
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/jsch/TestOperationalStates.java
@@ -0,0 +1,86 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.ccsdk.sli.adaptors.netconf.jsch;
+
+import java.util.Collections;
+import java.util.List;
+import org.onap.ccsdk.sli.adaptors.netconf.NetconfConnectionDetails;
+
+public class TestOperationalStates {
+
+ private static final String HOST = "192.168.1.2";
+ private static final String USER = "test";
+ private static final String PSWD = "test123";
+ private static final int PORT = 830;
+ private static final List<String> CAPABILITIES = Collections.singletonList("<capability>urn:org:onap:appc:capability:1.1.0</capability>");
+ private static final String GET_OPERATIONAL_STATES =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
+ " <get>\n" +
+ " <filter>\n" +
+ " <ManagedElement xmlns=\"urn:org:onap:appc:Test\">\n" +
+ " <VnfFunction xmlns=\"urn:org:onap:appc:Test\">\n" +
+ " <ProcessorManagement>\n" +
+ " <MatedPair>\n" +
+ " <operationalState/>\n" +
+ " <PayloadProcessor>\n" +
+ " <operationalState/>\n" +
+ " </PayloadProcessor>\n" +
+ " </MatedPair>\n" +
+ " <SystemController>\n" +
+ " <operationalState/>\n" +
+ " </SystemController>\n" +
+ " </ProcessorManagement>\n" +
+ " </VnfFunction>\n" +
+ " </ManagedElement>\n" +
+ " </filter>\n" +
+ " </get>\n" +
+ "</rpc>";
+
+ public static void main(String[] args) {
+ try {
+ NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
+ connectionDetails.setHost(HOST);
+ connectionDetails.setPort(PORT);
+ connectionDetails.setUsername(USER);
+ connectionDetails.setPassword(PSWD);
+ connectionDetails.setCapabilities(CAPABILITIES);
+ NetconfClientJsch netconfClientJsch = new NetconfClientJsch();
+ netconfClientJsch.connect(connectionDetails);
+ try {
+ System.out.println("=> Running get configuration...");
+ String configuration = netconfClientJsch.getConfiguration();
+ System.out.println("=> Configuration:\n" + configuration);
+
+ System.out.println("=> Running get operational states...");
+ String outMessage = netconfClientJsch.exchangeMessage(GET_OPERATIONAL_STATES);
+ System.out.println("=> Operational states:\n" + outMessage);
+ } finally {
+ netconfClientJsch.disconnect();
+ }
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/odlconnector/NetconfClientRestconfImplTest.java b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/odlconnector/NetconfClientRestconfImplTest.java
new file mode 100644
index 000000000..4b59c6d2a
--- /dev/null
+++ b/adaptors/netconf-adaptor/netconf-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/netconf/odlconnector/NetconfClientRestconfImplTest.java
@@ -0,0 +1,207 @@
+/*
+ * ============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.ccsdk.sli.adaptors.netconf.odlconnector;
+
+import java.util.Properties;
+import org.apache.http.HttpStatus;
+import org.junit.Before;
+import org.junit.Ignore;
+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.ccsdk.sli.adaptors.netconf.HttpClient;
+import org.onap.ccsdk.sli.adaptors.netconf.NetconfAdaptorConstants;
+import org.onap.ccsdk.sli.adaptors.netconf.NetconfConnectionDetails;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.powermock.reflect.Whitebox;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+@Ignore
+@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 SvcLogicException {
+ NetconfClientRestconfImpl client = new NetconfClientRestconfImpl();
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Invalid connection details - null value");
+ client.configure(null);
+ }
+
+ @Test
+ public void testConfigureNullProperties() throws SvcLogicException {
+ NetconfClientRestconfImpl client = Mockito.spy(new NetconfClientRestconfImpl());
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Invalid properties!");
+ Whitebox.setInternalState(client, "connectionDetails", Mockito.mock(NetconfConnectionDetails.class));
+ client.configure(null);
+ }
+
+ @Test
+ public void testConfigureWithError() throws SvcLogicException {
+ PowerMockito.when(HttpClient.putMethod(NetconfAdaptorConstants.PROTOCOL, NetconfAdaptorConstants.CONTROLLER_IP, NetconfAdaptorConstants.CONTROLLER_PORT,
+ NetconfAdaptorConstants.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(SvcLogicException.class);
+ expectedEx.expectMessage("Error configuring node :NODE_NAME, of Module :MODULE_NAME, in device :null");
+ client.configure(null);
+ }
+
+ @Test
+ public void testConfigure4ArgWithError() throws SvcLogicException {
+ PowerMockito.when(HttpClient.putMethod(NetconfAdaptorConstants.PROTOCOL, NetconfAdaptorConstants.CONTROLLER_IP, NetconfAdaptorConstants.CONTROLLER_PORT,
+ NetconfAdaptorConstants.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(SvcLogicException.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 SvcLogicException {
+ PowerMockito.when(HttpClient.putMethod(NetconfAdaptorConstants.PROTOCOL, NetconfAdaptorConstants.CONTROLLER_IP, NetconfAdaptorConstants.CONTROLLER_PORT,
+ NetconfAdaptorConstants.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(SvcLogicException.class);
+ expectedEx.expectMessage("Error connecting device :null");
+ client.connect(details);
+ }
+
+ @Test
+ public void testConnectWithNullDetails() throws SvcLogicException {
+ PowerMockito.when(HttpClient.putMethod(NetconfAdaptorConstants.PROTOCOL, NetconfAdaptorConstants.CONTROLLER_IP, NetconfAdaptorConstants.CONTROLLER_PORT,
+ NetconfAdaptorConstants.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(SvcLogicException.class);
+ expectedEx.expectMessage("Invalid connection details - null value");
+ client.connect(null);
+ }
+
+ @Test
+ public void testDisconnectNullDetails() throws SvcLogicException {
+ NetconfClientRestconfImpl client = Mockito.spy(new NetconfClientRestconfImpl());
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Invalid connection details - null value");
+ client.disconnect();
+ }
+
+ @Test
+ public void testDisconnect() throws SvcLogicException {
+ 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(SvcLogicException.class);
+ expectedEx.expectMessage("Disconnection of device null failed!");
+ client.disconnect();
+ }
+
+ @Test
+ public void testGetConfigurationNullDetails() throws SvcLogicException {
+ NetconfClientRestconfImpl client = Mockito.spy(new NetconfClientRestconfImpl());
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Invalid connection details - null value");
+ client.getConfiguration();
+ }
+
+ @Test
+ public void testGetConfigurationNullProperties() throws SvcLogicException {
+ NetconfClientRestconfImpl client = Mockito.spy(new NetconfClientRestconfImpl());
+ expectedEx.expect(SvcLogicException.class);
+ expectedEx.expectMessage("Invalid properties!");
+ Whitebox.setInternalState(client, "connectionDetails", Mockito.mock(NetconfConnectionDetails.class));
+ client.getConfiguration();
+ }
+
+ @Test
+ public void testGetConfigurationWithError() throws SvcLogicException {
+ PowerMockito.when(HttpClient.putMethod(NetconfAdaptorConstants.PROTOCOL, NetconfAdaptorConstants.CONTROLLER_IP, NetconfAdaptorConstants.CONTROLLER_PORT,
+ NetconfAdaptorConstants.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(SvcLogicException.class);
+ expectedEx.expectMessage("Error getting configuration of node :NODE_NAME, of Module :MODULE_NAME, in device :null");
+ client.getConfiguration();
+ }
+
+ @Test
+ public void testGetConfigurationSuccess() throws SvcLogicException {
+ PowerMockito.when(HttpClient.getMethod(NetconfAdaptorConstants.PROTOCOL, NetconfAdaptorConstants.CONTROLLER_IP, NetconfAdaptorConstants.CONTROLLER_PORT,
+ NetconfAdaptorConstants.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 SvcLogicException {
+ NetconfClientRestconfImpl client = new NetconfClientRestconfImpl();
+ assertFalse(client.checkConnection(null));
+
+ }
+}