2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.openecomp.appc.dg.netconf.impl;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import org.junit.Assert;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.mockito.Matchers;
30 import org.mockito.Mockito;
31 import org.openecomp.appc.adapter.netconf.*;
32 import org.openecomp.appc.adapter.netconf.util.Constants;
33 import org.openecomp.appc.dg.netconf.impl.NetconfClientPluginImpl;
34 import org.openecomp.appc.exceptions.APPCException;
35 import org.openecomp.sdnc.sli.SvcLogicContext;
36 import org.osgi.framework.Bundle;
37 import org.osgi.framework.BundleContext;
38 import org.osgi.framework.FrameworkUtil;
39 import org.osgi.framework.ServiceReference;
40 import org.powermock.api.mockito.PowerMockito;
41 import org.powermock.core.classloader.annotations.PrepareForTest;
42 import org.powermock.modules.junit4.PowerMockRunner;
44 import java.lang.reflect.Field;
45 import java.text.DateFormat;
46 import java.text.SimpleDateFormat;
47 import java.util.Date;
48 import java.util.HashMap;
51 import static org.powermock.api.mockito.PowerMockito.when;
55 @RunWith(PowerMockRunner.class)
56 @PrepareForTest({OperationalStateValidatorFactory.class, NetconfClientPluginImpl.class, FrameworkUtil.class, ObjectMapper.class})
58 public class NetconfClientPluginImplTest {
59 private NetconfClientPluginImpl netconfClientPlugin;
60 private NetconfDataAccessService dao;
61 private NetconfClientFactory clientFactory;
62 private Map<String, String> params;
64 private final BundleContext bundleContext = Mockito.mock(BundleContext.class);
65 private final Bundle bundleService = Mockito.mock(Bundle.class);
66 private final ServiceReference sref1 = Mockito.mock(ServiceReference.class);
67 private final ServiceReference sref2 = Mockito.mock(ServiceReference.class);
68 private final ServiceReference sref3 = Mockito.mock(ServiceReference.class);
69 private static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message";
72 String host = "http://www.test.com";
73 String host1 = "http://www.test1.com";
74 String vnfType = "VNF";
76 String username = "test";
77 String password = "test";
78 String connectionDetails = "{\"host\":\"" + host + "\",\"port\":" + port + ",\"username\":\"" + username + "\",\"password\":\"" + password + "\",\"capabilities\":null,\"additionalProperties\":null}";
79 String fileContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
80 "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
83 "\t\t\t<running/>\n" +
87 String operationalState = "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
90 " <ManagedElement xmlns=\"urn:org:openecomp:appc:Test\">\n" +
91 " <VnfFunction xmlns=\"urn:org:openecomop:appc:Test\">\n" +
92 " <ProcessorManagement>\n" +
94 " <operationalState/>\n" +
95 " <PayloadProcessor>\n" +
96 " <operationalState/>\n" +
97 " </PayloadProcessor>\n" +
99 " <SystemController>\n" +
100 " <operationalState/>\n" +
101 " </SystemController>\n" +
102 " </ProcessorManagement>\n" +
103 " </VnfFunction>\n" +
104 " </ManagedElement>\n" +
111 public void setUp() throws NoSuchFieldException, IllegalAccessException {
112 clientFactory = new NetconfClientFactoryMock();
118 public void testConfigure() throws Exception {
121 SvcLogicContext ctx = new SvcLogicContext();
123 params = new HashMap<>();
124 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
125 params.put(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
127 netconfClientPlugin.configure(params, ctx);
129 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
132 Assert.assertEquals("wrong configuration", fileContent, client.getConf());
133 Assert.assertEquals("wrong host", host, client.getLastConnectionDetails().getHost());
134 Assert.assertEquals("wrong port", port, client.getLastConnectionDetails().getPort());
135 Assert.assertEquals("wrong username", username, client.getLastConnectionDetails().getUsername());
136 Assert.assertEquals("wrong password", password, client.getLastConnectionDetails().getPassword());
137 Assert.assertFalse(client.isConnection());
138 } catch (Exception e) {
139 Assert.fail("failed with because of " + e.getCause());
147 public void testConfigureNegativeIOException() throws Exception {
149 SvcLogicContext ctx = new SvcLogicContext();
151 params = new HashMap<>();
152 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
153 params.put(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
154 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
158 netconfClientPlugin.configure(params, ctx);
159 Assert.assertTrue(false);
160 } catch (APPCException e) {
161 Assert.assertNull(client.getLastConnectionDetails());
162 Assert.assertNull(client.getConf());
168 public void testOperationStateValidation() throws Exception {
170 SvcLogicContext ctx = new SvcLogicContext();
171 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
172 daoServiceMock.setConfigFile(fileContent);
174 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
175 client.setAnswer(operationalState);
178 params = new HashMap<>();
179 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
180 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
181 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
182 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
183 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
185 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
186 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
188 netconfClientPlugin.operationStateValidation(params, ctx);
190 Assert.assertTrue("validation process failed", validatorMock.isValidated());
191 Assert.assertEquals(fileContent, client.getLastMessage());
196 public void testOperationStateValidationNegativeJsonProcessingNullIllegalStateException() throws Exception {
198 SvcLogicContext ctx = new SvcLogicContext();
199 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
200 daoServiceMock.setConfigFile(fileContent);
202 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
203 client.setAnswer(operationalState);
205 params = new HashMap<>();
206 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
207 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
208 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
209 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
210 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
212 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
213 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
214 substituteMapper(true);
217 netconfClientPlugin.operationStateValidation(params, ctx);
218 substituteMapper(false);
219 } catch (APPCException e) {
220 substituteMapper(false);
221 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
222 Assert.assertFalse(validatorMock.isValidated());
223 Assert.assertNull(client.getLastMessage());
228 public void testOperationStateValidationNegativeConnectionDetailsAreNullNullPointerException() throws Exception {
230 SvcLogicContext ctx = new SvcLogicContext();
231 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
232 daoServiceMock.setConfigFile(fileContent);
234 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
235 client.setAnswer(operationalState);
238 params = new HashMap<>();
239 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
240 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
241 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, null);
242 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
243 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
245 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
246 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
247 ObjectMapper mapper = PowerMockito.mock(ObjectMapper.class);
248 final NetconfConnectionDetails netconfConnectionDetails = null;
249 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());
264 public void testOperationStateValidationNegativeAppcException() throws Exception {
266 SvcLogicContext ctx = new SvcLogicContext();
267 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
268 daoServiceMock.setConfigFile(fileContent);
270 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
271 client.setAnswer("wrong");
274 params = new HashMap<>();
275 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
276 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
277 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
278 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
279 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
281 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
282 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
286 netconfClientPlugin.operationStateValidation(params, ctx);
287 Assert.assertTrue(false);
288 } catch (APPCException e) {
289 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
290 Assert.assertFalse("validation process failed", validatorMock.isValidated());
297 public void testOperationStateValidatioConnectionDetailsInParamsAreEmpty() throws Exception {
299 SvcLogicContext ctx = new SvcLogicContext();
300 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
301 daoServiceMock.setConfigFile(fileContent);
303 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
304 client.setAnswer(operationalState);
305 ((DAOServiceMock) dao).setConnection(getConnectionDetails());
308 params = new HashMap<>();
309 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
310 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
311 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "");
312 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
313 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
315 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
316 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
318 netconfClientPlugin.operationStateValidation(params, ctx);
320 Assert.assertTrue("validation process failed", validatorMock.isValidated());
321 Assert.assertEquals(fileContent, client.getLastMessage());
325 public void testOperationStateValidatioConnectionDetailsInParamsAreNull() throws Exception {
327 SvcLogicContext ctx = new SvcLogicContext();
328 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
329 daoServiceMock.setConfigFile(fileContent);
331 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
332 client.setAnswer(operationalState);
333 ((DAOServiceMock) dao).setConnection(getConnectionDetails());
336 params = new HashMap<>();
337 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
338 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
339 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, null);
340 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
341 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
343 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
344 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
346 netconfClientPlugin.operationStateValidation(params, ctx);
348 Assert.assertTrue("validation process failed", validatorMock.isValidated());
349 Assert.assertEquals(fileContent, client.getLastMessage());
354 public void testBackupConfiguration() throws Exception {
356 SvcLogicContext ctx = new SvcLogicContext();
357 params = new HashMap<>();
358 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
359 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
360 client.setConf(fileContent);
361 netconfClientPlugin.backupConfiguration(params, ctx);
363 DAOServiceMock mockdao = (DAOServiceMock) dao;
364 DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
365 Date date = new Date();
366 String creationDateExpected = dateFormat.format(date);
367 String creationDateActual = mockdao.getBackupConf().get("creationDate").substring(0, 10);
370 Assert.assertEquals("wrong configuration in db", fileContent, mockdao.getBackupConf().get("logText"));
371 Assert.assertEquals(creationDateExpected, creationDateActual);
378 public void testBackupConfigurationNegativeDgErrorFieldName() throws Exception {
380 SvcLogicContext ctx = new SvcLogicContext();
381 params = new HashMap<>();
382 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
383 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
384 client.setConf(fileContent);
386 netconfClientPlugin.backupConfiguration(params, ctx);
387 Assert.assertTrue(false);
388 } catch (APPCException e) {
389 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
391 DAOServiceMock mockdao = (DAOServiceMock) dao;
392 Assert.assertNull(mockdao.getBackupConf());
398 public void testGetConfig() throws Exception {
400 String entity = "123";
402 SvcLogicContext ctx = new SvcLogicContext();
403 ctx.setAttribute("entity", entity);
405 params = new HashMap<>();
406 params.put("conf-id", "current");
407 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
408 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
409 client.setConf(fileContent);
412 netconfClientPlugin.getConfig(params, ctx);
414 Assert.assertEquals("Success", ctx.getAttribute("getConfig_Result"));
415 Assert.assertEquals(fileContent, ctx.getAttribute("fullConfig"));
416 Assert.assertNotNull(ctx.getAttribute(entity + ".Configuration"));
417 Assert.assertEquals(fileContent, ctx.getAttribute(entity + ".Configuration"));
422 public void testGetConfigNegativeConfigurationNull() throws Exception {
424 String entity = "123";
426 SvcLogicContext ctx = new SvcLogicContext();
427 ctx.setAttribute("entity", entity);
429 params = new HashMap<>();
430 params.put("conf-id", "current");
431 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
434 netconfClientPlugin.getConfig(params, ctx);
436 Assert.assertEquals("failure", ctx.getAttribute("getConfig_Result"));
437 Assert.assertNull(ctx.getAttribute("fullConfig"));
438 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
439 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
444 public void testGetConfigNegativeNotSupportedConfId() throws Exception {
446 String entity = "123";
447 SvcLogicContext ctx = new SvcLogicContext();
448 ctx.setAttribute("entity", entity);
450 params = new HashMap<>();
451 params.put("conf-id", "current1");
452 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
455 netconfClientPlugin.getConfig(params, ctx);
457 Assert.assertNull(ctx.getAttribute("getConfig_Result"));
458 Assert.assertNull(ctx.getAttribute("fullConfig"));
459 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
460 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
464 public void testGetConfigNegativeWronjJsonConnectionDetailsException() throws Exception {
466 String entity = "123";
468 SvcLogicContext ctx = new SvcLogicContext();
469 ctx.setAttribute("entity", entity);
471 params = new HashMap<>();
472 params.put("conf-id", "current");
473 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
477 netconfClientPlugin.getConfig(params, ctx);
478 Assert.assertTrue(false);
479 } catch (APPCException e) {
480 Assert.assertEquals("failure", ctx.getAttribute("getConfig_Result"));
481 Assert.assertNull(ctx.getAttribute("fullConfig"));
482 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
483 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
484 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
491 public void testGetRunningConfig() throws Exception {
493 SvcLogicContext ctx = new SvcLogicContext();
494 params = new HashMap<>();
495 params.put("host-ip-address", host);
496 params.put("user-name", username);
497 params.put("password", password);
498 params.put("port-number", String.valueOf(port));
500 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
501 client.setConf(fileContent);
503 netconfClientPlugin.getRunningConfig(params, ctx);
505 Assert.assertEquals("Success", ctx.getAttribute("getRunningConfig_Result"));
506 Assert.assertEquals(fileContent, ctx.getAttribute("running-config"));
507 Assert.assertEquals("success", ctx.getStatus());
511 public void testGetRunningConfigWithoutPortNumberDgErrorFieldNameException() throws Exception {
513 SvcLogicContext ctx = new SvcLogicContext();
514 params = new HashMap<>();
515 params.put("host-ip-address", host);
516 params.put("user-name", username);
517 params.put("password", password);
519 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
520 client.setConf(fileContent);
523 netconfClientPlugin.getRunningConfig(params, ctx);
524 Assert.assertTrue(false);
525 } catch (APPCException e) {
526 Assert.assertEquals("failure", ctx.getAttribute("getRunningConfig_Result"));
527 Assert.assertNull(ctx.getAttribute("running-config"));
528 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
535 public void testGetRunningConfigNegativeConfigurationNull() throws Exception {
537 SvcLogicContext ctx = new SvcLogicContext();
538 params = new HashMap<>();
539 params.put("host-ip-address", host);
540 params.put("user-name", username);
541 params.put("password", password);
542 params.put("port-number", String.valueOf(port));
544 netconfClientPlugin.getRunningConfig(params, ctx);
546 Assert.assertEquals("failure", ctx.getAttribute("getRunningConfig_Result"));
547 Assert.assertNull(ctx.getAttribute("running-config"));
551 public void testValidateMandatoryParamNegativeEmptyParamValue() throws Exception {
553 String paramName = "test";
554 String paramValue = "";
557 netconfClientPlugin.validateMandatoryParam(paramName, paramValue);
558 Assert.assertTrue(false);
559 } catch (Exception e) {
560 Assert.assertTrue(true);
565 public void testRetrieveConnectionDetails() throws Exception {
567 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
568 daoServiceMock.setConfigFile(fileContent);
569 ConnectionDetails connectionDetails1 = getConnectionDetails();
570 daoServiceMock.setConnection(connectionDetails1);
572 NetconfConnectionDetails connectionDetailsActual = netconfClientPlugin.retrieveConnectionDetails(VnfType.VNF);
575 Assert.assertEquals("wrong host", connectionDetails1.getHost(), connectionDetailsActual.getHost());
576 Assert.assertEquals("wrong password", connectionDetails1.getPassword(), connectionDetailsActual.getPassword());
577 Assert.assertEquals("wrong port", connectionDetails1.getPort(), connectionDetailsActual.getPort());
578 Assert.assertEquals("wrong usename", connectionDetails1.getUsername(), connectionDetailsActual.getUsername());
583 public void testRetrieveConnectionDetailsNegativeMissingConfiguration() throws Exception {
585 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
586 daoServiceMock.setConfigFile(fileContent);
587 ConnectionDetails connectionDetails1 = getConnectionDetails();
588 daoServiceMock.setConnection(connectionDetails1);
590 NetconfConnectionDetails connectionDetailsActual = null;
592 connectionDetailsActual = netconfClientPlugin.retrieveConnectionDetails(VnfType.MOCK);
593 Assert.assertTrue(false);
594 } catch (APPCException e) {
595 Assert.assertNull(connectionDetailsActual);
602 public void testRetrieveConfigurationFileContent() throws Exception {
605 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
606 daoServiceMock.setConfigFile(fileContent);
608 Assert.assertEquals("wrong config in a database", fileContent, netconfClientPlugin.retrieveConfigurationFileContent("VnfGetRunningConfig"));
611 private ConnectionDetails getConnectionDetails() {
613 ConnectionDetails connectionDetails = new ConnectionDetails();
614 connectionDetails.setPassword(password);
615 connectionDetails.setPort(port);
616 connectionDetails.setUsername(username);
617 connectionDetails.setHost(host);
618 return connectionDetails;
622 private void initDao() throws NoSuchFieldException, IllegalAccessException {
623 dao = new DAOServiceMock();
624 PowerMockito.mockStatic(FrameworkUtil.class);
625 when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
626 when(bundleService.getBundleContext()).thenReturn(bundleContext);
627 when(bundleContext.getServiceReference(NetconfDataAccessService.class)).thenReturn(sref1);
628 when(bundleContext.getService(sref1)).thenReturn(dao);
633 private void fullInit() throws NoSuchFieldException, IllegalAccessException {
635 initClientFactory2();
637 netconfClientPlugin = new NetconfClientPluginImpl();
638 netconfClientPlugin.setDao(this.dao);
641 private void shortInit() throws NoSuchFieldException, IllegalAccessException {
644 netconfClientPlugin = new NetconfClientPluginImpl();
645 netconfClientPlugin.setDao(this.dao);
648 private void initClientFactory() throws NoSuchFieldException, IllegalAccessException {
650 PowerMockito.mockStatic(FrameworkUtil.class);
651 when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
652 when(bundleService.getBundleContext()).thenReturn(bundleContext);
653 when(bundleContext.getServiceReference(NetconfClientFactory.class)).thenReturn(sref2);
654 when(bundleContext.getService(sref2)).thenReturn(clientFactory);
658 private void initClientFactory2() {
659 PowerMockito.mockStatic(FrameworkUtil.class);
660 when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
661 when(bundleService.getBundleContext()).thenReturn(bundleContext);
662 when(bundleContext.getServiceReference(Matchers.anyString())).thenReturn(sref3);
663 when(bundleContext.getService(sref3)).thenReturn(clientFactory);
666 private void substituteMapper(boolean command) throws NoSuchFieldException, IllegalAccessException {
667 ObjectMapper mapper = new ObjectMapperMock();
668 ObjectMapper mapper2 = new ObjectMapper();
669 Field field = NetconfClientPluginImpl.class.getDeclaredField("mapper");
670 field.setAccessible(true);
672 field.set(netconfClientPlugin, mapper);
674 field.set(netconfClientPlugin, mapper2);