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 220328c..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,9 +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.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;
@@ -55,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;
@@ -112,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();
 
@@ -140,8 +145,6 @@ public class NetconfClientPluginImplTest {
         } catch (Exception e) {
             Assert.fail("failed with because of " + e.getCause());
         }
-
-
     }
 
 
@@ -155,7 +158,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);
@@ -176,7 +178,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);
@@ -193,7 +194,6 @@ public class NetconfClientPluginImplTest {
         Assert.assertEquals(fileContent, client.getLastMessage());
     }
 
-
     @Test
     public void testOperationStateValidationNegativeJsonProcessingNullIllegalStateException() throws Exception {
         shortInit();
@@ -236,7 +236,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);
@@ -250,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());
-
         }
     }
 
@@ -272,7 +269,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);
@@ -283,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());
-
         }
     }
 
@@ -306,7 +300,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);
@@ -334,7 +327,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);
@@ -368,14 +360,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();
@@ -389,11 +377,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
@@ -410,7 +396,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"));
@@ -432,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"));
@@ -453,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"));
@@ -474,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);
@@ -485,8 +467,6 @@ public class NetconfClientPluginImplTest {
             Assert.assertNull(ctx.getAttribute(entity + ".Configuration"));
             Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
         }
-
-
     }
 
     @Test
@@ -529,8 +509,6 @@ public class NetconfClientPluginImplTest {
             Assert.assertNull(ctx.getAttribute("running-config"));
             Assert.assertNotNull(ctx.getAttribute(DG_OUTPUT_STATUS_MESSAGE));
         }
-
-
     }
 
     @Test
@@ -573,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());
@@ -596,8 +573,6 @@ public class NetconfClientPluginImplTest {
         } catch (APPCException e) {
             Assert.assertNull(connectionDetailsActual);
         }
-
-
     }
 
     @Test
@@ -611,7 +586,6 @@ public class NetconfClientPluginImplTest {
     }
 
     private ConnectionDetails getConnectionDetails() {
-
         ConnectionDetails connectionDetails = new ConnectionDetails();
         connectionDetails.setPassword(password);
         connectionDetails.setPort(port);
@@ -628,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 {
@@ -648,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() {