2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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.
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.util.Constants;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
37 import org.onap.appc.adapter.netconf.ConnectionDetails;
38 import org.onap.appc.adapter.netconf.NetconfClientFactory;
39 import org.onap.appc.adapter.netconf.NetconfClientType;
40 import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
41 import org.onap.appc.adapter.netconf.NetconfDataAccessService;
42 import org.onap.appc.adapter.netconf.OperationalStateValidatorFactory;
43 import org.onap.appc.adapter.netconf.VnfType;
44 import org.osgi.framework.Bundle;
45 import org.osgi.framework.BundleContext;
46 import org.osgi.framework.FrameworkUtil;
47 import org.osgi.framework.ServiceReference;
48 import org.powermock.api.mockito.PowerMockito;
49 import org.powermock.core.classloader.annotations.PrepareForTest;
50 import org.powermock.modules.junit4.PowerMockRunner;
52 import java.lang.reflect.Field;
53 import java.text.DateFormat;
54 import java.text.SimpleDateFormat;
55 import java.util.Date;
56 import java.util.HashMap;
59 import static org.powermock.api.mockito.PowerMockito.when;
62 @RunWith(PowerMockRunner.class)
63 @PrepareForTest({OperationalStateValidatorFactory.class, FrameworkUtil.class, ObjectMapper.class})
65 public class NetconfClientPluginImplTest {
66 private NetconfClientPluginImpl netconfClientPlugin;
67 private NetconfDataAccessService dao;
68 private NetconfClientFactory clientFactory;
69 private Map<String, String> params;
71 private final BundleContext bundleContext = Mockito.mock(BundleContext.class);
72 private final Bundle bundleService = Mockito.mock(Bundle.class);
73 private final ServiceReference sref1 = Mockito.mock(ServiceReference.class);
74 private final ServiceReference sref2 = Mockito.mock(ServiceReference.class);
75 private final ServiceReference sref3 = Mockito.mock(ServiceReference.class);
76 private static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message";
79 String host = "http://www.test.com";
80 String host1 = "http://www.test1.com";
81 String vnfType = "VNF";
83 String username = "test";
84 String password = "test";
85 String connectionDetails =
86 "{\"host\":\"" + host + "\",\"port\":" + port + ",\"username\":\"" + username
87 + "\",\"password\":\"" + password + "\",\"capabilities\":null,\"additionalProperties\":null}";
89 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
90 + "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
93 + "\t\t\t<running/>\n"
97 String operationalState =
98 "<rpc message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"
101 + " <ManagedElement xmlns=\"urn:org:onap:appc:Test\">\n"
102 + " <VnfFunction xmlns=\"urn:org:openecomop:appc:Test\">\n"
103 + " <ProcessorManagement>\n"
105 + " <operationalState/>\n"
106 + " <PayloadProcessor>\n"
107 + " <operationalState/>\n"
108 + " </PayloadProcessor>\n"
110 + " <SystemController>\n"
111 + " <operationalState/>\n"
112 + " </SystemController>\n"
113 + " </ProcessorManagement>\n"
114 + " </VnfFunction>\n"
115 + " </ManagedElement>\n"
122 public void setUp() throws NoSuchFieldException, IllegalAccessException {
123 clientFactory = new NetconfClientFactoryMock();
128 public void testConfigure() throws Exception {
130 SvcLogicContext ctx = new SvcLogicContext();
132 params = new HashMap<>();
133 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
134 params.put(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
136 netconfClientPlugin.configure(params, ctx);
138 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
141 Assert.assertEquals("wrong configuration", fileContent, client.getConf());
142 Assert.assertEquals("wrong host", host, client.getLastConnectionDetails().getHost());
143 Assert.assertEquals("wrong port", port, client.getLastConnectionDetails().getPort());
144 Assert.assertEquals("wrong username", username, client.getLastConnectionDetails().getUsername());
145 Assert.assertEquals("wrong password", password, client.getLastConnectionDetails().getPassword());
146 Assert.assertFalse(client.isConnection());
147 } catch (Exception e) {
148 Assert.fail("failed because of " + e.getCause());
154 public void testConfigureNegativeIOException() throws Exception {
156 SvcLogicContext ctx = new SvcLogicContext();
158 params = new HashMap<>();
159 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
160 params.put(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
161 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
164 netconfClientPlugin.configure(params, ctx);
165 Assert.assertTrue(false);
166 } catch (APPCException e) {
167 Assert.assertNull(client.getLastConnectionDetails());
168 Assert.assertNull(client.getConf());
174 public void testOperationStateValidation() throws Exception {
176 SvcLogicContext ctx = new SvcLogicContext();
177 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
178 daoServiceMock.setConfigFile(fileContent);
180 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
181 client.setAnswer(operationalState);
183 params = new HashMap<>();
184 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
185 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
186 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
187 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
188 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
190 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
191 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class)))
192 .thenReturn(validatorMock);
194 netconfClientPlugin.operationStateValidation(params, ctx);
196 Assert.assertTrue("validation process failed", validatorMock.isValidated());
197 Assert.assertEquals(fileContent, client.getLastMessage());
201 public void testOperationStateValidationNegativeJsonProcessingNullIllegalStateException() throws Exception {
203 SvcLogicContext ctx = new SvcLogicContext();
204 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
205 daoServiceMock.setConfigFile(fileContent);
207 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
208 client.setAnswer(operationalState);
210 params = new HashMap<>();
211 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
212 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
213 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
214 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
215 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
217 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
218 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class)))
219 .thenReturn(validatorMock);
220 substituteMapper(true);
223 netconfClientPlugin.operationStateValidation(params, ctx);
224 substituteMapper(false);
225 } catch (APPCException e) {
226 substituteMapper(false);
227 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
228 Assert.assertFalse(validatorMock.isValidated());
229 Assert.assertNull(client.getLastMessage());
234 public void testOperationStateValidationNegativeConnectionDetailsAreNullNullPointerException() throws Exception {
236 SvcLogicContext ctx = new SvcLogicContext();
237 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
238 daoServiceMock.setConfigFile(fileContent);
240 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
241 client.setAnswer(operationalState);
243 params = new HashMap<>();
244 params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
245 params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
246 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, null);
247 MockOperationalStateValidatorImpl validatorMock = new MockOperationalStateValidatorImpl();
248 validatorMock.setConfigurationFileName("VnfGetRunningConfig");
250 PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
251 when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class)))
252 .thenReturn(validatorMock);
253 ObjectMapper mapper = PowerMockito.mock(ObjectMapper.class);
254 final NetconfConnectionDetails netconfConnectionDetails = null;
255 when(mapper.readValue(Matchers.anyString(), Matchers.any(Class.class))).thenReturn(netconfConnectionDetails);
258 netconfClientPlugin.operationStateValidation(params, ctx);
259 Assert.assertTrue(false);
260 } catch (APPCException e) {
261 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
262 Assert.assertFalse("validation process failed", validatorMock.isValidated());
268 public void testOperationStateValidationNegativeAppcException() throws Exception {
270 SvcLogicContext ctx = new SvcLogicContext();
271 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
272 daoServiceMock.setConfigFile(fileContent);
274 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
275 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)))
286 .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());
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());
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)))
318 .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());
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)))
346 .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);
371 Assert.assertEquals("wrong configuration in db", fileContent, mockdao.getBackupConf().get("logText"));
372 Assert.assertEquals(creationDateExpected, creationDateActual);
376 public void testBackupConfigurationNegativeDgErrorFieldName() throws Exception {
378 SvcLogicContext ctx = new SvcLogicContext();
379 params = new HashMap<>();
380 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
381 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
382 client.setConf(fileContent);
384 netconfClientPlugin.backupConfiguration(params, ctx);
385 Assert.assertTrue(false);
386 } catch (APPCException e) {
387 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
388 DAOServiceMock mockdao = (DAOServiceMock) dao;
389 Assert.assertNull(mockdao.getBackupConf());
394 public void testGetConfig() throws Exception {
396 String entity = "123";
398 SvcLogicContext ctx = new SvcLogicContext();
399 ctx.setAttribute("entity", entity);
401 params = new HashMap<>();
402 params.put("conf-id", "current");
403 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
404 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
405 client.setConf(fileContent);
407 netconfClientPlugin.getConfig(params, ctx);
409 Assert.assertEquals("Success", ctx.getAttribute("getConfig_Result"));
410 Assert.assertEquals(fileContent, ctx.getAttribute("fullConfig"));
411 Assert.assertNotNull(ctx.getAttribute(entity + ".Configuration"));
412 Assert.assertEquals(fileContent, ctx.getAttribute(entity + ".Configuration"));
417 public void testGetConfigNegativeConfigurationNull() throws Exception {
419 String entity = "123";
421 SvcLogicContext ctx = new SvcLogicContext();
422 ctx.setAttribute("entity", entity);
424 params = new HashMap<>();
425 params.put("conf-id", "current");
426 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
428 netconfClientPlugin.getConfig(params, ctx);
430 Assert.assertEquals("failure", ctx.getAttribute("getConfig_Result"));
431 Assert.assertNull(ctx.getAttribute("fullConfig"));
432 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
433 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
438 public void testGetConfigNegativeNotSupportedConfId() throws Exception {
440 String entity = "123";
441 SvcLogicContext ctx = new SvcLogicContext();
442 ctx.setAttribute("entity", entity);
444 params = new HashMap<>();
445 params.put("conf-id", "current1");
446 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
448 netconfClientPlugin.getConfig(params, ctx);
450 Assert.assertNull(ctx.getAttribute("getConfig_Result"));
451 Assert.assertNull(ctx.getAttribute("fullConfig"));
452 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
453 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
457 public void testGetConfigNegativeWronjJsonConnectionDetailsException() throws Exception {
459 String entity = "123";
461 SvcLogicContext ctx = new SvcLogicContext();
462 ctx.setAttribute("entity", entity);
464 params = new HashMap<>();
465 params.put("conf-id", "current");
466 params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
469 netconfClientPlugin.getConfig(params, ctx);
470 Assert.assertTrue(false);
471 } catch (APPCException e) {
472 Assert.assertEquals("failure", ctx.getAttribute("getConfig_Result"));
473 Assert.assertNull(ctx.getAttribute("fullConfig"));
474 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
475 Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
476 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
481 public void testGetRunningConfig() throws Exception {
483 SvcLogicContext ctx = new SvcLogicContext();
484 params = new HashMap<>();
485 params.put("host-ip-address", host);
486 params.put("user-name", username);
487 params.put("password", password);
488 params.put("port-number", String.valueOf(port));
490 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
491 client.setConf(fileContent);
493 netconfClientPlugin.getRunningConfig(params, ctx);
495 Assert.assertEquals("Success", ctx.getAttribute("getRunningConfig_Result"));
496 Assert.assertEquals(fileContent, ctx.getAttribute("running-config"));
497 Assert.assertEquals("success", ctx.getStatus());
501 public void testGetRunningConfigWithoutPortNumberDgErrorFieldNameException() throws Exception {
503 SvcLogicContext ctx = new SvcLogicContext();
504 params = new HashMap<>();
505 params.put("host-ip-address", host);
506 params.put("user-name", username);
507 params.put("password", password);
509 NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
510 client.setConf(fileContent);
513 netconfClientPlugin.getRunningConfig(params, ctx);
514 Assert.assertTrue(false);
515 } catch (APPCException e) {
516 Assert.assertEquals("failure", ctx.getAttribute("getRunningConfig_Result"));
517 Assert.assertNull(ctx.getAttribute("running-config"));
518 Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
523 public void testGetRunningConfigNegativeConfigurationNull() throws Exception {
525 SvcLogicContext ctx = new SvcLogicContext();
526 params = new HashMap<>();
527 params.put("host-ip-address", host);
528 params.put("user-name", username);
529 params.put("password", password);
530 params.put("port-number", String.valueOf(port));
532 netconfClientPlugin.getRunningConfig(params, ctx);
534 Assert.assertEquals("failure", ctx.getAttribute("getRunningConfig_Result"));
535 Assert.assertNull(ctx.getAttribute("running-config"));
539 public void testValidateMandatoryParamNegativeEmptyParamValue() throws Exception {
541 String paramName = "test";
542 String paramValue = "";
545 netconfClientPlugin.validateMandatoryParam(paramName, paramValue);
546 Assert.assertTrue(false);
547 } catch (Exception e) {
548 Assert.assertTrue(true);
553 public void testRetrieveConnectionDetails() throws Exception {
555 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
556 daoServiceMock.setConfigFile(fileContent);
557 ConnectionDetails connectionDetails1 = getConnectionDetails();
558 daoServiceMock.setConnection(connectionDetails1);
560 NetconfConnectionDetails connectionDetailsActual = netconfClientPlugin.retrieveConnectionDetails(VnfType.VNF);
562 Assert.assertEquals("wrong host", connectionDetails1.getHost(), connectionDetailsActual.getHost());
563 Assert.assertEquals("wrong password", connectionDetails1.getPassword(), connectionDetailsActual.getPassword());
564 Assert.assertEquals("wrong port", connectionDetails1.getPort(), connectionDetailsActual.getPort());
565 Assert.assertEquals("wrong username", connectionDetails1.getUsername(), connectionDetailsActual.getUsername());
570 public void testRetrieveConnectionDetailsNegativeMissingConfiguration() throws Exception {
572 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
573 daoServiceMock.setConfigFile(fileContent);
574 ConnectionDetails connectionDetails1 = getConnectionDetails();
575 daoServiceMock.setConnection(connectionDetails1);
577 NetconfConnectionDetails connectionDetailsActual = null;
579 connectionDetailsActual = netconfClientPlugin.retrieveConnectionDetails(VnfType.MOCK);
580 Assert.assertTrue(false);
581 } catch (APPCException e) {
582 Assert.assertNull(connectionDetailsActual);
587 public void testRetrieveConfigurationFileContent() throws Exception {
590 DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
591 daoServiceMock.setConfigFile(fileContent);
593 Assert.assertEquals("wrong config in a database",
594 fileContent, netconfClientPlugin.retrieveConfigurationFileContent("VnfGetRunningConfig"));
597 private ConnectionDetails getConnectionDetails() {
598 ConnectionDetails connectionDetails = new ConnectionDetails();
599 connectionDetails.setPassword(password);
600 connectionDetails.setPort(port);
601 connectionDetails.setUsername(username);
602 connectionDetails.setHost(host);
603 return connectionDetails;
607 private void initDao() throws NoSuchFieldException, IllegalAccessException {
608 dao = new DAOServiceMock();
609 PowerMockito.mockStatic(FrameworkUtil.class);
610 when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
611 when(bundleService.getBundleContext()).thenReturn(bundleContext);
612 when(bundleContext.getServiceReference(NetconfDataAccessService.class)).thenReturn(sref1);
613 when(bundleContext.getService(sref1)).thenReturn(dao);
616 private void fullInit() throws NoSuchFieldException, IllegalAccessException {
618 initClientFactory2();
620 netconfClientPlugin = new NetconfClientPluginImpl();
621 netconfClientPlugin.setDao(this.dao);
624 private void shortInit() throws NoSuchFieldException, IllegalAccessException {
627 netconfClientPlugin = new NetconfClientPluginImpl();
628 netconfClientPlugin.setDao(this.dao);
631 private void initClientFactory() throws NoSuchFieldException, IllegalAccessException {
632 PowerMockito.mockStatic(FrameworkUtil.class);
633 when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
634 when(bundleService.getBundleContext()).thenReturn(bundleContext);
635 when(bundleContext.getServiceReference(NetconfClientFactory.class)).thenReturn(sref2);
636 when(bundleContext.getService(sref2)).thenReturn(clientFactory);
639 private void initClientFactory2() {
640 PowerMockito.mockStatic(FrameworkUtil.class);
641 when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
642 when(bundleService.getBundleContext()).thenReturn(bundleContext);
643 when(bundleContext.getServiceReference(Matchers.anyString())).thenReturn(sref3);
644 when(bundleContext.getService(sref3)).thenReturn(clientFactory);
647 private void substituteMapper(boolean command) throws NoSuchFieldException, IllegalAccessException {
648 ObjectMapper mapper = new ObjectMapperMock();
649 ObjectMapper mapper2 = new ObjectMapper();
650 Field field = NetconfClientPluginImpl.class.getDeclaredField("mapper");
651 field.setAccessible(true);
653 field.set(netconfClientPlugin, mapper);
655 field.set(netconfClientPlugin, mapper2);