2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.dg.netconf.impl;
27 import org.onap.appc.exceptions.APPCException;
28 import com.fasterxml.jackson.databind.ObjectMapper;
29 import org.junit.Assert;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.Matchers;
34 import org.mockito.Mockito;
35 import org.onap.appc.adapter.netconf.*;
36 import org.onap.appc.adapter.netconf.util.Constants;
37 import org.onap.appc.dg.netconf.impl.NetconfClientPluginImpl;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
39 import org.osgi.framework.Bundle;
40 import org.osgi.framework.BundleContext;
41 import org.osgi.framework.FrameworkUtil;
42 import org.osgi.framework.ServiceReference;
43 import org.powermock.api.mockito.PowerMockito;
44 import org.powermock.core.classloader.annotations.PrepareForTest;
45 import org.powermock.modules.junit4.PowerMockRunner;
47 import java.lang.reflect.Field;
48 import java.text.DateFormat;
49 import java.text.SimpleDateFormat;
50 import java.util.Date;
51 import java.util.HashMap;
54 import static org.powermock.api.mockito.PowerMockito.when;
58 @RunWith(PowerMockRunner.class)
59 @PrepareForTest({OperationalStateValidatorFactory.class, NetconfClientPluginImpl.class, FrameworkUtil.class, ObjectMapper.class})
61 public class NetconfClientPluginImplTest {
62 private NetconfClientPluginImpl netconfClientPlugin;
63 private NetconfDataAccessService dao;
64 private NetconfClientFactory clientFactory;
65 private Map<String, String> params;
67 private final BundleContext bundleContext = Mockito.mock(BundleContext.class);
68 private final Bundle bundleService = Mockito.mock(Bundle.class);
69 private final ServiceReference sref1 = Mockito.mock(ServiceReference.class);
70 private final ServiceReference sref2 = Mockito.mock(ServiceReference.class);
71 private final ServiceReference sref3 = Mockito.mock(ServiceReference.class);
72 private static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message";
75 String host = "http://www.test.com";
76 String host1 = "http://www.test1.com";
77 String vnfType = "VNF";
79 String username = "test";
80 String password = "test";
81 String connectionDetails = "{\"host\":\"" + host + "\",\"port\":" + port + ",\"username\":\"" + username + "\",\"password\":\"" + password + "\",\"capabilities\":null,\"additionalProperties\":null}";
82 String fileContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
83 "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
86 "\t\t\t<running/>\n" +
90 String operationalState = "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
93 " <ManagedElement xmlns=\"urn:org:onap:appc:Test\">\n" +
94 " <VnfFunction xmlns=\"urn:org:openecomop:appc:Test\">\n" +
95 " <ProcessorManagement>\n" +
97 " <operationalState/>\n" +
98 " <PayloadProcessor>\n" +
99 " <operationalState/>\n" +
100 " </PayloadProcessor>\n" +
102 " <SystemController>\n" +
103 " <operationalState/>\n" +
104 " </SystemController>\n" +
105 " </ProcessorManagement>\n" +
106 " </VnfFunction>\n" +
107 " </ManagedElement>\n" +
114 public void setUp() throws NoSuchFieldException, IllegalAccessException {
115 clientFactory = new NetconfClientFactoryMock();
121 public void testConfigure() throws Exception {
124 SvcLogicContext ctx = new SvcLogicContext();
126 params = new HashMap<>();
127 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
128 params.put(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
130 netconfClientPlugin.configure(params, ctx);
132 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
135 Assert.assertEquals("wrong configuration", fileContent, client.getConf());
136 Assert.assertEquals("wrong host", host, client.getLastConnectionDetails().getHost());
137 Assert.assertEquals("wrong port", port, client.getLastConnectionDetails().getPort());
138 Assert.assertEquals("wrong username", username, client.getLastConnectionDetails().getUsername());
139 Assert.assertEquals("wrong password", password, client.getLastConnectionDetails().getPassword());
140 Assert.assertFalse(client.isConnection());
141 } catch (Exception e) {
142 Assert.fail("failed with because of " + e.getCause());
150 public void testConfigureNegativeIOException() throws Exception {
152 SvcLogicContext ctx = new SvcLogicContext();
154 params = new HashMap<>();
155 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
156 params.put(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
157 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
161 netconfClientPlugin.configure(params, ctx);
162 Assert.assertTrue(false);
163 } catch (APPCException e) {
164 Assert.assertNull(client.getLastConnectionDetails());
165 Assert.assertNull(client.getConf());
171 public void testOperationStateValidation() throws Exception {
173 SvcLogicContext ctx = new SvcLogicContext();
174 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
175 daoServiceMock.setConfigFile(fileContent);
177 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
178 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());
199 public void testOperationStateValidationNegativeJsonProcessingNullIllegalStateException() throws Exception {
201 SvcLogicContext ctx = new SvcLogicContext();
202 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
203 daoServiceMock.setConfigFile(fileContent);
205 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
206 client.setAnswer(operationalState);
208 params = new HashMap<>();
209 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
210 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
211 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
212 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
213 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
215 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
216 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
217 substituteMapper(true);
220 netconfClientPlugin.operationStateValidation(params, ctx);
221 substituteMapper(false);
222 } catch (APPCException e) {
223 substituteMapper(false);
224 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
225 Assert.assertFalse(validatorMock.isValidated());
226 Assert.assertNull(client.getLastMessage());
231 public void testOperationStateValidationNegativeConnectionDetailsAreNullNullPointerException() throws Exception {
233 SvcLogicContext ctx = new SvcLogicContext();
234 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
235 daoServiceMock.setConfigFile(fileContent);
237 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
238 client.setAnswer(operationalState);
241 params = new HashMap<>();
242 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
243 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
244 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, null);
245 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
246 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
248 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
249 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
250 ObjectMapper mapper = PowerMockito.mock(ObjectMapper.class);
251 final NetconfConnectionDetails netconfConnectionDetails = null;
252 when(mapper.readValue(Matchers.anyString(), Matchers.any(Class.class))).thenReturn(netconfConnectionDetails);
256 netconfClientPlugin.operationStateValidation(params, ctx);
257 Assert.assertTrue(false);
258 } catch (APPCException e) {
259 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
260 Assert.assertFalse("validation process failed", validatorMock.isValidated());
267 public void testOperationStateValidationNegativeAppcException() throws Exception {
269 SvcLogicContext ctx = new SvcLogicContext();
270 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
271 daoServiceMock.setConfigFile(fileContent);
273 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
274 client.setAnswer("wrong");
277 params = new HashMap<>();
278 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
279 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
280 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
281 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
282 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
284 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
285 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
289 netconfClientPlugin.operationStateValidation(params, ctx);
290 Assert.assertTrue(false);
291 } catch (APPCException e) {
292 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
293 Assert.assertFalse("validation process failed", validatorMock.isValidated());
300 public void testOperationStateValidatioConnectionDetailsInParamsAreEmpty() throws Exception {
302 SvcLogicContext ctx = new SvcLogicContext();
303 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
304 daoServiceMock.setConfigFile(fileContent);
306 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
307 client.setAnswer(operationalState);
308 ((DAOServiceMock) dao).setConnection(getConnectionDetails());
311 params = new HashMap<>();
312 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
313 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
314 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "");
315 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
316 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
318 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
319 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
321 netconfClientPlugin.operationStateValidation(params, ctx);
323 Assert.assertTrue("validation process failed", validatorMock.isValidated());
324 Assert.assertEquals(fileContent, client.getLastMessage());
328 public void testOperationStateValidatioConnectionDetailsInParamsAreNull() throws Exception {
330 SvcLogicContext ctx = new SvcLogicContext();
331 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
332 daoServiceMock.setConfigFile(fileContent);
334 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
335 client.setAnswer(operationalState);
336 ((DAOServiceMock) dao).setConnection(getConnectionDetails());
339 params = new HashMap<>();
340 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
341 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
342 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, null);
343 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
344 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
346 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
347 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
349 netconfClientPlugin.operationStateValidation(params, ctx);
351 Assert.assertTrue("validation process failed", validatorMock.isValidated());
352 Assert.assertEquals(fileContent, client.getLastMessage());
357 public void testBackupConfiguration() throws Exception {
359 SvcLogicContext ctx = new SvcLogicContext();
360 params = new HashMap<>();
361 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
362 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
363 client.setConf(fileContent);
364 netconfClientPlugin.backupConfiguration(params, ctx);
366 DAOServiceMock mockdao = (DAOServiceMock) dao;
367 DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
368 Date date = new Date();
369 String creationDateExpected = dateFormat.format(date);
370 String creationDateActual = mockdao.getBackupConf().get("creationDate").substring(0, 10);
373 Assert.assertEquals("wrong configuration in db", fileContent, mockdao.getBackupConf().get("logText"));
374 Assert.assertEquals(creationDateExpected, creationDateActual);
381 public void testBackupConfigurationNegativeDgErrorFieldName() throws Exception {
383 SvcLogicContext ctx = new SvcLogicContext();
384 params = new HashMap<>();
385 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
386 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
387 client.setConf(fileContent);
389 netconfClientPlugin.backupConfiguration(params, ctx);
390 Assert.assertTrue(false);
391 } catch (APPCException e) {
392 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
394 DAOServiceMock mockdao = (DAOServiceMock) dao;
395 Assert.assertNull(mockdao.getBackupConf());
401 public void testGetConfig() throws Exception {
403 String entity = "123";
405 SvcLogicContext ctx = new SvcLogicContext();
406 ctx.setAttribute("entity", entity);
408 params = new HashMap<>();
409 params.put("conf-id", "current");
410 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
411 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
412 client.setConf(fileContent);
415 netconfClientPlugin.getConfig(params, ctx);
417 Assert.assertEquals("Success", ctx.getAttribute("getConfig_Result"));
418 Assert.assertEquals(fileContent, ctx.getAttribute("fullConfig"));
419 Assert.assertNotNull(ctx.getAttribute(entity + ".Configuration"));
420 Assert.assertEquals(fileContent, ctx.getAttribute(entity + ".Configuration"));
425 public void testGetConfigNegativeConfigurationNull() throws Exception {
427 String entity = "123";
429 SvcLogicContext ctx = new SvcLogicContext();
430 ctx.setAttribute("entity", entity);
432 params = new HashMap<>();
433 params.put("conf-id", "current");
434 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
437 netconfClientPlugin.getConfig(params, ctx);
439 Assert.assertEquals("failure", ctx.getAttribute("getConfig_Result"));
440 Assert.assertNull(ctx.getAttribute("fullConfig"));
441 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
442 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
447 public void testGetConfigNegativeNotSupportedConfId() throws Exception {
449 String entity = "123";
450 SvcLogicContext ctx = new SvcLogicContext();
451 ctx.setAttribute("entity", entity);
453 params = new HashMap<>();
454 params.put("conf-id", "current1");
455 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
458 netconfClientPlugin.getConfig(params, ctx);
460 Assert.assertNull(ctx.getAttribute("getConfig_Result"));
461 Assert.assertNull(ctx.getAttribute("fullConfig"));
462 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
463 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
467 public void testGetConfigNegativeWronjJsonConnectionDetailsException() throws Exception {
469 String entity = "123";
471 SvcLogicContext ctx = new SvcLogicContext();
472 ctx.setAttribute("entity", entity);
474 params = new HashMap<>();
475 params.put("conf-id", "current");
476 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
480 netconfClientPlugin.getConfig(params, ctx);
481 Assert.assertTrue(false);
482 } catch (APPCException e) {
483 Assert.assertEquals("failure", ctx.getAttribute("getConfig_Result"));
484 Assert.assertNull(ctx.getAttribute("fullConfig"));
485 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
486 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
487 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
494 public void testGetRunningConfig() throws Exception {
496 SvcLogicContext ctx = new SvcLogicContext();
497 params = new HashMap<>();
498 params.put("host-ip-address", host);
499 params.put("user-name", username);
500 params.put("password", password);
501 params.put("port-number", String.valueOf(port));
503 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
504 client.setConf(fileContent);
506 netconfClientPlugin.getRunningConfig(params, ctx);
508 Assert.assertEquals("Success", ctx.getAttribute("getRunningConfig_Result"));
509 Assert.assertEquals(fileContent, ctx.getAttribute("running-config"));
510 Assert.assertEquals("success", ctx.getStatus());
514 public void testGetRunningConfigWithoutPortNumberDgErrorFieldNameException() throws Exception {
516 SvcLogicContext ctx = new SvcLogicContext();
517 params = new HashMap<>();
518 params.put("host-ip-address", host);
519 params.put("user-name", username);
520 params.put("password", password);
522 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
523 client.setConf(fileContent);
526 netconfClientPlugin.getRunningConfig(params, ctx);
527 Assert.assertTrue(false);
528 } catch (APPCException e) {
529 Assert.assertEquals("failure", ctx.getAttribute("getRunningConfig_Result"));
530 Assert.assertNull(ctx.getAttribute("running-config"));
531 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
538 public void testGetRunningConfigNegativeConfigurationNull() throws Exception {
540 SvcLogicContext ctx = new SvcLogicContext();
541 params = new HashMap<>();
542 params.put("host-ip-address", host);
543 params.put("user-name", username);
544 params.put("password", password);
545 params.put("port-number", String.valueOf(port));
547 netconfClientPlugin.getRunningConfig(params, ctx);
549 Assert.assertEquals("failure", ctx.getAttribute("getRunningConfig_Result"));
550 Assert.assertNull(ctx.getAttribute("running-config"));
554 public void testValidateMandatoryParamNegativeEmptyParamValue() throws Exception {
556 String paramName = "test";
557 String paramValue = "";
560 netconfClientPlugin.validateMandatoryParam(paramName, paramValue);
561 Assert.assertTrue(false);
562 } catch (Exception e) {
563 Assert.assertTrue(true);
568 public void testRetrieveConnectionDetails() throws Exception {
570 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
571 daoServiceMock.setConfigFile(fileContent);
572 ConnectionDetails connectionDetails1 = getConnectionDetails();
573 daoServiceMock.setConnection(connectionDetails1);
575 NetconfConnectionDetails connectionDetailsActual = netconfClientPlugin.retrieveConnectionDetails(VnfType.VNF);
578 Assert.assertEquals("wrong host", connectionDetails1.getHost(), connectionDetailsActual.getHost());
579 Assert.assertEquals("wrong password", connectionDetails1.getPassword(), connectionDetailsActual.getPassword());
580 Assert.assertEquals("wrong port", connectionDetails1.getPort(), connectionDetailsActual.getPort());
581 Assert.assertEquals("wrong usename", connectionDetails1.getUsername(), connectionDetailsActual.getUsername());
586 public void testRetrieveConnectionDetailsNegativeMissingConfiguration() throws Exception {
588 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
589 daoServiceMock.setConfigFile(fileContent);
590 ConnectionDetails connectionDetails1 = getConnectionDetails();
591 daoServiceMock.setConnection(connectionDetails1);
593 NetconfConnectionDetails connectionDetailsActual = null;
595 connectionDetailsActual = netconfClientPlugin.retrieveConnectionDetails(VnfType.MOCK);
596 Assert.assertTrue(false);
597 } catch (APPCException e) {
598 Assert.assertNull(connectionDetailsActual);
605 public void testRetrieveConfigurationFileContent() throws Exception {
608 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
609 daoServiceMock.setConfigFile(fileContent);
611 Assert.assertEquals("wrong config in a database", fileContent, netconfClientPlugin.retrieveConfigurationFileContent("VnfGetRunningConfig"));
614 private ConnectionDetails getConnectionDetails() {
616 ConnectionDetails connectionDetails = new ConnectionDetails();
617 connectionDetails.setPassword(password);
618 connectionDetails.setPort(port);
619 connectionDetails.setUsername(username);
620 connectionDetails.setHost(host);
621 return connectionDetails;
625 private void initDao() throws NoSuchFieldException, IllegalAccessException {
626 dao = new DAOServiceMock();
627 PowerMockito.mockStatic(FrameworkUtil.class);
628 when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
629 when(bundleService.getBundleContext()).thenReturn(bundleContext);
630 when(bundleContext.getServiceReference(NetconfDataAccessService.class)).thenReturn(sref1);
631 when(bundleContext.getService(sref1)).thenReturn(dao);
636 private void fullInit() throws NoSuchFieldException, IllegalAccessException {
638 initClientFactory2();
640 netconfClientPlugin = new NetconfClientPluginImpl();
641 netconfClientPlugin.setDao(this.dao);
644 private void shortInit() throws NoSuchFieldException, IllegalAccessException {
647 netconfClientPlugin = new NetconfClientPluginImpl();
648 netconfClientPlugin.setDao(this.dao);
651 private void initClientFactory() throws NoSuchFieldException, IllegalAccessException {
653 PowerMockito.mockStatic(FrameworkUtil.class);
654 when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
655 when(bundleService.getBundleContext()).thenReturn(bundleContext);
656 when(bundleContext.getServiceReference(NetconfClientFactory.class)).thenReturn(sref2);
657 when(bundleContext.getService(sref2)).thenReturn(clientFactory);
661 private void initClientFactory2() {
662 PowerMockito.mockStatic(FrameworkUtil.class);
663 when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
664 when(bundleService.getBundleContext()).thenReturn(bundleContext);
665 when(bundleContext.getServiceReference(Matchers.anyString())).thenReturn(sref3);
666 when(bundleContext.getService(sref3)).thenReturn(clientFactory);
669 private void substituteMapper(boolean command) throws NoSuchFieldException, IllegalAccessException {
670 ObjectMapper mapper = new ObjectMapperMock();
671 ObjectMapper mapper2 = new ObjectMapper();
672 Field field = NetconfClientPluginImpl.class.getDeclaredField("mapper");
673 field.setAccessible(true);
675 field.set(netconfClientPlugin, mapper);
677 field.set(netconfClientPlugin, mapper2);