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.Ignore;
29 import org.junit.runner.RunWith;
30 import org.mockito.Matchers;
31 import org.mockito.Mockito;
32 import org.openecomp.appc.adapter.netconf.*;
33 import org.openecomp.appc.adapter.netconf.util.Constants;
34 import org.openecomp.appc.dg.netconf.impl.NetconfClientPluginImpl;
35 import org.openecomp.appc.exceptions.APPCException;
36 import org.openecomp.sdnc.sli.SvcLogicContext;
37 import org.osgi.framework.Bundle;
38 import org.osgi.framework.BundleContext;
39 import org.osgi.framework.FrameworkUtil;
40 import org.osgi.framework.ServiceReference;
41 import org.powermock.api.mockito.PowerMockito;
42 import org.powermock.core.classloader.annotations.PrepareForTest;
43 import org.powermock.modules.junit4.PowerMockRunner;
45 import java.lang.reflect.Field;
46 import java.text.DateFormat;
47 import java.text.SimpleDateFormat;
48 import java.util.Date;
49 import java.util.HashMap;
52 import static org.powermock.api.mockito.PowerMockito.when;
56 @RunWith(PowerMockRunner.class)
57 @PrepareForTest({OperationalStateValidatorFactory.class, NetconfClientPluginImpl.class, FrameworkUtil.class, ObjectMapper.class})
59 public class NetconfClientPluginImplTest {
60 private NetconfClientPluginImpl netconfClientPlugin;
61 private NetconfDataAccessService dao;
62 private NetconfClientFactory clientFactory;
63 private Map<String, String> params;
65 private final BundleContext bundleContext = Mockito.mock(BundleContext.class);
66 private final Bundle bundleService = Mockito.mock(Bundle.class);
67 private final ServiceReference sref1 = Mockito.mock(ServiceReference.class);
68 private final ServiceReference sref2 = Mockito.mock(ServiceReference.class);
69 private final ServiceReference sref3 = Mockito.mock(ServiceReference.class);
70 private static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message";
73 String host = "http://www.test.com";
74 String host1 = "http://www.test1.com";
75 String vnfType = "VNF";
77 String username = "test";
78 String password = "test";
79 String connectionDetails = "{\"host\":\"" + host + "\",\"port\":" + port + ",\"username\":\"" + username + "\",\"password\":\"" + password + "\",\"capabilities\":null,\"additionalProperties\":null}";
80 String fileContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
81 "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
84 "\t\t\t<running/>\n" +
88 String operationalState = "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
91 " <ManagedElement xmlns=\"urn:org:openecomp:appc:Test\">\n" +
92 " <VnfFunction xmlns=\"urn:org:openecomop:appc:Test\">\n" +
93 " <ProcessorManagement>\n" +
95 " <operationalState/>\n" +
96 " <PayloadProcessor>\n" +
97 " <operationalState/>\n" +
98 " </PayloadProcessor>\n" +
100 " <SystemController>\n" +
101 " <operationalState/>\n" +
102 " </SystemController>\n" +
103 " </ProcessorManagement>\n" +
104 " </VnfFunction>\n" +
105 " </ManagedElement>\n" +
112 public void setUp() throws NoSuchFieldException, IllegalAccessException {
113 clientFactory = new NetconfClientFactoryMock();
119 public void testConfigure() throws Exception {
122 SvcLogicContext ctx = new SvcLogicContext();
124 params = new HashMap<>();
125 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
126 params.put(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
128 netconfClientPlugin.configure(params, ctx);
130 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
133 Assert.assertEquals("wrong configuration", fileContent, client.getConf());
134 Assert.assertEquals("wrong host", host, client.getLastConnectionDetails().getHost());
135 Assert.assertEquals("wrong port", port, client.getLastConnectionDetails().getPort());
136 Assert.assertEquals("wrong username", username, client.getLastConnectionDetails().getUsername());
137 Assert.assertEquals("wrong password", password, client.getLastConnectionDetails().getPassword());
138 Assert.assertFalse(client.isConnection());
139 } catch (Exception e) {
140 Assert.fail("failed with because of " + e.getCause());
148 public void testConfigureNegativeIOException() throws Exception {
150 SvcLogicContext ctx = new SvcLogicContext();
152 params = new HashMap<>();
153 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
154 params.put(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
155 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
159 netconfClientPlugin.configure(params, ctx);
160 Assert.assertTrue(false);
161 } catch (APPCException e) {
162 Assert.assertNull(client.getLastConnectionDetails());
163 Assert.assertNull(client.getConf());
169 public void testOperationStateValidation() throws Exception {
171 SvcLogicContext ctx = new SvcLogicContext();
172 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
173 daoServiceMock.setConfigFile(fileContent);
175 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
176 client.setAnswer(operationalState);
179 params = new HashMap<>();
180 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
181 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
182 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
183 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
184 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
186 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
187 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
189 netconfClientPlugin.operationStateValidation(params, ctx);
191 Assert.assertTrue("validation process failed", validatorMock.isValidated());
192 Assert.assertEquals(fileContent, client.getLastMessage());
197 public void testOperationStateValidationNegativeJsonProcessingNullIllegalStateException() throws Exception {
199 SvcLogicContext ctx = new SvcLogicContext();
200 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
201 daoServiceMock.setConfigFile(fileContent);
203 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
204 client.setAnswer(operationalState);
206 params = new HashMap<>();
207 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
208 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
209 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
210 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
211 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
213 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
214 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
215 substituteMapper(true);
218 netconfClientPlugin.operationStateValidation(params, ctx);
219 substituteMapper(false);
220 } catch (APPCException e) {
221 substituteMapper(false);
222 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
223 Assert.assertFalse(validatorMock.isValidated());
224 Assert.assertNull(client.getLastMessage());
229 public void testOperationStateValidationNegativeConnectionDetailsAreNullNullPointerException() throws Exception {
231 SvcLogicContext ctx = new SvcLogicContext();
232 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
233 daoServiceMock.setConfigFile(fileContent);
235 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
236 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);
254 netconfClientPlugin.operationStateValidation(params, ctx);
255 Assert.assertTrue(false);
256 } catch (APPCException e) {
257 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
258 Assert.assertFalse("validation process failed", validatorMock.isValidated());
265 public void testOperationStateValidationNegativeAppcException() throws Exception {
267 SvcLogicContext ctx = new SvcLogicContext();
268 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
269 daoServiceMock.setConfigFile(fileContent);
271 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
272 client.setAnswer("wrong");
275 params = new HashMap<>();
276 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
277 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
278 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
279 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
280 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
282 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
283 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
287 netconfClientPlugin.operationStateValidation(params, ctx);
288 Assert.assertTrue(false);
289 } catch (APPCException e) {
290 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
291 Assert.assertFalse("validation process failed", validatorMock.isValidated());
298 public void testOperationStateValidatioConnectionDetailsInParamsAreEmpty() throws Exception {
300 SvcLogicContext ctx = new SvcLogicContext();
301 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
302 daoServiceMock.setConfigFile(fileContent);
304 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
305 client.setAnswer(operationalState);
306 ((DAOServiceMock) dao).setConnection(getConnectionDetails());
309 params = new HashMap<>();
310 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
311 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
312 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "");
313 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
314 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
316 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
317 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
319 netconfClientPlugin.operationStateValidation(params, ctx);
321 Assert.assertTrue("validation process failed", validatorMock.isValidated());
322 Assert.assertEquals(fileContent, client.getLastMessage());
326 public void testOperationStateValidatioConnectionDetailsInParamsAreNull() throws Exception {
328 SvcLogicContext ctx = new SvcLogicContext();
329 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
330 daoServiceMock.setConfigFile(fileContent);
332 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
333 client.setAnswer(operationalState);
334 ((DAOServiceMock) dao).setConnection(getConnectionDetails());
337 params = new HashMap<>();
338 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
339 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
340 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, null);
341 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
342 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
344 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
345 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
347 netconfClientPlugin.operationStateValidation(params, ctx);
349 Assert.assertTrue("validation process failed", validatorMock.isValidated());
350 Assert.assertEquals(fileContent, client.getLastMessage());
355 public void testBackupConfiguration() throws Exception {
357 SvcLogicContext ctx = new SvcLogicContext();
358 params = new HashMap<>();
359 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
360 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
361 client.setConf(fileContent);
362 netconfClientPlugin.backupConfiguration(params, ctx);
364 DAOServiceMock mockdao = (DAOServiceMock) dao;
365 DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
366 Date date = new Date();
367 String creationDateExpected = dateFormat.format(date);
368 String creationDateActual = mockdao.getBackupConf().get("creationDate").substring(0, 10);
371 Assert.assertEquals("wrong configuration in db", fileContent, mockdao.getBackupConf().get("logText"));
372 Assert.assertEquals(creationDateExpected, creationDateActual);
379 public void testBackupConfigurationNegativeDgErrorFieldName() throws Exception {
381 SvcLogicContext ctx = new SvcLogicContext();
382 params = new HashMap<>();
383 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
384 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
385 client.setConf(fileContent);
387 netconfClientPlugin.backupConfiguration(params, ctx);
388 Assert.assertTrue(false);
389 } catch (APPCException e) {
390 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
392 DAOServiceMock mockdao = (DAOServiceMock) dao;
393 Assert.assertNull(mockdao.getBackupConf());
399 public void testGetConfig() throws Exception {
401 String entity = "123";
403 SvcLogicContext ctx = new SvcLogicContext();
404 ctx.setAttribute("entity", entity);
406 params = new HashMap<>();
407 params.put("conf-id", "current");
408 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
409 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
410 client.setConf(fileContent);
413 netconfClientPlugin.getConfig(params, ctx);
415 Assert.assertEquals("Success", ctx.getAttribute("getConfig_Result"));
416 Assert.assertEquals(fileContent, ctx.getAttribute("fullConfig"));
417 Assert.assertNotNull(ctx.getAttribute(entity + ".Configuration"));
418 Assert.assertEquals(fileContent, ctx.getAttribute(entity + ".Configuration"));
423 public void testGetConfigNegativeConfigurationNull() throws Exception {
425 String entity = "123";
427 SvcLogicContext ctx = new SvcLogicContext();
428 ctx.setAttribute("entity", entity);
430 params = new HashMap<>();
431 params.put("conf-id", "current");
432 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
435 netconfClientPlugin.getConfig(params, ctx);
437 Assert.assertEquals("failure", ctx.getAttribute("getConfig_Result"));
438 Assert.assertNull(ctx.getAttribute("fullConfig"));
439 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
440 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
445 public void testGetConfigNegativeNotSupportedConfId() throws Exception {
447 String entity = "123";
448 SvcLogicContext ctx = new SvcLogicContext();
449 ctx.setAttribute("entity", entity);
451 params = new HashMap<>();
452 params.put("conf-id", "current1");
453 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
456 netconfClientPlugin.getConfig(params, ctx);
458 Assert.assertNull(ctx.getAttribute("getConfig_Result"));
459 Assert.assertNull(ctx.getAttribute("fullConfig"));
460 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
461 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
465 public void testGetConfigNegativeWronjJsonConnectionDetailsException() throws Exception {
467 String entity = "123";
469 SvcLogicContext ctx = new SvcLogicContext();
470 ctx.setAttribute("entity", entity);
472 params = new HashMap<>();
473 params.put("conf-id", "current");
474 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
478 netconfClientPlugin.getConfig(params, ctx);
479 Assert.assertTrue(false);
480 } catch (APPCException e) {
481 Assert.assertEquals("failure", ctx.getAttribute("getConfig_Result"));
482 Assert.assertNull(ctx.getAttribute("fullConfig"));
483 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
484 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
485 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
492 public void testGetRunningConfig() throws Exception {
494 SvcLogicContext ctx = new SvcLogicContext();
495 params = new HashMap<>();
496 params.put("host-ip-address", host);
497 params.put("user-name", username);
498 params.put("password", password);
499 params.put("port-number", String.valueOf(port));
501 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
502 client.setConf(fileContent);
504 netconfClientPlugin.getRunningConfig(params, ctx);
506 Assert.assertEquals("Success", ctx.getAttribute("getRunningConfig_Result"));
507 Assert.assertEquals(fileContent, ctx.getAttribute("running-config"));
508 Assert.assertEquals("success", ctx.getStatus());
512 public void testGetRunningConfigWithoutPortNumberDgErrorFieldNameException() throws Exception {
514 SvcLogicContext ctx = new SvcLogicContext();
515 params = new HashMap<>();
516 params.put("host-ip-address", host);
517 params.put("user-name", username);
518 params.put("password", password);
520 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
521 client.setConf(fileContent);
524 netconfClientPlugin.getRunningConfig(params, ctx);
525 Assert.assertTrue(false);
526 } catch (APPCException e) {
527 Assert.assertEquals("failure", ctx.getAttribute("getRunningConfig_Result"));
528 Assert.assertNull(ctx.getAttribute("running-config"));
529 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
536 public void testGetRunningConfigNegativeConfigurationNull() throws Exception {
538 SvcLogicContext ctx = new SvcLogicContext();
539 params = new HashMap<>();
540 params.put("host-ip-address", host);
541 params.put("user-name", username);
542 params.put("password", password);
543 params.put("port-number", String.valueOf(port));
545 netconfClientPlugin.getRunningConfig(params, ctx);
547 Assert.assertEquals("failure", ctx.getAttribute("getRunningConfig_Result"));
548 Assert.assertNull(ctx.getAttribute("running-config"));
552 public void testValidateMandatoryParamNegativeEmptyParamValue() throws Exception {
554 String paramName = "test";
555 String paramValue = "";
558 netconfClientPlugin.validateMandatoryParam(paramName, paramValue);
559 Assert.assertTrue(false);
560 } catch (Exception e) {
561 Assert.assertTrue(true);
566 public void testRetrieveConnectionDetails() throws Exception {
568 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
569 daoServiceMock.setConfigFile(fileContent);
570 ConnectionDetails connectionDetails1 = getConnectionDetails();
571 daoServiceMock.setConnection(connectionDetails1);
573 NetconfConnectionDetails connectionDetailsActual = netconfClientPlugin.retrieveConnectionDetails(VnfType.VNF);
576 Assert.assertEquals("wrong host", connectionDetails1.getHost(), connectionDetailsActual.getHost());
577 Assert.assertEquals("wrong password", connectionDetails1.getPassword(), connectionDetailsActual.getPassword());
578 Assert.assertEquals("wrong port", connectionDetails1.getPort(), connectionDetailsActual.getPort());
579 Assert.assertEquals("wrong usename", connectionDetails1.getUsername(), connectionDetailsActual.getUsername());
584 public void testRetrieveConnectionDetailsNegativeMissingConfiguration() throws Exception {
586 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
587 daoServiceMock.setConfigFile(fileContent);
588 ConnectionDetails connectionDetails1 = getConnectionDetails();
589 daoServiceMock.setConnection(connectionDetails1);
591 NetconfConnectionDetails connectionDetailsActual = null;
593 connectionDetailsActual = netconfClientPlugin.retrieveConnectionDetails(VnfType.MOCK);
594 Assert.assertTrue(false);
595 } catch (APPCException e) {
596 Assert.assertNull(connectionDetailsActual);
603 public void testRetrieveConfigurationFileContent() throws Exception {
606 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
607 daoServiceMock.setConfigFile(fileContent);
609 Assert.assertEquals("wrong config in a database", fileContent, netconfClientPlugin.retrieveConfigurationFileContent("VnfGetRunningConfig"));
612 private ConnectionDetails getConnectionDetails() {
614 ConnectionDetails connectionDetails = new ConnectionDetails();
615 connectionDetails.setPassword(password);
616 connectionDetails.setPort(port);
617 connectionDetails.setUsername(username);
618 connectionDetails.setHost(host);
619 return connectionDetails;
623 private void initDao() throws NoSuchFieldException, IllegalAccessException {
624 dao = new DAOServiceMock();
625 PowerMockito.mockStatic(FrameworkUtil.class);
626 when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
627 when(bundleService.getBundleContext()).thenReturn(bundleContext);
628 when(bundleContext.getServiceReference(NetconfDataAccessService.class)).thenReturn(sref1);
629 when(bundleContext.getService(sref1)).thenReturn(dao);
634 private void fullInit() throws NoSuchFieldException, IllegalAccessException {
636 initClientFactory2();
638 netconfClientPlugin = new NetconfClientPluginImpl();
639 netconfClientPlugin.setDao(this.dao);
642 private void shortInit() throws NoSuchFieldException, IllegalAccessException {
645 netconfClientPlugin = new NetconfClientPluginImpl();
646 netconfClientPlugin.setDao(this.dao);
649 private void initClientFactory() throws NoSuchFieldException, IllegalAccessException {
651 PowerMockito.mockStatic(FrameworkUtil.class);
652 when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
653 when(bundleService.getBundleContext()).thenReturn(bundleContext);
654 when(bundleContext.getServiceReference(NetconfClientFactory.class)).thenReturn(sref2);
655 when(bundleContext.getService(sref2)).thenReturn(clientFactory);
659 private void initClientFactory2() {
660 PowerMockito.mockStatic(FrameworkUtil.class);
661 when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
662 when(bundleService.getBundleContext()).thenReturn(bundleContext);
663 when(bundleContext.getServiceReference(Matchers.anyString())).thenReturn(sref3);
664 when(bundleContext.getService(sref3)).thenReturn(clientFactory);
667 private void substituteMapper(boolean command) throws NoSuchFieldException, IllegalAccessException {
668 ObjectMapper mapper = new ObjectMapperMock();
669 ObjectMapper mapper2 = new ObjectMapper();
670 Field field = NetconfClientPluginImpl.class.getDeclaredField("mapper");
671 field.setAccessible(true);
673 field.set(netconfClientPlugin, mapper);
675 field.set(netconfClientPlugin, mapper2);