2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.dg.netconf.impl;
28 import org.onap.appc.exceptions.APPCException;
29 import com.fasterxml.jackson.databind.ObjectMapper;
30 import org.junit.Assert;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Matchers;
35 import org.mockito.Mockito;
36 import org.onap.appc.adapter.netconf.*;
37 import org.onap.appc.adapter.netconf.util.Constants;
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, 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();
120 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());
146 public void testConfigureNegativeIOException() throws Exception {
148 SvcLogicContext ctx = new SvcLogicContext();
150 params = new HashMap<>();
151 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
152 params.put(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
153 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
156 netconfClientPlugin.configure(params, ctx);
157 Assert.assertTrue(false);
158 } catch (APPCException e) {
159 Assert.assertNull(client.getLastConnectionDetails());
160 Assert.assertNull(client.getConf());
166 public void testOperationStateValidation() throws Exception {
168 SvcLogicContext ctx = new SvcLogicContext();
169 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
170 daoServiceMock.setConfigFile(fileContent);
172 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
173 client.setAnswer(operationalState);
175 params = new HashMap<>();
176 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
177 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
178 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
179 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
180 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
182 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
183 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
185 netconfClientPlugin.operationStateValidation(params, ctx);
187 Assert.assertTrue("validation process failed", validatorMock.isValidated());
188 Assert.assertEquals(fileContent, client.getLastMessage());
192 public void testOperationStateValidationNegativeJsonProcessingNullIllegalStateException() throws Exception {
194 SvcLogicContext ctx = new SvcLogicContext();
195 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
196 daoServiceMock.setConfigFile(fileContent);
198 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
199 client.setAnswer(operationalState);
201 params = new HashMap<>();
202 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
203 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
204 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
205 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
206 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
208 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
209 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
210 substituteMapper(true);
213 netconfClientPlugin.operationStateValidation(params, ctx);
214 substituteMapper(false);
215 } catch (APPCException e) {
216 substituteMapper(false);
217 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
218 Assert.assertFalse(validatorMock.isValidated());
219 Assert.assertNull(client.getLastMessage());
224 public void testOperationStateValidationNegativeConnectionDetailsAreNullNullPointerException() throws Exception {
226 SvcLogicContext ctx = new SvcLogicContext();
227 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
228 daoServiceMock.setConfigFile(fileContent);
230 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
231 client.setAnswer(operationalState);
233 params = new HashMap<>();
234 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
235 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
236 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, null);
237 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
238 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
240 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
241 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
242 ObjectMapper mapper = PowerMockito.mock(ObjectMapper.class);
243 final NetconfConnectionDetails netconfConnectionDetails = null;
244 when(mapper.readValue(Matchers.anyString(), Matchers.any(Class.class))).thenReturn(netconfConnectionDetails);
247 netconfClientPlugin.operationStateValidation(params, ctx);
248 Assert.assertTrue(false);
249 } catch (APPCException e) {
250 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
251 Assert.assertFalse("validation process failed", validatorMock.isValidated());
257 public void testOperationStateValidationNegativeAppcException() throws Exception {
259 SvcLogicContext ctx = new SvcLogicContext();
260 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
261 daoServiceMock.setConfigFile(fileContent);
263 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
264 client.setAnswer("wrong");
266 params = new HashMap<>();
267 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
268 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
269 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
270 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
271 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
273 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
274 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
277 netconfClientPlugin.operationStateValidation(params, ctx);
278 Assert.assertTrue(false);
279 } catch (APPCException e) {
280 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
281 Assert.assertFalse("validation process failed", validatorMock.isValidated());
287 public void testOperationStateValidatioConnectionDetailsInParamsAreEmpty() throws Exception {
289 SvcLogicContext ctx = new SvcLogicContext();
290 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
291 daoServiceMock.setConfigFile(fileContent);
293 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
294 client.setAnswer(operationalState);
295 ((DAOServiceMock) dao).setConnection(getConnectionDetails());
297 params = new HashMap<>();
298 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
299 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
300 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "");
301 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
302 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
304 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
305 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
307 netconfClientPlugin.operationStateValidation(params, ctx);
309 Assert.assertTrue("validation process failed", validatorMock.isValidated());
310 Assert.assertEquals(fileContent, client.getLastMessage());
314 public void testOperationStateValidatioConnectionDetailsInParamsAreNull() throws Exception {
316 SvcLogicContext ctx = new SvcLogicContext();
317 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
318 daoServiceMock.setConfigFile(fileContent);
320 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
321 client.setAnswer(operationalState);
322 ((DAOServiceMock) dao).setConnection(getConnectionDetails());
324 params = new HashMap<>();
325 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
326 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
327 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, null);
328 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
329 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
331 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
332 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
334 netconfClientPlugin.operationStateValidation(params, ctx);
336 Assert.assertTrue("validation process failed", validatorMock.isValidated());
337 Assert.assertEquals(fileContent, client.getLastMessage());
342 public void testBackupConfiguration() throws Exception {
344 SvcLogicContext ctx = new SvcLogicContext();
345 params = new HashMap<>();
346 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
347 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
348 client.setConf(fileContent);
349 netconfClientPlugin.backupConfiguration(params, ctx);
351 DAOServiceMock mockdao = (DAOServiceMock) dao;
352 DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
353 Date date = new Date();
354 String creationDateExpected = dateFormat.format(date);
355 String creationDateActual = mockdao.getBackupConf().get("creationDate").substring(0, 10);
357 Assert.assertEquals("wrong configuration in db", fileContent, mockdao.getBackupConf().get("logText"));
358 Assert.assertEquals(creationDateExpected, creationDateActual);
362 public void testBackupConfigurationNegativeDgErrorFieldName() throws Exception {
364 SvcLogicContext ctx = new SvcLogicContext();
365 params = new HashMap<>();
366 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
367 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
368 client.setConf(fileContent);
370 netconfClientPlugin.backupConfiguration(params, ctx);
371 Assert.assertTrue(false);
372 } catch (APPCException e) {
373 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
374 DAOServiceMock mockdao = (DAOServiceMock) dao;
375 Assert.assertNull(mockdao.getBackupConf());
380 public void testGetConfig() throws Exception {
382 String entity = "123";
384 SvcLogicContext ctx = new SvcLogicContext();
385 ctx.setAttribute("entity", entity);
387 params = new HashMap<>();
388 params.put("conf-id", "current");
389 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
390 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
391 client.setConf(fileContent);
393 netconfClientPlugin.getConfig(params, ctx);
395 Assert.assertEquals("Success", ctx.getAttribute("getConfig_Result"));
396 Assert.assertEquals(fileContent, ctx.getAttribute("fullConfig"));
397 Assert.assertNotNull(ctx.getAttribute(entity + ".Configuration"));
398 Assert.assertEquals(fileContent, ctx.getAttribute(entity + ".Configuration"));
403 public void testGetConfigNegativeConfigurationNull() throws Exception {
405 String entity = "123";
407 SvcLogicContext ctx = new SvcLogicContext();
408 ctx.setAttribute("entity", entity);
410 params = new HashMap<>();
411 params.put("conf-id", "current");
412 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
414 netconfClientPlugin.getConfig(params, ctx);
416 Assert.assertEquals("failure", ctx.getAttribute("getConfig_Result"));
417 Assert.assertNull(ctx.getAttribute("fullConfig"));
418 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
419 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
424 public void testGetConfigNegativeNotSupportedConfId() throws Exception {
426 String entity = "123";
427 SvcLogicContext ctx = new SvcLogicContext();
428 ctx.setAttribute("entity", entity);
430 params = new HashMap<>();
431 params.put("conf-id", "current1");
432 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
434 netconfClientPlugin.getConfig(params, ctx);
436 Assert.assertNull(ctx.getAttribute("getConfig_Result"));
437 Assert.assertNull(ctx.getAttribute("fullConfig"));
438 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
439 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
443 public void testGetConfigNegativeWronjJsonConnectionDetailsException() throws Exception {
445 String entity = "123";
447 SvcLogicContext ctx = new SvcLogicContext();
448 ctx.setAttribute("entity", entity);
450 params = new HashMap<>();
451 params.put("conf-id", "current");
452 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
455 netconfClientPlugin.getConfig(params, ctx);
456 Assert.assertTrue(false);
457 } catch (APPCException e) {
458 Assert.assertEquals("failure", ctx.getAttribute("getConfig_Result"));
459 Assert.assertNull(ctx.getAttribute("fullConfig"));
460 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
461 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
462 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
467 public void testGetRunningConfig() throws Exception {
469 SvcLogicContext ctx = new SvcLogicContext();
470 params = new HashMap<>();
471 params.put("host-ip-address", host);
472 params.put("user-name", username);
473 params.put("password", password);
474 params.put("port-number", String.valueOf(port));
476 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
477 client.setConf(fileContent);
479 netconfClientPlugin.getRunningConfig(params, ctx);
481 Assert.assertEquals("Success", ctx.getAttribute("getRunningConfig_Result"));
482 Assert.assertEquals(fileContent, ctx.getAttribute("running-config"));
483 Assert.assertEquals("success", ctx.getStatus());
487 public void testGetRunningConfigWithoutPortNumberDgErrorFieldNameException() throws Exception {
489 SvcLogicContext ctx = new SvcLogicContext();
490 params = new HashMap<>();
491 params.put("host-ip-address", host);
492 params.put("user-name", username);
493 params.put("password", password);
495 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
496 client.setConf(fileContent);
499 netconfClientPlugin.getRunningConfig(params, ctx);
500 Assert.assertTrue(false);
501 } catch (APPCException e) {
502 Assert.assertEquals("failure", ctx.getAttribute("getRunningConfig_Result"));
503 Assert.assertNull(ctx.getAttribute("running-config"));
504 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
509 public void testGetRunningConfigNegativeConfigurationNull() throws Exception {
511 SvcLogicContext ctx = new SvcLogicContext();
512 params = new HashMap<>();
513 params.put("host-ip-address", host);
514 params.put("user-name", username);
515 params.put("password", password);
516 params.put("port-number", String.valueOf(port));
518 netconfClientPlugin.getRunningConfig(params, ctx);
520 Assert.assertEquals("failure", ctx.getAttribute("getRunningConfig_Result"));
521 Assert.assertNull(ctx.getAttribute("running-config"));
525 public void testValidateMandatoryParamNegativeEmptyParamValue() throws Exception {
527 String paramName = "test";
528 String paramValue = "";
531 netconfClientPlugin.validateMandatoryParam(paramName, paramValue);
532 Assert.assertTrue(false);
533 } catch (Exception e) {
534 Assert.assertTrue(true);
539 public void testRetrieveConnectionDetails() throws Exception {
541 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
542 daoServiceMock.setConfigFile(fileContent);
543 ConnectionDetails connectionDetails1 = getConnectionDetails();
544 daoServiceMock.setConnection(connectionDetails1);
546 NetconfConnectionDetails connectionDetailsActual = netconfClientPlugin.retrieveConnectionDetails(VnfType.VNF);
548 Assert.assertEquals("wrong host", connectionDetails1.getHost(), connectionDetailsActual.getHost());
549 Assert.assertEquals("wrong password", connectionDetails1.getPassword(), connectionDetailsActual.getPassword());
550 Assert.assertEquals("wrong port", connectionDetails1.getPort(), connectionDetailsActual.getPort());
551 Assert.assertEquals("wrong usename", connectionDetails1.getUsername(), connectionDetailsActual.getUsername());
556 public void testRetrieveConnectionDetailsNegativeMissingConfiguration() throws Exception {
558 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
559 daoServiceMock.setConfigFile(fileContent);
560 ConnectionDetails connectionDetails1 = getConnectionDetails();
561 daoServiceMock.setConnection(connectionDetails1);
563 NetconfConnectionDetails connectionDetailsActual = null;
565 connectionDetailsActual = netconfClientPlugin.retrieveConnectionDetails(VnfType.MOCK);
566 Assert.assertTrue(false);
567 } catch (APPCException e) {
568 Assert.assertNull(connectionDetailsActual);
573 public void testRetrieveConfigurationFileContent() throws Exception {
576 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
577 daoServiceMock.setConfigFile(fileContent);
579 Assert.assertEquals("wrong config in a database", fileContent, netconfClientPlugin.retrieveConfigurationFileContent("VnfGetRunningConfig"));
582 private ConnectionDetails getConnectionDetails() {
583 ConnectionDetails connectionDetails = new ConnectionDetails();
584 connectionDetails.setPassword(password);
585 connectionDetails.setPort(port);
586 connectionDetails.setUsername(username);
587 connectionDetails.setHost(host);
588 return connectionDetails;
592 private void initDao() throws NoSuchFieldException, IllegalAccessException {
593 dao = new DAOServiceMock();
594 PowerMockito.mockStatic(FrameworkUtil.class);
595 when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
596 when(bundleService.getBundleContext()).thenReturn(bundleContext);
597 when(bundleContext.getServiceReference(NetconfDataAccessService.class)).thenReturn(sref1);
598 when(bundleContext.getService(sref1)).thenReturn(dao);
601 private void fullInit() throws NoSuchFieldException, IllegalAccessException {
603 initClientFactory2();
605 netconfClientPlugin = new NetconfClientPluginImpl();
606 netconfClientPlugin.setDao(this.dao);
609 private void shortInit() throws NoSuchFieldException, IllegalAccessException {
612 netconfClientPlugin = new NetconfClientPluginImpl();
613 netconfClientPlugin.setDao(this.dao);
616 private void initClientFactory() throws NoSuchFieldException, IllegalAccessException {
617 PowerMockito.mockStatic(FrameworkUtil.class);
618 when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
619 when(bundleService.getBundleContext()).thenReturn(bundleContext);
620 when(bundleContext.getServiceReference(NetconfClientFactory.class)).thenReturn(sref2);
621 when(bundleContext.getService(sref2)).thenReturn(clientFactory);
624 private void initClientFactory2() {
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(Matchers.anyString())).thenReturn(sref3);
629 when(bundleContext.getService(sref3)).thenReturn(clientFactory);
632 private void substituteMapper(boolean command) throws NoSuchFieldException, IllegalAccessException {
633 ObjectMapper mapper = new ObjectMapperMock();
634 ObjectMapper mapper2 = new ObjectMapper();
635 Field field = NetconfClientPluginImpl.class.getDeclaredField("mapper");
636 field.setAccessible(true);
638 field.set(netconfClientPlugin, mapper);
640 field.set(netconfClientPlugin, mapper2);