* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@RunWith(PowerMockRunner.class)
-@PrepareForTest({OperationalStateValidatorFactory.class, NetconfClientPluginImpl.class, FrameworkUtil.class, ObjectMapper.class})
+@PrepareForTest({OperationalStateValidatorFactory.class, FrameworkUtil.class, ObjectMapper.class})
public class NetconfClientPluginImplTest {
private NetconfClientPluginImpl netconfClientPlugin;
@Before
public void setUp() throws NoSuchFieldException, IllegalAccessException {
clientFactory = new NetconfClientFactoryMock();
-
}
@Test
public void testConfigure() throws Exception {
-
shortInit();
SvcLogicContext ctx = new SvcLogicContext();
} catch (Exception e) {
Assert.fail("failed with because of " + e.getCause());
}
-
-
}
params.put(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
-
try {
netconfClientPlugin.configure(params, ctx);
Assert.assertTrue(false);
NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
client.setAnswer(operationalState);
-
params = new HashMap<>();
params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
Assert.assertEquals(fileContent, client.getLastMessage());
}
-
@Test
public void testOperationStateValidationNegativeJsonProcessingNullIllegalStateException() throws Exception {
shortInit();
NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
client.setAnswer(operationalState);
-
params = new HashMap<>();
params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
final NetconfConnectionDetails netconfConnectionDetails = null;
when(mapper.readValue(Matchers.anyString(), Matchers.any(Class.class))).thenReturn(netconfConnectionDetails);
-
try {
netconfClientPlugin.operationStateValidation(params, ctx);
Assert.assertTrue(false);
} catch (APPCException e) {
Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
Assert.assertFalse("validation process failed", validatorMock.isValidated());
-
}
}
NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
client.setAnswer("wrong");
-
params = new HashMap<>();
params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
PowerMockito.mockStatic(OperationalStateValidatorFactory.class);
when(OperationalStateValidatorFactory.getOperationalStateValidator(Matchers.any(VnfType.class))).thenReturn(validatorMock);
-
try {
netconfClientPlugin.operationStateValidation(params, ctx);
Assert.assertTrue(false);
} catch (APPCException e) {
Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
Assert.assertFalse("validation process failed", validatorMock.isValidated());
-
}
}
client.setAnswer(operationalState);
((DAOServiceMock) dao).setConnection(getConnectionDetails());
-
params = new HashMap<>();
params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
client.setAnswer(operationalState);
((DAOServiceMock) dao).setConnection(getConnectionDetails());
-
params = new HashMap<>();
params.put(Constants.VNF_TYPE_FIELD_NAME, vnfType);
params.put(Constants.VNF_HOST_IP_ADDRESS_FIELD_NAME, host1);
String creationDateExpected = dateFormat.format(date);
String creationDateActual = mockdao.getBackupConf().get("creationDate").substring(0, 10);
-
Assert.assertEquals("wrong configuration in db", fileContent, mockdao.getBackupConf().get("logText"));
Assert.assertEquals(creationDateExpected, creationDateActual);
-
-
}
-
@Test
public void testBackupConfigurationNegativeDgErrorFieldName() throws Exception {
shortInit();
Assert.assertTrue(false);
} catch (APPCException e) {
Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
-
DAOServiceMock mockdao = (DAOServiceMock) dao;
Assert.assertNull(mockdao.getBackupConf());
}
-
}
@Test
NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
client.setConf(fileContent);
-
netconfClientPlugin.getConfig(params, ctx);
Assert.assertEquals("Success", ctx.getAttribute("getConfig_Result"));
params.put("conf-id", "current");
params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
-
netconfClientPlugin.getConfig(params, ctx);
Assert.assertEquals("failure", ctx.getAttribute("getConfig_Result"));
params.put("conf-id", "current1");
params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
-
netconfClientPlugin.getConfig(params, ctx);
Assert.assertNull(ctx.getAttribute("getConfig_Result"));
params.put("conf-id", "current");
params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
-
try {
netconfClientPlugin.getConfig(params, ctx);
Assert.assertTrue(false);
Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
}
-
-
}
@Test
Assert.assertNull(ctx.getAttribute("running-config"));
Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
}
-
-
}
@Test
NetconfConnectionDetails connectionDetailsActual = netconfClientPlugin.retrieveConnectionDetails(VnfType.VNF);
-
Assert.assertEquals("wrong host", connectionDetails1.getHost(), connectionDetailsActual.getHost());
Assert.assertEquals("wrong password", connectionDetails1.getPassword(), connectionDetailsActual.getPassword());
Assert.assertEquals("wrong port", connectionDetails1.getPort(), connectionDetailsActual.getPort());
} catch (APPCException e) {
Assert.assertNull(connectionDetailsActual);
}
-
-
}
@Test
}
private ConnectionDetails getConnectionDetails() {
-
ConnectionDetails connectionDetails = new ConnectionDetails();
connectionDetails.setPassword(password);
connectionDetails.setPort(port);
when(bundleService.getBundleContext()).thenReturn(bundleContext);
when(bundleContext.getServiceReference(NetconfDataAccessService.class)).thenReturn(sref1);
when(bundleContext.getService(sref1)).thenReturn(dao);
-
-
}
private void fullInit() throws NoSuchFieldException, IllegalAccessException {
}
private void initClientFactory() throws NoSuchFieldException, IllegalAccessException {
-
PowerMockito.mockStatic(FrameworkUtil.class);
when(FrameworkUtil.getBundle(Matchers.any(Class.class))).thenReturn(bundleService);
when(bundleService.getBundleContext()).thenReturn(bundleContext);
when(bundleContext.getServiceReference(NetconfClientFactory.class)).thenReturn(sref2);
when(bundleContext.getService(sref2)).thenReturn(clientFactory);
-
}
private void initClientFactory2() {
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications (C) 2019 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.appc.dg.netconf.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
-import org.junit.*;
+import org.junit.Assert;
+import org.junit.Test;
import org.onap.appc.adapter.netconf.ConnectionDetails;
import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
import org.onap.appc.adapter.netconf.NetconfDataAccessService;
import java.util.HashMap;
import java.util.Map;
-import static org.powermock.api.support.SuppressCode.suppressConstructor;
-
public class NetconfDBPluginImplTest {
private NetconfDBPluginImpl netconfDBPlugin;
private NetconfDataAccessService daoService;
try {
netconfDBPlugin.retrieveDSConfiguration(params, ctx);
} catch (DataAccessException e) {
- //Assert.assertNotNull(ctx.getAttribute("org.onap.appc.dg.error"));
Assert.assertNull(ctx.getAttribute("file-content"));
}
-
-
}
@Test
netconfDBPlugin.retrieveVMDSConfiguration(params, ctx);
Assert.assertTrue(false);
} catch (APPCException e) {
-
Assert.assertEquals("failure", ctx.getAttribute("retrieveVMDSConfiguration_Result"));
}
}
netconfDBPlugin.retrieveVMDSConfiguration(params, ctx);
substituteMapper(false);
Assert.assertTrue(false);
-
} catch (APPCException e) {
substituteMapper(false);
Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
-
}
}
Assert.assertNull(ctx.getAttribute("connection-details"));
Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
}
-
}