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.ccsdk.sli.core.sli.SvcLogicContext;
38 import org.osgi.framework.Bundle;
39 import org.osgi.framework.BundleContext;
40 import org.osgi.framework.FrameworkUtil;
41 import org.osgi.framework.ServiceReference;
42 import org.powermock.api.mockito.PowerMockito;
43 import org.powermock.core.classloader.annotations.PrepareForTest;
44 import org.powermock.modules.junit4.PowerMockRunner;
46 import java.lang.reflect.Field;
47 import java.text.DateFormat;
48 import java.text.SimpleDateFormat;
49 import java.util.Date;
50 import java.util.HashMap;
53 import static org.powermock.api.mockito.PowerMockito.when;
57 @RunWith(PowerMockRunner.class)
58 @PrepareForTest({OperationalStateValidatorFactory.class, NetconfClientPluginImpl.class, FrameworkUtil.class, ObjectMapper.class})
60 public class NetconfClientPluginImplTest {
61 private NetconfClientPluginImpl netconfClientPlugin;
62 private NetconfDataAccessService dao;
63 private NetconfClientFactory clientFactory;
64 private Map<String, String> params;
66 private final BundleContext bundleContext = Mockito.mock(BundleContext.class);
67 private final Bundle bundleService = Mockito.mock(Bundle.class);
68 private final ServiceReference sref1 = Mockito.mock(ServiceReference.class);
69 private final ServiceReference sref2 = Mockito.mock(ServiceReference.class);
70 private final ServiceReference sref3 = Mockito.mock(ServiceReference.class);
71 private static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message";
74 String host = "http://www.test.com";
75 String host1 = "http://www.test1.com";
76 String vnfType = "VNF";
78 String username = "test";
79 String password = "test";
80 String connectionDetails = "{\"host\":\"" + host + "\",\"port\":" + port + ",\"username\":\"" + username + "\",\"password\":\"" + password + "\",\"capabilities\":null,\"additionalProperties\":null}";
81 String fileContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
82 "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
85 "\t\t\t<running/>\n" +
89 String operationalState = "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
92 " <ManagedElement xmlns=\"urn:org:onap:appc:Test\">\n" +
93 " <VnfFunction xmlns=\"urn:org:openecomop:appc:Test\">\n" +
94 " <ProcessorManagement>\n" +
96 " <operationalState/>\n" +
97 " <PayloadProcessor>\n" +
98 " <operationalState/>\n" +
99 " </PayloadProcessor>\n" +
101 " <SystemController>\n" +
102 " <operationalState/>\n" +
103 " </SystemController>\n" +
104 " </ProcessorManagement>\n" +
105 " </VnfFunction>\n" +
106 " </ManagedElement>\n" +
113 public void setUp() throws NoSuchFieldException, IllegalAccessException {
114 clientFactory = new NetconfClientFactoryMock();
120 public void testConfigure() throws Exception {
123 SvcLogicContext ctx = new SvcLogicContext();
125 params = new HashMap<>();
126 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
127 params.put(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
129 netconfClientPlugin.configure(params, ctx);
131 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
134 Assert.assertEquals("wrong configuration", fileContent, client.getConf());
135 Assert.assertEquals("wrong host", host, client.getLastConnectionDetails().getHost());
136 Assert.assertEquals("wrong port", port, client.getLastConnectionDetails().getPort());
137 Assert.assertEquals("wrong username", username, client.getLastConnectionDetails().getUsername());
138 Assert.assertEquals("wrong password", password, client.getLastConnectionDetails().getPassword());
139 Assert.assertFalse(client.isConnection());
140 } catch (Exception e) {
141 Assert.fail("failed with because of " + e.getCause());
149 public void testConfigureNegativeIOException() throws Exception {
151 SvcLogicContext ctx = new SvcLogicContext();
153 params = new HashMap<>();
154 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
155 params.put(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
156 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
160 netconfClientPlugin.configure(params, ctx);
161 Assert.assertTrue(false);
162 } catch (APPCException e) {
163 Assert.assertNull(client.getLastConnectionDetails());
164 Assert.assertNull(client.getConf());
170 public void testOperationStateValidation() throws Exception {
172 SvcLogicContext ctx = new SvcLogicContext();
173 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
174 daoServiceMock.setConfigFile(fileContent);
176 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
177 client.setAnswer(operationalState);
180 params = new HashMap<>();
181 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
182 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
183 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
184 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
185 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
187 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
188 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
190 netconfClientPlugin.operationStateValidation(params, ctx);
192 Assert.assertTrue("validation process failed", validatorMock.isValidated());
193 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);
240 params = new HashMap<>();
241 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
242 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
243 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, null);
244 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
245 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
247 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
248 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
249 ObjectMapper mapper = PowerMockito.mock(ObjectMapper.class);
250 final NetconfConnectionDetails netconfConnectionDetails = null;
251 when(mapper.readValue(Matchers.anyString(), Matchers.any(Class.class))).thenReturn(netconfConnectionDetails);
255 netconfClientPlugin.operationStateValidation(params, ctx);
256 Assert.assertTrue(false);
257 } catch (APPCException e) {
258 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
259 Assert.assertFalse("validation process failed", validatorMock.isValidated());
266 public void testOperationStateValidationNegativeAppcException() throws Exception {
268 SvcLogicContext ctx = new SvcLogicContext();
269 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
270 daoServiceMock.setConfigFile(fileContent);
272 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
273 client.setAnswer("wrong");
276 params = new HashMap<>();
277 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
278 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
279 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
280 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
281 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
283 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
284 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
288 netconfClientPlugin.operationStateValidation(params, ctx);
289 Assert.assertTrue(false);
290 } catch (APPCException e) {
291 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
292 Assert.assertFalse("validation process failed", validatorMock.isValidated());
299 public void testOperationStateValidatioConnectionDetailsInParamsAreEmpty() throws Exception {
301 SvcLogicContext ctx = new SvcLogicContext();
302 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
303 daoServiceMock.setConfigFile(fileContent);
305 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
306 client.setAnswer(operationalState);
307 ((DAOServiceMock) dao).setConnection(getConnectionDetails());
310 params = new HashMap<>();
311 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
312 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
313 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "");
314 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
315 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
317 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
318 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
320 netconfClientPlugin.operationStateValidation(params, ctx);
322 Assert.assertTrue("validation process failed", validatorMock.isValidated());
323 Assert.assertEquals(fileContent, client.getLastMessage());
327 public void testOperationStateValidatioConnectionDetailsInParamsAreNull() throws Exception {
329 SvcLogicContext ctx = new SvcLogicContext();
330 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
331 daoServiceMock.setConfigFile(fileContent);
333 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
334 client.setAnswer(operationalState);
335 ((DAOServiceMock) dao).setConnection(getConnectionDetails());
338 params = new HashMap<>();
339 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
340 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
341 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, null);
342 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
343 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
345 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
346 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
348 netconfClientPlugin.operationStateValidation(params, ctx);
350 Assert.assertTrue("validation process failed", validatorMock.isValidated());
351 Assert.assertEquals(fileContent, client.getLastMessage());
356 public void testBackupConfiguration() throws Exception {
358 SvcLogicContext ctx = new SvcLogicContext();
359 params = new HashMap<>();
360 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
361 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
362 client.setConf(fileContent);
363 netconfClientPlugin.backupConfiguration(params, ctx);
365 DAOServiceMock mockdao = (DAOServiceMock) dao;
366 DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
367 Date date = new Date();
368 String creationDateExpected = dateFormat.format(date);
369 String creationDateActual = mockdao.getBackupConf().get("creationDate").substring(0, 10);
372 Assert.assertEquals("wrong configuration in db", fileContent, mockdao.getBackupConf().get("logText"));
373 Assert.assertEquals(creationDateExpected, creationDateActual);
380 public void testBackupConfigurationNegativeDgErrorFieldName() throws Exception {
382 SvcLogicContext ctx = new SvcLogicContext();
383 params = new HashMap<>();
384 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
385 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
386 client.setConf(fileContent);
388 netconfClientPlugin.backupConfiguration(params, ctx);
389 Assert.assertTrue(false);
390 } catch (APPCException e) {
391 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
393 DAOServiceMock mockdao = (DAOServiceMock) dao;
394 Assert.assertNull(mockdao.getBackupConf());
400 public void testGetConfig() throws Exception {
402 String entity = "123";
404 SvcLogicContext ctx = new SvcLogicContext();
405 ctx.setAttribute("entity", entity);
407 params = new HashMap<>();
408 params.put("conf-id", "current");
409 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
410 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
411 client.setConf(fileContent);
414 netconfClientPlugin.getConfig(params, ctx);
416 Assert.assertEquals("Success", ctx.getAttribute("getConfig_Result"));
417 Assert.assertEquals(fileContent, ctx.getAttribute("fullConfig"));
418 Assert.assertNotNull(ctx.getAttribute(entity + ".Configuration"));
419 Assert.assertEquals(fileContent, ctx.getAttribute(entity + ".Configuration"));
424 public void testGetConfigNegativeConfigurationNull() throws Exception {
426 String entity = "123";
428 SvcLogicContext ctx = new SvcLogicContext();
429 ctx.setAttribute("entity", entity);
431 params = new HashMap<>();
432 params.put("conf-id", "current");
433 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
436 netconfClientPlugin.getConfig(params, ctx);
438 Assert.assertEquals("failure", ctx.getAttribute("getConfig_Result"));
439 Assert.assertNull(ctx.getAttribute("fullConfig"));
440 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
441 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
446 public void testGetConfigNegativeNotSupportedConfId() throws Exception {
448 String entity = "123";
449 SvcLogicContext ctx = new SvcLogicContext();
450 ctx.setAttribute("entity", entity);
452 params = new HashMap<>();
453 params.put("conf-id", "current1");
454 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
457 netconfClientPlugin.getConfig(params, ctx);
459 Assert.assertNull(ctx.getAttribute("getConfig_Result"));
460 Assert.assertNull(ctx.getAttribute("fullConfig"));
461 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
462 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
466 public void testGetConfigNegativeWronjJsonConnectionDetailsException() throws Exception {
468 String entity = "123";
470 SvcLogicContext ctx = new SvcLogicContext();
471 ctx.setAttribute("entity", entity);
473 params = new HashMap<>();
474 params.put("conf-id", "current");
475 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
479 netconfClientPlugin.getConfig(params, ctx);
480 Assert.assertTrue(false);
481 } catch (APPCException e) {
482 Assert.assertEquals("failure", ctx.getAttribute("getConfig_Result"));
483 Assert.assertNull(ctx.getAttribute("fullConfig"));
484 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
485 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
486 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
493 public void testGetRunningConfig() 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);
500 params.put("port-number", String.valueOf(port));
502 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
503 client.setConf(fileContent);
505 netconfClientPlugin.getRunningConfig(params, ctx);
507 Assert.assertEquals("Success", ctx.getAttribute("getRunningConfig_Result"));
508 Assert.assertEquals(fileContent, ctx.getAttribute("running-config"));
509 Assert.assertEquals("success", ctx.getStatus());
513 public void testGetRunningConfigWithoutPortNumberDgErrorFieldNameException() throws Exception {
515 SvcLogicContext ctx = new SvcLogicContext();
516 params = new HashMap<>();
517 params.put("host-ip-address", host);
518 params.put("user-name", username);
519 params.put("password", password);
521 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
522 client.setConf(fileContent);
525 netconfClientPlugin.getRunningConfig(params, ctx);
526 Assert.assertTrue(false);
527 } catch (APPCException e) {
528 Assert.assertEquals("failure", ctx.getAttribute("getRunningConfig_Result"));
529 Assert.assertNull(ctx.getAttribute("running-config"));
530 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
537 public void testGetRunningConfigNegativeConfigurationNull() throws Exception {
539 SvcLogicContext ctx = new SvcLogicContext();
540 params = new HashMap<>();
541 params.put("host-ip-address", host);
542 params.put("user-name", username);
543 params.put("password", password);
544 params.put("port-number", String.valueOf(port));
546 netconfClientPlugin.getRunningConfig(params, ctx);
548 Assert.assertEquals("failure", ctx.getAttribute("getRunningConfig_Result"));
549 Assert.assertNull(ctx.getAttribute("running-config"));
553 public void testValidateMandatoryParamNegativeEmptyParamValue() throws Exception {
555 String paramName = "test";
556 String paramValue = "";
559 netconfClientPlugin.validateMandatoryParam(paramName, paramValue);
560 Assert.assertTrue(false);
561 } catch (Exception e) {
562 Assert.assertTrue(true);
567 public void testRetrieveConnectionDetails() throws Exception {
569 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
570 daoServiceMock.setConfigFile(fileContent);
571 ConnectionDetails connectionDetails1 = getConnectionDetails();
572 daoServiceMock.setConnection(connectionDetails1);
574 NetconfConnectionDetails connectionDetailsActual = netconfClientPlugin.retrieveConnectionDetails(VnfType.VNF);
577 Assert.assertEquals("wrong host", connectionDetails1.getHost(), connectionDetailsActual.getHost());
578 Assert.assertEquals("wrong password", connectionDetails1.getPassword(), connectionDetailsActual.getPassword());
579 Assert.assertEquals("wrong port", connectionDetails1.getPort(), connectionDetailsActual.getPort());
580 Assert.assertEquals("wrong usename", connectionDetails1.getUsername(), connectionDetailsActual.getUsername());
585 public void testRetrieveConnectionDetailsNegativeMissingConfiguration() throws Exception {
587 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
588 daoServiceMock.setConfigFile(fileContent);
589 ConnectionDetails connectionDetails1 = getConnectionDetails();
590 daoServiceMock.setConnection(connectionDetails1);
592 NetconfConnectionDetails connectionDetailsActual = null;
594 connectionDetailsActual = netconfClientPlugin.retrieveConnectionDetails(VnfType.MOCK);
595 Assert.assertTrue(false);
596 } catch (APPCException e) {
597 Assert.assertNull(connectionDetailsActual);
604 public void testRetrieveConfigurationFileContent() throws Exception {
607 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
608 daoServiceMock.setConfigFile(fileContent);
610 Assert.assertEquals("wrong config in a database", fileContent, netconfClientPlugin.retrieveConfigurationFileContent("VnfGetRunningConfig"));
613 private ConnectionDetails getConnectionDetails() {
615 ConnectionDetails connectionDetails = new ConnectionDetails();
616 connectionDetails.setPassword(password);
617 connectionDetails.setPort(port);
618 connectionDetails.setUsername(username);
619 connectionDetails.setHost(host);
620 return connectionDetails;
624 private void initDao() throws NoSuchFieldException, IllegalAccessException {
625 dao = new DAOServiceMock();
626 PowerMockito.mockStatic(FrameworkUtil.class);
627 when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
628 when(bundleService.getBundleContext()).thenReturn(bundleContext);
629 when(bundleContext.getServiceReference(NetconfDataAccessService.class)).thenReturn(sref1);
630 when(bundleContext.getService(sref1)).thenReturn(dao);
635 private void fullInit() throws NoSuchFieldException, IllegalAccessException {
637 initClientFactory2();
639 netconfClientPlugin = new NetconfClientPluginImpl();
640 netconfClientPlugin.setDao(this.dao);
643 private void shortInit() throws NoSuchFieldException, IllegalAccessException {
646 netconfClientPlugin = new NetconfClientPluginImpl();
647 netconfClientPlugin.setDao(this.dao);
650 private void initClientFactory() throws NoSuchFieldException, IllegalAccessException {
652 PowerMockito.mockStatic(FrameworkUtil.class);
653 when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
654 when(bundleService.getBundleContext()).thenReturn(bundleContext);
655 when(bundleContext.getServiceReference(NetconfClientFactory.class)).thenReturn(sref2);
656 when(bundleContext.getService(sref2)).thenReturn(clientFactory);
660 private void initClientFactory2() {
661 PowerMockito.mockStatic(FrameworkUtil.class);
662 when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
663 when(bundleService.getBundleContext()).thenReturn(bundleContext);
664 when(bundleContext.getServiceReference(Matchers.anyString())).thenReturn(sref3);
665 when(bundleContext.getService(sref3)).thenReturn(clientFactory);
668 private void substituteMapper(boolean command) throws NoSuchFieldException, IllegalAccessException {
669 ObjectMapper mapper = new ObjectMapperMock();
670 ObjectMapper mapper2 = new ObjectMapper();
671 Field field = NetconfClientPluginImpl.class.getDeclaredField("mapper");
672 field.setAccessible(true);
674 field.set(netconfClientPlugin, mapper);
676 field.set(netconfClientPlugin, mapper2);