2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
 
   6  * ================================================================================
 
   7  * Copyright (C) 2017 Amdocs
 
   8  * ================================================================================
 
   9  * Modifications (C) 2019 Ericsson
 
  10  * =============================================================================
 
  11  * Licensed under the Apache License, Version 2.0 (the "License");
 
  12  * you may not use this file except in compliance with the License.
 
  13  * You may obtain a copy of the License at
 
  15  *      http://www.apache.org/licenses/LICENSE-2.0
 
  17  * Unless required by applicable law or agreed to in writing, software
 
  18  * distributed under the License is distributed on an "AS IS" BASIS,
 
  19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  20  * See the License for the specific language governing permissions and
 
  21  * limitations under the License.
 
  23  * ============LICENSE_END=========================================================
 
  26 package org.onap.appc.dg.netconf.impl;
 
  28 import org.onap.appc.exceptions.APPCException;
 
  29 import com.fasterxml.jackson.databind.ObjectMapper;
 
  30 import org.junit.Assert;
 
  31 import org.junit.Before;
 
  32 import org.junit.Test;
 
  33 import org.junit.runner.RunWith;
 
  34 import org.mockito.Matchers;
 
  35 import org.mockito.Mockito;
 
  36 import org.onap.appc.adapter.netconf.util.Constants;
 
  37 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 
  38 import org.onap.appc.adapter.netconf.ConnectionDetails;
 
  39 import org.onap.appc.adapter.netconf.NetconfClientFactory;
 
  40 import org.onap.appc.adapter.netconf.NetconfClientType;
 
  41 import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
 
  42 import org.onap.appc.adapter.netconf.NetconfDataAccessService;
 
  43 import org.onap.appc.adapter.netconf.OperationalStateValidatorFactory;
 
  44 import org.onap.appc.adapter.netconf.VnfType;
 
  45 import org.osgi.framework.Bundle;
 
  46 import org.osgi.framework.BundleContext;
 
  47 import org.osgi.framework.FrameworkUtil;
 
  48 import org.osgi.framework.ServiceReference;
 
  49 import org.powermock.api.mockito.PowerMockito;
 
  50 import org.powermock.core.classloader.annotations.PrepareForTest;
 
  51 import org.powermock.modules.junit4.PowerMockRunner;
 
  53 import java.lang.reflect.Field;
 
  54 import java.text.DateFormat;
 
  55 import java.text.SimpleDateFormat;
 
  56 import java.util.Date;
 
  57 import java.util.HashMap;
 
  60 import static org.powermock.api.mockito.PowerMockito.when;
 
  64 @RunWith(PowerMockRunner.class)
 
  65 @PrepareForTest({OperationalStateValidatorFactory.class, FrameworkUtil.class, ObjectMapper.class})
 
  67 public class NetconfClientPluginImplTest {
 
  68     private NetconfClientPluginImpl netconfClientPlugin;
 
  69     private NetconfDataAccessService dao;
 
  70     private NetconfClientFactory clientFactory;
 
  71     private Map<String, String> params;
 
  73     private final BundleContext bundleContext = Mockito.mock(BundleContext.class);
 
  74     private final Bundle bundleService = Mockito.mock(Bundle.class);
 
  75     private final ServiceReference sref1 = Mockito.mock(ServiceReference.class);
 
  76     private final ServiceReference sref2 = Mockito.mock(ServiceReference.class);
 
  77     private final ServiceReference sref3 = Mockito.mock(ServiceReference.class);
 
  78     private static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message";
 
  81     String host = "http://www.test.com";
 
  82     String host1 = "http://www.test1.com";
 
  83     String vnfType = "VNF";
 
  85     String username = "test";
 
  86     String password = "test";
 
  87     String connectionDetails = "{\"host\":\"" + host + "\",\"port\":" + port + ",\"username\":\"" + username + "\",\"password\":\"" + password + "\",\"capabilities\":null,\"additionalProperties\":null}";
 
  88     String fileContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
 
  89             "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
 
  92             "\t\t\t<running/>\n" +
 
  96     String operationalState = "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
 
  99             "                     <ManagedElement xmlns=\"urn:org:onap:appc:Test\">\n" +
 
 100             "                           <VnfFunction xmlns=\"urn:org:openecomop:appc:Test\">\n" +
 
 101             "                                  <ProcessorManagement>\n" +
 
 103             "                                                <operationalState/>\n" +
 
 104             "                                                <PayloadProcessor>\n" +
 
 105             "                                                       <operationalState/>\n" +
 
 106             "                                                </PayloadProcessor>\n" +
 
 108             "                                         <SystemController>\n" +
 
 109             "                                                <operationalState/>\n" +
 
 110             "                                         </SystemController>\n" +
 
 111             "                                  </ProcessorManagement>\n" +
 
 112             "                           </VnfFunction>\n" +
 
 113             "                     </ManagedElement>\n" +
 
 120     public void setUp() throws NoSuchFieldException, IllegalAccessException {
 
 121         clientFactory = new NetconfClientFactoryMock();
 
 126     public void testConfigure() throws Exception {
 
 128         SvcLogicContext ctx = new SvcLogicContext();
 
 130         params = new HashMap<>();
 
 131         params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
 
 132         params.put(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
 
 134         netconfClientPlugin.configure(params, ctx);
 
 136         NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
 
 139             Assert.assertEquals("wrong configuration", fileContent, client.getConf());
 
 140             Assert.assertEquals("wrong host", host, client.getLastConnectionDetails().getHost());
 
 141             Assert.assertEquals("wrong port", port, client.getLastConnectionDetails().getPort());
 
 142             Assert.assertEquals("wrong username", username, client.getLastConnectionDetails().getUsername());
 
 143             Assert.assertEquals("wrong password", password, client.getLastConnectionDetails().getPassword());
 
 144             Assert.assertFalse(client.isConnection());
 
 145         } catch (Exception e) {
 
 146             Assert.fail("failed with because of " + e.getCause());
 
 152     public void testConfigureNegativeIOException() throws Exception {
 
 154         SvcLogicContext ctx = new SvcLogicContext();
 
 156         params = new HashMap<>();
 
 157         params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
 
 158         params.put(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
 
 159         NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
 
 162             netconfClientPlugin.configure(params, ctx);
 
 163             Assert.assertTrue(false);
 
 164         } catch (APPCException e) {
 
 165             Assert.assertNull(client.getLastConnectionDetails());
 
 166             Assert.assertNull(client.getConf());
 
 172     public void testOperationStateValidation() throws Exception {
 
 174         SvcLogicContext ctx = new SvcLogicContext();
 
 175         DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
 
 176         daoServiceMock.setConfigFile(fileContent);
 
 178         NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
 
 179         client.setAnswer(operationalState);
 
 181         params = new HashMap<>();
 
 182         params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
 
 183         params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
 
 184         params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
 
 185         MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
 
 186         validatorMock.setConfigurationFileName("VnfGetRunningConfig");
 
 188         PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
 
 189         when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
 
 191         netconfClientPlugin.operationStateValidation(params, ctx);
 
 193         Assert.assertTrue("validation process failed", validatorMock.isValidated());
 
 194         Assert.assertEquals(fileContent, client.getLastMessage());
 
 198     public void testOperationStateValidationNegativeJsonProcessingNullIllegalStateException() throws Exception {
 
 200         SvcLogicContext ctx = new SvcLogicContext();
 
 201         DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
 
 202         daoServiceMock.setConfigFile(fileContent);
 
 204         NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
 
 205         client.setAnswer(operationalState);
 
 207         params = new HashMap<>();
 
 208         params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
 
 209         params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
 
 210         params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
 
 211         MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
 
 212         validatorMock.setConfigurationFileName("VnfGetRunningConfig");
 
 214         PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
 
 215         when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
 
 216         substituteMapper(true);
 
 219             netconfClientPlugin.operationStateValidation(params, ctx);
 
 220             substituteMapper(false);
 
 221         } catch (APPCException e) {
 
 222             substituteMapper(false);
 
 223             Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
 
 224             Assert.assertFalse(validatorMock.isValidated());
 
 225             Assert.assertNull(client.getLastMessage());
 
 230     public void testOperationStateValidationNegativeConnectionDetailsAreNullNullPointerException() throws Exception {
 
 232         SvcLogicContext ctx = new SvcLogicContext();
 
 233         DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
 
 234         daoServiceMock.setConfigFile(fileContent);
 
 236         NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
 
 237         client.setAnswer(operationalState);
 
 239         params = new HashMap<>();
 
 240         params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
 
 241         params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
 
 242         params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, null);
 
 243         MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
 
 244         validatorMock.setConfigurationFileName("VnfGetRunningConfig");
 
 246         PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
 
 247         when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
 
 248         ObjectMapper mapper = PowerMockito.mock(ObjectMapper.class);
 
 249         final NetconfConnectionDetails netconfConnectionDetails = null;
 
 250         when(mapper.readValue(Matchers.anyString(), Matchers.any(Class.class))).thenReturn(netconfConnectionDetails);
 
 253             netconfClientPlugin.operationStateValidation(params, ctx);
 
 254             Assert.assertTrue(false);
 
 255         } catch (APPCException e) {
 
 256             Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
 
 257             Assert.assertFalse("validation process failed", validatorMock.isValidated());
 
 263     public void testOperationStateValidationNegativeAppcException() throws Exception {
 
 265         SvcLogicContext ctx = new SvcLogicContext();
 
 266         DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
 
 267         daoServiceMock.setConfigFile(fileContent);
 
 269         NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
 
 270         client.setAnswer("wrong");
 
 272         params = new HashMap<>();
 
 273         params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
 
 274         params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
 
 275         params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
 
 276         MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
 
 277         validatorMock.setConfigurationFileName("VnfGetRunningConfig");
 
 279         PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
 
 280         when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
 
 283             netconfClientPlugin.operationStateValidation(params, ctx);
 
 284             Assert.assertTrue(false);
 
 285         } catch (APPCException e) {
 
 286             Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
 
 287             Assert.assertFalse("validation process failed", validatorMock.isValidated());
 
 293     public void testOperationStateValidatioConnectionDetailsInParamsAreEmpty() throws Exception {
 
 295         SvcLogicContext ctx = new SvcLogicContext();
 
 296         DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
 
 297         daoServiceMock.setConfigFile(fileContent);
 
 299         NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
 
 300         client.setAnswer(operationalState);
 
 301         ((DAOServiceMock) dao).setConnection(getConnectionDetails());
 
 303         params = new HashMap<>();
 
 304         params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
 
 305         params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
 
 306         params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "");
 
 307         MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
 
 308         validatorMock.setConfigurationFileName("VnfGetRunningConfig");
 
 310         PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
 
 311         when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
 
 313         netconfClientPlugin.operationStateValidation(params, ctx);
 
 315         Assert.assertTrue("validation process failed", validatorMock.isValidated());
 
 316         Assert.assertEquals(fileContent, client.getLastMessage());
 
 320     public void testOperationStateValidatioConnectionDetailsInParamsAreNull() throws Exception {
 
 322         SvcLogicContext ctx = new SvcLogicContext();
 
 323         DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
 
 324         daoServiceMock.setConfigFile(fileContent);
 
 326         NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
 
 327         client.setAnswer(operationalState);
 
 328         ((DAOServiceMock) dao).setConnection(getConnectionDetails());
 
 330         params = new HashMap<>();
 
 331         params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
 
 332         params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
 
 333         params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, null);
 
 334         MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
 
 335         validatorMock.setConfigurationFileName("VnfGetRunningConfig");
 
 337         PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
 
 338         when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
 
 340         netconfClientPlugin.operationStateValidation(params, ctx);
 
 342         Assert.assertTrue("validation process failed", validatorMock.isValidated());
 
 343         Assert.assertEquals(fileContent, client.getLastMessage());
 
 348     public void testBackupConfiguration() throws Exception {
 
 350         SvcLogicContext ctx = new SvcLogicContext();
 
 351         params = new HashMap<>();
 
 352         params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
 
 353         NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
 
 354         client.setConf(fileContent);
 
 355         netconfClientPlugin.backupConfiguration(params, ctx);
 
 357         DAOServiceMock mockdao = (DAOServiceMock) dao;
 
 358         DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
 
 359         Date date = new Date();
 
 360         String creationDateExpected = dateFormat.format(date);
 
 361         String creationDateActual = mockdao.getBackupConf().get("creationDate").substring(0, 10);
 
 363         Assert.assertEquals("wrong configuration in db", fileContent, mockdao.getBackupConf().get("logText"));
 
 364         Assert.assertEquals(creationDateExpected, creationDateActual);
 
 368     public void testBackupConfigurationNegativeDgErrorFieldName() throws Exception {
 
 370         SvcLogicContext ctx = new SvcLogicContext();
 
 371         params = new HashMap<>();
 
 372         params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
 
 373         NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
 
 374         client.setConf(fileContent);
 
 376             netconfClientPlugin.backupConfiguration(params, ctx);
 
 377             Assert.assertTrue(false);
 
 378         } catch (APPCException e) {
 
 379             Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
 
 380             DAOServiceMock mockdao = (DAOServiceMock) dao;
 
 381             Assert.assertNull(mockdao.getBackupConf());
 
 386     public void testGetConfig() throws Exception {
 
 388         String entity = "123";
 
 390         SvcLogicContext ctx = new SvcLogicContext();
 
 391         ctx.setAttribute("entity", entity);
 
 393         params = new HashMap<>();
 
 394         params.put("conf-id", "current");
 
 395         params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
 
 396         NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
 
 397         client.setConf(fileContent);
 
 399         netconfClientPlugin.getConfig(params, ctx);
 
 401         Assert.assertEquals("Success", ctx.getAttribute("getConfig_Result"));
 
 402         Assert.assertEquals(fileContent, ctx.getAttribute("fullConfig"));
 
 403         Assert.assertNotNull(ctx.getAttribute(entity + ".Configuration"));
 
 404         Assert.assertEquals(fileContent, ctx.getAttribute(entity + ".Configuration"));
 
 409     public void testGetConfigNegativeConfigurationNull() throws Exception {
 
 411         String entity = "123";
 
 413         SvcLogicContext ctx = new SvcLogicContext();
 
 414         ctx.setAttribute("entity", entity);
 
 416         params = new HashMap<>();
 
 417         params.put("conf-id", "current");
 
 418         params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
 
 420         netconfClientPlugin.getConfig(params, ctx);
 
 422         Assert.assertEquals("failure", ctx.getAttribute("getConfig_Result"));
 
 423         Assert.assertNull(ctx.getAttribute("fullConfig"));
 
 424         Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
 
 425         Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
 
 430     public void testGetConfigNegativeNotSupportedConfId() throws Exception {
 
 432         String entity = "123";
 
 433         SvcLogicContext ctx = new SvcLogicContext();
 
 434         ctx.setAttribute("entity", entity);
 
 436         params = new HashMap<>();
 
 437         params.put("conf-id", "current1");
 
 438         params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
 
 440         netconfClientPlugin.getConfig(params, ctx);
 
 442         Assert.assertNull(ctx.getAttribute("getConfig_Result"));
 
 443         Assert.assertNull(ctx.getAttribute("fullConfig"));
 
 444         Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
 
 445         Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
 
 449     public void testGetConfigNegativeWronjJsonConnectionDetailsException() throws Exception {
 
 451         String entity = "123";
 
 453         SvcLogicContext ctx = new SvcLogicContext();
 
 454         ctx.setAttribute("entity", entity);
 
 456         params = new HashMap<>();
 
 457         params.put("conf-id", "current");
 
 458         params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
 
 461             netconfClientPlugin.getConfig(params, ctx);
 
 462             Assert.assertTrue(false);
 
 463         } catch (APPCException e) {
 
 464             Assert.assertEquals("failure", ctx.getAttribute("getConfig_Result"));
 
 465             Assert.assertNull(ctx.getAttribute("fullConfig"));
 
 466             Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
 
 467             Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
 
 468             Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
 
 473     public void testGetRunningConfig() throws Exception {
 
 475         SvcLogicContext ctx = new SvcLogicContext();
 
 476         params = new HashMap<>();
 
 477         params.put("host-ip-address", host);
 
 478         params.put("user-name", username);
 
 479         params.put("password", password);
 
 480         params.put("port-number", String.valueOf(port));
 
 482         NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
 
 483         client.setConf(fileContent);
 
 485         netconfClientPlugin.getRunningConfig(params, ctx);
 
 487         Assert.assertEquals("Success", ctx.getAttribute("getRunningConfig_Result"));
 
 488         Assert.assertEquals(fileContent, ctx.getAttribute("running-config"));
 
 489         Assert.assertEquals("success", ctx.getStatus());
 
 493     public void testGetRunningConfigWithoutPortNumberDgErrorFieldNameException() throws Exception {
 
 495         SvcLogicContext ctx = new SvcLogicContext();
 
 496         params = new HashMap<>();
 
 497         params.put("host-ip-address", host);
 
 498         params.put("user-name", username);
 
 499         params.put("password", password);
 
 501         NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
 
 502         client.setConf(fileContent);
 
 505             netconfClientPlugin.getRunningConfig(params, ctx);
 
 506             Assert.assertTrue(false);
 
 507         } catch (APPCException e) {
 
 508             Assert.assertEquals("failure", ctx.getAttribute("getRunningConfig_Result"));
 
 509             Assert.assertNull(ctx.getAttribute("running-config"));
 
 510             Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
 
 515     public void testGetRunningConfigNegativeConfigurationNull() throws Exception {
 
 517         SvcLogicContext ctx = new SvcLogicContext();
 
 518         params = new HashMap<>();
 
 519         params.put("host-ip-address", host);
 
 520         params.put("user-name", username);
 
 521         params.put("password", password);
 
 522         params.put("port-number", String.valueOf(port));
 
 524         netconfClientPlugin.getRunningConfig(params, ctx);
 
 526         Assert.assertEquals("failure", ctx.getAttribute("getRunningConfig_Result"));
 
 527         Assert.assertNull(ctx.getAttribute("running-config"));
 
 531     public void testValidateMandatoryParamNegativeEmptyParamValue() throws Exception {
 
 533         String paramName = "test";
 
 534         String paramValue = "";
 
 537             netconfClientPlugin.validateMandatoryParam(paramName, paramValue);
 
 538             Assert.assertTrue(false);
 
 539         } catch (Exception e) {
 
 540             Assert.assertTrue(true);
 
 545     public void testRetrieveConnectionDetails() throws Exception {
 
 547         DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
 
 548         daoServiceMock.setConfigFile(fileContent);
 
 549         ConnectionDetails connectionDetails1 = getConnectionDetails();
 
 550         daoServiceMock.setConnection(connectionDetails1);
 
 552         NetconfConnectionDetails connectionDetailsActual = netconfClientPlugin.retrieveConnectionDetails(VnfType.VNF);
 
 554         Assert.assertEquals("wrong host", connectionDetails1.getHost(), connectionDetailsActual.getHost());
 
 555         Assert.assertEquals("wrong password", connectionDetails1.getPassword(), connectionDetailsActual.getPassword());
 
 556         Assert.assertEquals("wrong port", connectionDetails1.getPort(), connectionDetailsActual.getPort());
 
 557         Assert.assertEquals("wrong usename", connectionDetails1.getUsername(), connectionDetailsActual.getUsername());
 
 562     public void testRetrieveConnectionDetailsNegativeMissingConfiguration() throws Exception {
 
 564         DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
 
 565         daoServiceMock.setConfigFile(fileContent);
 
 566         ConnectionDetails connectionDetails1 = getConnectionDetails();
 
 567         daoServiceMock.setConnection(connectionDetails1);
 
 569         NetconfConnectionDetails connectionDetailsActual = null;
 
 571             connectionDetailsActual = netconfClientPlugin.retrieveConnectionDetails(VnfType.MOCK);
 
 572             Assert.assertTrue(false);
 
 573         } catch (APPCException e) {
 
 574             Assert.assertNull(connectionDetailsActual);
 
 579     public void testRetrieveConfigurationFileContent() throws Exception {
 
 582         DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
 
 583         daoServiceMock.setConfigFile(fileContent);
 
 585         Assert.assertEquals("wrong config in a database", fileContent, netconfClientPlugin.retrieveConfigurationFileContent("VnfGetRunningConfig"));
 
 588     private ConnectionDetails getConnectionDetails() {
 
 589         ConnectionDetails connectionDetails = new ConnectionDetails();
 
 590         connectionDetails.setPassword(password);
 
 591         connectionDetails.setPort(port);
 
 592         connectionDetails.setUsername(username);
 
 593         connectionDetails.setHost(host);
 
 594         return connectionDetails;
 
 598     private void initDao() throws NoSuchFieldException, IllegalAccessException {
 
 599         dao = new DAOServiceMock();
 
 600         PowerMockito.mockStatic(FrameworkUtil.class);
 
 601         when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
 
 602         when(bundleService.getBundleContext()).thenReturn(bundleContext);
 
 603         when(bundleContext.getServiceReference(NetconfDataAccessService.class)).thenReturn(sref1);
 
 604         when(bundleContext.getService(sref1)).thenReturn(dao);
 
 607     private void fullInit() throws NoSuchFieldException, IllegalAccessException {
 
 609         initClientFactory2();
 
 611         netconfClientPlugin = new NetconfClientPluginImpl();
 
 612         netconfClientPlugin.setDao(this.dao);
 
 615     private void shortInit() throws NoSuchFieldException, IllegalAccessException {
 
 618         netconfClientPlugin = new NetconfClientPluginImpl();
 
 619         netconfClientPlugin.setDao(this.dao);
 
 622     private void initClientFactory() throws NoSuchFieldException, IllegalAccessException {
 
 623         PowerMockito.mockStatic(FrameworkUtil.class);
 
 624         when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
 
 625         when(bundleService.getBundleContext()).thenReturn(bundleContext);
 
 626         when(bundleContext.getServiceReference(NetconfClientFactory.class)).thenReturn(sref2);
 
 627         when(bundleContext.getService(sref2)).thenReturn(clientFactory);
 
 630     private void initClientFactory2() {
 
 631         PowerMockito.mockStatic(FrameworkUtil.class);
 
 632         when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
 
 633         when(bundleService.getBundleContext()).thenReturn(bundleContext);
 
 634         when(bundleContext.getServiceReference(Matchers.anyString())).thenReturn(sref3);
 
 635         when(bundleContext.getService(sref3)).thenReturn(clientFactory);
 
 638     private void substituteMapper(boolean command) throws NoSuchFieldException, IllegalAccessException {
 
 639         ObjectMapper mapper = new ObjectMapperMock();
 
 640         ObjectMapper mapper2 = new ObjectMapper();
 
 641         Field field = NetconfClientPluginImpl.class.getDeclaredField("mapper");
 
 642         field.setAccessible(true);
 
 644             field.set(netconfClientPlugin, mapper);
 
 646             field.set(netconfClientPlugin, mapper2);