diff options
Diffstat (limited to 'appc-dg')
6 files changed, 23 insertions, 64 deletions
diff --git a/appc-dg/appc-dg-shared/appc-dg-netconf/src/main/java/org/onap/appc/dg/netconf/impl/NetconfClientPluginImpl.java b/appc-dg/appc-dg-shared/appc-dg-netconf/src/main/java/org/onap/appc/dg/netconf/impl/NetconfClientPluginImpl.java index 4aff9a8bc..7b9d5d802 100644 --- a/appc-dg/appc-dg-shared/appc-dg-netconf/src/main/java/org/onap/appc/dg/netconf/impl/NetconfClientPluginImpl.java +++ b/appc-dg/appc-dg-shared/appc-dg-netconf/src/main/java/org/onap/appc/dg/netconf/impl/NetconfClientPluginImpl.java @@ -5,6 +5,8 @@ * 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. @@ -185,9 +187,7 @@ public class NetconfClientPluginImpl implements NetconfClientPlugin { NetconfClient client = null; try { - if (logger.isDebugEnabled()) { - logger.debug("Entered backup to DEVICE_INTERFACE_LOG"); - } + logger.debug("Entered backup to DEVICE_INTERFACE_LOG"); client = clientFactory.getNetconfClient(NetconfClientType.SSH); //get connection details @@ -218,9 +218,7 @@ public class NetconfClientPluginImpl implements NetconfClientPlugin { String confId = params.get("conf-id"); if ("current".equalsIgnoreCase(confId)) { try { - if (logger.isDebugEnabled()) { - logger.debug("Entered getConfig to DEVICE_INTERFACE_LOG"); - } + logger.debug("Entered getConfig to DEVICE_INTERFACE_LOG"); //get netconf client to get configuration BundleContext bctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); ServiceReference sref = bctx.getServiceReference(NETCONF_CLIENT_FACTORY_NAME); diff --git a/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/NetconfClientFactoryMock.java b/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/NetconfClientFactoryMock.java index b5e86e2d6..da42e8e3d 100644 --- a/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/NetconfClientFactoryMock.java +++ b/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/NetconfClientFactoryMock.java @@ -5,6 +5,8 @@ * 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. @@ -26,8 +28,6 @@ package org.onap.appc.dg.netconf.impl; import org.onap.appc.adapter.netconf.NetconfClient; import org.onap.appc.adapter.netconf.NetconfClientFactory; import org.onap.appc.adapter.netconf.NetconfClientType; -import org.onap.appc.adapter.netconf.jsch.NetconfClientJsch; -import org.onap.appc.adapter.netconf.odlconnector.NetconfClientRestconfImpl; public class NetconfClientFactoryMock extends NetconfClientFactory { @@ -36,9 +36,7 @@ public class NetconfClientFactoryMock extends NetconfClientFactory { @Override public NetconfClient getNetconfClient(NetconfClientType type){ - return jschClient; - } } diff --git a/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/NetconfClientJschMock.java b/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/NetconfClientJschMock.java index 4233ccccf..40621d81f 100644 --- a/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/NetconfClientJschMock.java +++ b/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/NetconfClientJschMock.java @@ -5,6 +5,8 @@ * 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. @@ -76,7 +78,9 @@ public class NetconfClientJschMock implements NetconfClient { if (connection) { this.lastMessage = message; return answer; - } else return null; + } else { + return null; + } } @Override @@ -91,7 +95,9 @@ public class NetconfClientJschMock implements NetconfClient { public String getConfiguration() throws APPCException { if (connection) { return configuration; - } else return null; + } else { + return null; + } } @Override diff --git a/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/NetconfClientPluginImplTest.java b/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/NetconfClientPluginImplTest.java index 51078e2bf..b1724ac0c 100644 --- a/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/NetconfClientPluginImplTest.java +++ b/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/NetconfClientPluginImplTest.java @@ -5,6 +5,8 @@ * 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. @@ -54,7 +56,7 @@ import static org.powermock.api.mockito.PowerMockito.when; @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; @@ -111,13 +113,11 @@ public class NetconfClientPluginImplTest { @Before public void setUp() throws NoSuchFieldException, IllegalAccessException { clientFactory = new NetconfClientFactoryMock(); - } @Test public void testConfigure() throws Exception { - shortInit(); SvcLogicContext ctx = new SvcLogicContext(); @@ -139,8 +139,6 @@ public class NetconfClientPluginImplTest { } catch (Exception e) { Assert.fail("failed with because of " + e.getCause()); } - - } @@ -154,7 +152,6 @@ public class NetconfClientPluginImplTest { params.put(Constants.FILE_CONTENT_FIELD_NAME, fileContent); NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH); - try { netconfClientPlugin.configure(params, ctx); Assert.assertTrue(false); @@ -175,7 +172,6 @@ public class NetconfClientPluginImplTest { 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); @@ -192,7 +188,6 @@ public class NetconfClientPluginImplTest { Assert.assertEquals(fileContent, client.getLastMessage()); } - @Test public void testOperationStateValidationNegativeJsonProcessingNullIllegalStateException() throws Exception { shortInit(); @@ -235,7 +230,6 @@ public class NetconfClientPluginImplTest { 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); @@ -249,14 +243,12 @@ public class NetconfClientPluginImplTest { 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()); - } } @@ -271,7 +263,6 @@ public class NetconfClientPluginImplTest { 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); @@ -282,14 +273,12 @@ public class NetconfClientPluginImplTest { 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()); - } } @@ -305,7 +294,6 @@ public class NetconfClientPluginImplTest { 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); @@ -333,7 +321,6 @@ public class NetconfClientPluginImplTest { 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); @@ -367,14 +354,10 @@ public class NetconfClientPluginImplTest { 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(); @@ -388,11 +371,9 @@ public class NetconfClientPluginImplTest { Assert.assertTrue(false); } catch (APPCException e) { Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE)); - DAOServiceMock mockdao = (DAOServiceMock) dao; Assert.assertNull(mockdao.getBackupConf()); } - } @Test @@ -409,7 +390,6 @@ public class NetconfClientPluginImplTest { NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH); client.setConf(fileContent); - netconfClientPlugin.getConfig(params, ctx); Assert.assertEquals("Success", ctx.getAttribute("getConfig_Result")); @@ -431,7 +411,6 @@ public class NetconfClientPluginImplTest { params.put("conf-id", "current"); params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails); - netconfClientPlugin.getConfig(params, ctx); Assert.assertEquals("failure", ctx.getAttribute("getConfig_Result")); @@ -452,7 +431,6 @@ public class NetconfClientPluginImplTest { params.put("conf-id", "current1"); params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails); - netconfClientPlugin.getConfig(params, ctx); Assert.assertNull(ctx.getAttribute("getConfig_Result")); @@ -473,7 +451,6 @@ public class NetconfClientPluginImplTest { params.put("conf-id", "current"); params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails); - try { netconfClientPlugin.getConfig(params, ctx); Assert.assertTrue(false); @@ -484,8 +461,6 @@ public class NetconfClientPluginImplTest { Assert.assertNull(ctx.getAttribute(entity + ".Configuration")); Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE)); } - - } @Test @@ -528,8 +503,6 @@ public class NetconfClientPluginImplTest { Assert.assertNull(ctx.getAttribute("running-config")); Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE)); } - - } @Test @@ -572,7 +545,6 @@ public class NetconfClientPluginImplTest { 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()); @@ -595,8 +567,6 @@ public class NetconfClientPluginImplTest { } catch (APPCException e) { Assert.assertNull(connectionDetailsActual); } - - } @Test @@ -610,7 +580,6 @@ public class NetconfClientPluginImplTest { } private ConnectionDetails getConnectionDetails() { - ConnectionDetails connectionDetails = new ConnectionDetails(); connectionDetails.setPassword(password); connectionDetails.setPort(port); @@ -627,8 +596,6 @@ public class NetconfClientPluginImplTest { when(bundleService.getBundleContext()).thenReturn(bundleContext); when(bundleContext.getServiceReference(NetconfDataAccessService.class)).thenReturn(sref1); when(bundleContext.getService(sref1)).thenReturn(dao); - - } private void fullInit() throws NoSuchFieldException, IllegalAccessException { @@ -647,13 +614,11 @@ public class NetconfClientPluginImplTest { } 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() { diff --git a/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/NetconfDBPluginImplTest.java b/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/NetconfDBPluginImplTest.java index 8f11022bd..95672194d 100644 --- a/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/NetconfDBPluginImplTest.java +++ b/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/NetconfDBPluginImplTest.java @@ -5,6 +5,8 @@ * 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. @@ -24,7 +26,8 @@ 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; @@ -38,8 +41,6 @@ import java.lang.reflect.Field; 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; @@ -85,11 +86,8 @@ public class NetconfDBPluginImplTest { try { netconfDBPlugin.retrieveDSConfiguration(params, ctx); } catch (DataAccessException e) { - //Assert.assertNotNull(ctx.getAttribute("org.onap.appc.dg.error")); Assert.assertNull(ctx.getAttribute("file-content")); } - - } @Test @@ -116,7 +114,6 @@ public class NetconfDBPluginImplTest { netconfDBPlugin.retrieveVMDSConfiguration(params, ctx); Assert.assertTrue(false); } catch (APPCException e) { - Assert.assertEquals("failure", ctx.getAttribute("retrieveVMDSConfiguration_Result")); } } @@ -135,11 +132,9 @@ public class NetconfDBPluginImplTest { netconfDBPlugin.retrieveVMDSConfiguration(params, ctx); substituteMapper(false); Assert.assertTrue(false); - } catch (APPCException e) { substituteMapper(false); Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE)); - } } @@ -183,7 +178,6 @@ public class NetconfDBPluginImplTest { Assert.assertNull(ctx.getAttribute("connection-details")); Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE)); } - } diff --git a/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/OperationStateValidatorFactoryMock.java b/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/OperationStateValidatorFactoryMock.java index 6fef1782c..368031dd7 100644 --- a/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/OperationStateValidatorFactoryMock.java +++ b/appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/OperationStateValidatorFactoryMock.java @@ -5,6 +5,8 @@ * 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. @@ -23,7 +25,6 @@ package org.onap.appc.dg.netconf.impl; -import org.apache.commons.lang3.NotImplementedException; import org.onap.appc.adapter.netconf.*; @@ -39,9 +40,6 @@ public class OperationStateValidatorFactoryMock extends OperationalStateValidato } public static OperationalStateValidator getOperationalStateValidator(VnfType vnfType) { - return new MockOperationalStateValidatorImpl(); - - } } |