From 1c192d2dd68724e292b6a30f463085a262e1e813 Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 15 Feb 2017 23:11:26 -0800 Subject: Moving all files to root directory Change-Id: Ica5535fd6ec85f350fe1640b42137b49f83f10f0 Signed-off-by: Patrick Brady --- .../test/java/OperationalStateValidatorTest.java | 197 +++++++++++++++++++++ .../netconf/internal/TestNetconfAdapter.java | 88 +++++++++ .../adapter/netconf/jsch/TestGetRunningConfig.java | 60 +++++++ .../adapter/netconf/jsch/TestModifyConfig.java | 93 ++++++++++ .../adapter/netconf/jsch/TestModifyConfigMock.java | 93 ++++++++++ .../netconf/jsch/TestModifyConfigRouterMock.java | 91 ++++++++++ .../netconf/jsch/TestOperationalStates.java | 87 +++++++++ 7 files changed, 709 insertions(+) create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/OperationalStateValidatorTest.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/internal/TestNetconfAdapter.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestGetRunningConfig.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfig.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfigMock.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfigRouterMock.java create mode 100644 appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestOperationalStates.java (limited to 'appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java') diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/OperationalStateValidatorTest.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/OperationalStateValidatorTest.java new file mode 100644 index 000000000..d6d5ae278 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/OperationalStateValidatorTest.java @@ -0,0 +1,197 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 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========================================================= + */ + +import org.openecomp.appc.exceptions.APPCException; +import org.junit.Test; +import org.openecomp.appc.adapter.netconf.OperationalStateValidator; +import org.openecomp.appc.adapter.netconf.OperationalStateValidatorFactory; +import org.openecomp.appc.adapter.netconf.VnfType; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + + +public class OperationalStateValidatorTest { + + @Test + public void testVNFValidResponse() { + String validResponse = "\n" + + "\n" + + " \n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " ENABLED\n" + + " \n" + + " processor_0_5\n" + + " ENABLED\n" + + " \n" + + " \n" + + " processor_0_7\n" + + " ENABLED\n" + + " \n" + + " \n" + + " \n" + + " SC-1\n" + + " ENABLED\n" + + " \n" + + " \n" + + " SC-2\n" + + " ENABLED\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(VnfType.VNF); + assertValidResponse(validResponse, operationalStateValidator); + } + + void assertInvalidResponse(String response, OperationalStateValidator operationalStateValidator) { + try { + operationalStateValidator.validateResponse(response); + fail("invalid resposne passed without exception!!!"); + } catch (APPCException e) { + assertNotNull(e.getMessage()); + } + } + + @Test + public void testVNFInvalidResponses() { + + OperationalStateValidator operationalStateValidator = OperationalStateValidatorFactory.getOperationalStateValidator(VnfType.VNF); + assertInvalidResponse(null, operationalStateValidator); + + assertInvalidResponse("", operationalStateValidator); + + String response = ""; + assertInvalidResponse(response, operationalStateValidator); + + response = "\n" + + "\n" + + ""; + assertInvalidResponse(response, operationalStateValidator); + + response = "\n" + + "\n" + + " \n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " ENABLED\n" + + " \n" + + " processor_0_5\n" + + " ENABLED\n" + + " \n" + + " \n" + + " processor_0_7\n" + + " ENABLED\n" + + " \n" + + " \n" + + " \n" + + " SC-1\n" + + " ENABLED\n" + + " \n" + + " \n" + + " SC-2\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + assertInvalidResponse(response, operationalStateValidator); + } + + void assertValidResponse(String response, OperationalStateValidator operationalStateValidator) { + try { + operationalStateValidator.validateResponse(response); + } catch (APPCException 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/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/internal/TestNetconfAdapter.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/internal/TestNetconfAdapter.java new file mode 100644 index 000000000..5e63d5010 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/internal/TestNetconfAdapter.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 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.openecomp.appc.adapter.netconf.internal; + +import org.junit.Assert; +import org.junit.Test; +import org.openecomp.appc.adapter.netconf.internal.NetconfAdapter; + +import java.io.IOException; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; + +public class TestNetconfAdapter { + + 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); + + NetconfAdapter netconfAdapter = new NetconfAdapter(is, os); + + String request = "Hello, netconf!"; + pos.write(request.getBytes()); + pos.write(EOM.getBytes()); + String response = netconfAdapter.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); + + NetconfAdapter netconfAdapter = new NetconfAdapter(is, os); + + String request = "Hello, netconf!"; + netconfAdapter.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); + + NetconfAdapter netconfAdapter = new NetconfAdapter(is, os); + + String request = "Hello, netconf!"; + netconfAdapter.sendMessage(request); + String response = netconfAdapter.receiveMessage(); + Assert.assertNotNull(response); + Assert.assertEquals(request, response.trim()); + } +} diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestGetRunningConfig.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestGetRunningConfig.java new file mode 100644 index 000000000..a26c6e9e9 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestGetRunningConfig.java @@ -0,0 +1,60 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 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.openecomp.appc.adapter.netconf.jsch; + +import java.util.Collections; +import java.util.List; + +import org.openecomp.appc.adapter.netconf.NetconfConnectionDetails; +import org.openecomp.appc.adapter.netconf.jsch.NetconfClientJsch; +import org.openecomp.appc.exceptions.APPCException; + +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 CAPABILITIES = Collections.singletonList("urn:org:openecomp:appc:capability:1.1.0"); + + public static void main(String[] args) throws APPCException { + 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/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfig.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfig.java new file mode 100644 index 000000000..e4baecc89 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfig.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 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.openecomp.appc.adapter.netconf.jsch; + +import java.util.Collections; +import java.util.List; + +import org.openecomp.appc.adapter.netconf.NetconfConnectionDetails; +import org.openecomp.appc.adapter.netconf.jsch.NetconfClientJsch; +import org.openecomp.appc.exceptions.APPCException; + +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 CAPABILITIES = Collections.singletonList("urn:org:openecomp:appc:capability:1.1.0"); + private static final String CONFIG = + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " merge\n" + + " \n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " example.com\n" + + " 60\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + public static void main(String[] args) throws APPCException { + 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/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfigMock.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfigMock.java new file mode 100644 index 000000000..1fe2e1093 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfigMock.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 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.openecomp.appc.adapter.netconf.jsch; + +import java.util.Collections; +import java.util.List; + +import org.openecomp.appc.adapter.netconf.NetconfConnectionDetails; +import org.openecomp.appc.adapter.netconf.jsch.NetconfClientJsch; +import org.openecomp.appc.exceptions.APPCException; + +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 CAPABILITIES = Collections.singletonList("urn:org:openecomp:appc:capability:1.1.0"); + private static final String CONFIG = + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " merge\n" + + " \n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " 1\n" + + " \n" + + " example.com\n" + + " 60\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + public static void main(String[] args) throws APPCException { + 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/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfigRouterMock.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfigRouterMock.java new file mode 100644 index 000000000..256e8e8f5 --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestModifyConfigRouterMock.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 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.openecomp.appc.adapter.netconf.jsch; + +import java.util.Collections; +import java.util.List; + +import org.openecomp.appc.adapter.netconf.NetconfConnectionDetails; +import org.openecomp.appc.adapter.netconf.jsch.NetconfClientJsch; +import org.openecomp.appc.exceptions.APPCException; + +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 CAPABILITIES = Collections.emptyList(); + private static final String CONFIG = + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 1\n" + + " \n" + + " 100.100.100.0/24\n" + + " 10\n" + + " \n" + + " \n" + + " \n" + + " 1000\n" + + " 10.10.1.1\n" + + " \n" + + " 2000\n" + + " 10.10.1.2\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n"; + + public static void main(String[] args) throws APPCException { + 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/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestOperationalStates.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestOperationalStates.java new file mode 100644 index 000000000..39c1a871c --- /dev/null +++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/openecomp/appc/adapter/netconf/jsch/TestOperationalStates.java @@ -0,0 +1,87 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : APP-C + * ================================================================================ + * Copyright (C) 2017 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.openecomp.appc.adapter.netconf.jsch; + +import java.util.Collections; +import java.util.List; + +import org.openecomp.appc.adapter.netconf.NetconfConnectionDetails; +import org.openecomp.appc.adapter.netconf.jsch.NetconfClientJsch; +import org.openecomp.appc.exceptions.APPCException; + +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 CAPABILITIES = Collections.singletonList("urn:org:openecomp:appc:capability:1.1.0"); + private static final String GET_OPERATIONAL_STATES = + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + public static void main(String[] args) throws APPCException { + 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(); + } + } +} -- cgit 1.2.3-korg