Test coverage in RequestValidatorImpl
[appc.git] / appc-dg / appc-dg-shared / appc-dg-netconf / src / test / java / org / onap / appc / dg / netconf / impl / NetconfClientPluginImplTest.java
index 0becff7..9e2384e 100644 (file)
@@ -2,9 +2,11 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * 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.
@@ -18,7 +20,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * 
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  * ============LICENSE_END=========================================================
  */
 
@@ -32,10 +33,15 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Matchers;
 import org.mockito.Mockito;
-import org.onap.appc.adapter.netconf.*;
 import org.onap.appc.adapter.netconf.util.Constants;
-import org.onap.appc.dg.netconf.impl.NetconfClientPluginImpl;
 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.appc.adapter.netconf.ConnectionDetails;
+import org.onap.appc.adapter.netconf.NetconfClientFactory;
+import org.onap.appc.adapter.netconf.NetconfClientType;
+import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
+import org.onap.appc.adapter.netconf.NetconfDataAccessService;
+import org.onap.appc.adapter.netconf.OperationalStateValidatorFactory;
+import org.onap.appc.adapter.netconf.VnfType;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.FrameworkUtil;
@@ -56,7 +62,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;
@@ -113,13 +119,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();
 
@@ -129,7 +133,7 @@ public class NetconfClientPluginImplTest {
 
         netconfClientPlugin.configure(params, ctx);
 
-        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
+        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
 
         try {
             Assert.assertEquals("wrong configuration", fileContent, client.getConf());
@@ -141,8 +145,6 @@ public class NetconfClientPluginImplTest {
         } catch (Exception e) {
             Assert.fail("failed with because of " + e.getCause());
         }
-
-
     }
 
 
@@ -154,8 +156,7 @@ public class NetconfClientPluginImplTest {
         params = new HashMap<>();
         params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
         params.put(Constants.FILE_CONTENT_FIELD_NAME, fileContent);
-        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
-
+        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
 
         try {
             netconfClientPlugin.configure(params, ctx);
@@ -174,10 +175,9 @@ public class NetconfClientPluginImplTest {
         DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
         daoServiceMock.setConfigFile(fileContent);
 
-        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
+        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);
@@ -194,7 +194,6 @@ public class NetconfClientPluginImplTest {
         Assert.assertEquals(fileContent, client.getLastMessage());
     }
 
-
     @Test
     public void testOperationStateValidationNegativeJsonProcessingNullIllegalStateException() throws Exception {
         shortInit();
@@ -202,7 +201,7 @@ public class NetconfClientPluginImplTest {
         DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
         daoServiceMock.setConfigFile(fileContent);
 
-        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
+        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
         client.setAnswer(operationalState);
 
         params = new HashMap<>();
@@ -234,10 +233,9 @@ public class NetconfClientPluginImplTest {
         DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
         daoServiceMock.setConfigFile(fileContent);
 
-        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
+        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);
@@ -251,14 +249,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());
-
         }
     }
 
@@ -270,10 +266,9 @@ public class NetconfClientPluginImplTest {
         DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
         daoServiceMock.setConfigFile(fileContent);
 
-        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
+        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);
@@ -284,14 +279,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());
-
         }
     }
 
@@ -303,11 +296,10 @@ public class NetconfClientPluginImplTest {
         DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
         daoServiceMock.setConfigFile(fileContent);
 
-        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
+        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
         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);
@@ -331,11 +323,10 @@ public class NetconfClientPluginImplTest {
         DAOServiceMock daoServiceMock = (DAOServiceMock) dao;
         daoServiceMock.setConfigFile(fileContent);
 
-        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
+        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
         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);
@@ -359,7 +350,7 @@ public class NetconfClientPluginImplTest {
         SvcLogicContext ctx = new SvcLogicContext();
         params = new HashMap<>();
         params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
-        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
+        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
         client.setConf(fileContent);
         netconfClientPlugin.backupConfiguration(params, ctx);
 
@@ -369,32 +360,26 @@ 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();
         SvcLogicContext ctx = new SvcLogicContext();
         params = new HashMap<>();
         params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, "{" + connectionDetails);
-        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
+        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
         client.setConf(fileContent);
         try {
             netconfClientPlugin.backupConfiguration(params, ctx);
             Assert.assertTrue(false);
         } catch (APPCException e) {
             Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
-
             DAOServiceMock mockdao = (DAOServiceMock) dao;
             Assert.assertNull(mockdao.getBackupConf());
         }
-
     }
 
     @Test
@@ -408,10 +393,9 @@ public class NetconfClientPluginImplTest {
         params = new HashMap<>();
         params.put("conf-id", "current");
         params.put(Constants.CONNECTION_DETAILS_FIELD_NAME, connectionDetails);
-        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
+        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
         client.setConf(fileContent);
 
-
         netconfClientPlugin.getConfig(params, ctx);
 
         Assert.assertEquals("Success", ctx.getAttribute("getConfig_Result"));
@@ -433,7 +417,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"));
@@ -454,7 +437,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"));
@@ -475,7 +457,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);
@@ -486,8 +467,6 @@ public class NetconfClientPluginImplTest {
             Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
             Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
         }
-
-
     }
 
     @Test
@@ -500,7 +479,7 @@ public class NetconfClientPluginImplTest {
         params.put("password", password);
         params.put("port-number", String.valueOf(port));
 
-        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
+        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
         client.setConf(fileContent);
 
         netconfClientPlugin.getRunningConfig(params, ctx);
@@ -519,7 +498,7 @@ public class NetconfClientPluginImplTest {
         params.put("user-name", username);
         params.put("password", password);
 
-        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.GetNetconfClient(NetconfClientType.SSH);
+        NetconfClientJschMock client = (NetconfClientJschMock) clientFactory.getNetconfClient(NetconfClientType.SSH);
         client.setConf(fileContent);
 
         try {
@@ -530,8 +509,6 @@ public class NetconfClientPluginImplTest {
             Assert.assertNull(ctx.getAttribute("running-config"));
             Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
         }
-
-
     }
 
     @Test
@@ -574,7 +551,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());
@@ -597,8 +573,6 @@ public class NetconfClientPluginImplTest {
         } catch (APPCException e) {
             Assert.assertNull(connectionDetailsActual);
         }
-
-
     }
 
     @Test
@@ -612,7 +586,6 @@ public class NetconfClientPluginImplTest {
     }
 
     private ConnectionDetails getConnectionDetails() {
-
         ConnectionDetails connectionDetails = new ConnectionDetails();
         connectionDetails.setPassword(password);
         connectionDetails.setPort(port);
@@ -629,8 +602,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 {
@@ -649,13 +620,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() {