Sonar fixes in "appc-netconf-adapter-bundle" 57/29157/3
authorwejs <maciej.wejs@nokia.com>
Thu, 25 Jan 2018 11:41:33 +0000 (12:41 +0100)
committerwejs <maciej.wejs@nokia.com>
Thu, 1 Feb 2018 11:18:18 +0000 (12:18 +0100)
Change-Id: Ib5842a5f43c9437fee464e9a35e3120a11d1c6b1
Issue-ID: APPC-494
Signed-off-by: wejs <maciej.wejs@nokia.com>
24 files changed:
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivator.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/MockOperationalStateValidatorImpl.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/NetconfClientFactory.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/NetconfDataAccessService.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/OperationalStateValidator.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/OperationalStateValidatorFactory.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/VNFOperationalStateValidatorImpl.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfAdapter.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfConstMessages.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfMessage.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/jsch/JSchLogger.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/jsch/NetconfClientJsch.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/odlconnector/NetconfClientRestconfImpl.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/internal/TestNetconfAdapter.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestGetRunningConfig.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestModifyConfig.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestModifyConfigMock.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestModifyConfigRouterMock.java
appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/test/java/org/onap/appc/adapter/netconf/jsch/TestOperationalStates.java
appc-dg/appc-dg-shared/appc-dg-netconf/src/main/java/org/onap/appc/dg/netconf/impl/NetconfClientPluginImpl.java
appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/NetconfClientFactoryMock.java
appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/NetconfClientPluginImplTest.java
appc-dg/appc-dg-shared/appc-dg-netconf/src/test/java/org/onap/appc/dg/netconf/impl/OperationStateValidatorFactoryMock.java

index 70438d7..33bf331 100644 (file)
@@ -26,9 +26,6 @@ package org.onap.appc.adapter.netconf;
 
 import org.onap.appc.adapter.netconf.internal.NetconfDataAccessServiceImpl;
 import org.onap.ccsdk.sli.core.dblib.DbLibService;
-import org.onap.appc.i18n.Msg;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
@@ -43,10 +40,6 @@ public class AppcNetconfAdapterActivator implements BundleActivator {
     private ServiceRegistration reporterRegistration = null;
     private ServiceRegistration factoryRegistration = null;
     private ServiceRegistration dbRegistration = null;
-    /**
-     * The logger to be used
-     */
-    private static final EELFLogger logger = EELFManager.getInstance().getLogger(AppcNetconfAdapterActivator.class);
 
     /**
      * Called when this bundle is started so the Framework can perform the bundle-specific activities necessary to start
@@ -71,17 +64,13 @@ public class AppcNetconfAdapterActivator implements BundleActivator {
             */
             NetconfClientFactory clientFactory = new NetconfClientFactory();                
             factoryRegistration = context.registerService(NetconfClientFactory.class, clientFactory, null);
-            NetconfDataAccessService DAService = new NetconfDataAccessServiceImpl();
+            NetconfDataAccessService dataAccessService = new NetconfDataAccessServiceImpl();
             //set dblib service
-            DbLibService dblibSvc = null;
             ServiceReference sref = context.getServiceReference(DbLibService.class.getName());
-            dblibSvc  = (DbLibService)context.getService(sref);
-            DAService.setDbLibService(dblibSvc);
+            dataAccessService.setDbLibService((DbLibService)context.getService(sref));
             ///////////////////////////////////
-            factoryRegistration = context.registerService(NetconfDataAccessService.class, DAService, null);
+            factoryRegistration = context.registerService(NetconfDataAccessService.class, dataAccessService, null);
         }
-
-        //logger.info(Msg.COMPONENT_INITIALIZED, "NETCONF adapter");
     }
 
     /**
@@ -122,9 +111,4 @@ public class AppcNetconfAdapterActivator implements BundleActivator {
             dbRegistration = null;
         }
     }
-
-    public String getName() {
-        return "APPC NETCONF adapter";
-    }
-
 }
index 079ae76..f293362 100644 (file)
@@ -26,8 +26,8 @@ package org.onap.appc.adapter.netconf;
 
 import org.onap.appc.exceptions.APPCException;
 
-
 public class MockOperationalStateValidatorImpl implements OperationalStateValidator {
+
     @Override
     public VnfType getVnfType() {
         return VnfType.MOCK;
@@ -35,8 +35,8 @@ public class MockOperationalStateValidatorImpl implements OperationalStateValida
 
     @Override
     public String getConfigurationFileName() {
-        String configFileName = OperationalStateValidatorFactory.configuration.getProperty(this.getClass().getCanonicalName() + CONFIG_FILE_PROPERTY_SUFFIX);
-        return configFileName;
+        return OperationalStateValidatorFactory.configuration
+                .getProperty(this.getClass().getCanonicalName() + CONFIG_FILE_PROPERTY_SUFFIX);
     }
 
     @Override
index 45c8fb0..0ce6c4b 100644 (file)
@@ -30,7 +30,7 @@ import org.onap.appc.adapter.netconf.odlconnector.NetconfClientRestconfImpl;
 
 public class NetconfClientFactory {
 
-    public NetconfClient GetNetconfClient(NetconfClientType type){
+    public NetconfClient getNetconfClient(NetconfClientType type){
 
         if(type==NetconfClientType.RESTCONF) {
             return new NetconfClientRestconfImpl();
index f831541..a8607a5 100644 (file)
@@ -49,7 +49,7 @@ public interface NetconfDataAccessService {
      * @return
      * @throws DataAccessException
      */
-    String retrieveConfigFileName(String xmlID) throws DataAccessException;
+    String retrieveConfigFileName(String xmlID);
 
     /**
      *
@@ -58,7 +58,7 @@ public interface NetconfDataAccessService {
      * @return
      * @throws DataAccessException
      */
-    boolean retrieveConnectionDetails(String vnfType, ConnectionDetails connectionDetails) throws DataAccessException;
+    boolean retrieveConnectionDetails(String vnfType, ConnectionDetails connectionDetails);
 
     /**
      *
@@ -67,8 +67,7 @@ public interface NetconfDataAccessService {
      * @return
      * @throws DataAccessException
      */
-    boolean retrieveNetconfConnectionDetails(String vnfType, NetconfConnectionDetails connectionDetails) throws
-                    DataAccessException;
+    boolean retrieveNetconfConnectionDetails(String vnfType, NetconfConnectionDetails connectionDetails);
 
     /**
      *
@@ -79,7 +78,6 @@ public interface NetconfDataAccessService {
      * @return
      * @throws DataAccessException
      */
-    boolean logDeviceInteraction(String instanceId, String requestId, String creationDate, String logText) throws
-                    DataAccessException;
+    boolean logDeviceInteraction(String instanceId, String requestId, String creationDate, String logText);
 
 }
index ffa3862..db3a8ef 100644 (file)
@@ -28,8 +28,9 @@ import org.onap.appc.exceptions.APPCException;
 
 
 public interface OperationalStateValidator {
+    public static final String CONFIG_FILE_PROPERTY_SUFFIX = "-CONFIG_FILE";
     public VnfType getVnfType();
     public String getConfigurationFileName();
     public void validateResponse(String response) throws APPCException;
-    final public static String CONFIG_FILE_PROPERTY_SUFFIX = "-CONFIG_FILE";
+
 }
index 37e9691..d6d34ba 100644 (file)
@@ -31,8 +31,10 @@ import org.onap.appc.configuration.ConfigurationFactory;
 public class OperationalStateValidatorFactory {
     protected static final Configuration configuration = ConfigurationFactory.getConfiguration();
 
+    protected OperationalStateValidatorFactory() {}
+
     public static OperationalStateValidator getOperationalStateValidator(String vnfType) {
-        VnfType vnfTypeEnum = null;
+        VnfType vnfTypeEnum;
         try {
             vnfTypeEnum = VnfType.getVnfType(vnfType);
         } catch (IllegalArgumentException e) {
index 4bb5ab2..ebe69c8 100644 (file)
@@ -41,6 +41,7 @@ import java.util.*;
 
 public class VNFOperationalStateValidatorImpl implements OperationalStateValidator {
     private static final String OPERATIONAL_STATE_ELEMENT_NAME = "operationalState";
+
     @Override
     public VnfType getVnfType() {
         return VnfType.VNF;
@@ -48,8 +49,9 @@ public class VNFOperationalStateValidatorImpl implements OperationalStateValidat
 
     @Override
     public String getConfigurationFileName() {
-        String configFileName = OperationalStateValidatorFactory.configuration.getProperty(this.getClass().getCanonicalName() + CONFIG_FILE_PROPERTY_SUFFIX);
-        configFileName = configFileName == null?  "VnfGetOperationalStates" : configFileName;
+        String configFileName = OperationalStateValidatorFactory.configuration
+                .getProperty(this.getClass().getCanonicalName() + CONFIG_FILE_PROPERTY_SUFFIX);
+        configFileName = configFileName == null ? "VnfGetOperationalStates" : configFileName;
         return configFileName;
     }
 
@@ -58,54 +60,46 @@ public class VNFOperationalStateValidatorImpl implements OperationalStateValidat
         if(StringUtils.isEmpty(response)) {
             throw new APPCException("empty response");
         }
-
-        boolean isValid = false;
-        String errorMsg = "unexpected response";
         try {
-            List<Map.Entry> operationalStateList = getOperationalStateList(response);
-            if(operationalStateList != null && !operationalStateList.isEmpty()) {
-                for (Map.Entry stateEntry : operationalStateList) {
-                    if(!((String)stateEntry.getValue()).equalsIgnoreCase("ENABLED")){
-                        errorMsg = "at least one "+OPERATIONAL_STATE_ELEMENT_NAME+" is not in valid satae. "+operationalStateList.toString();
-                        isValid = false;
-                        break;
-                    }else{
-                        isValid =true;
-                    }
-                }
-            }else {
-                errorMsg = "response without any "+OPERATIONAL_STATE_ELEMENT_NAME+" element";
+            List<Map.Entry> operationalStateList = getOperationalStateList(response).orElseThrow(() ->
+                    new APPCException("response without any "+OPERATIONAL_STATE_ELEMENT_NAME+" element"));
+
+            if(operationalStateList.stream().anyMatch(this::isNotEnabled)) {
+                throw new APPCException("at least one "+OPERATIONAL_STATE_ELEMENT_NAME+" is not in valid state. "
+                        +operationalStateList.toString());
             }
-        } catch (Exception e ) {
-            isValid = false;
-            errorMsg = e.toString();
+
+        } catch (Exception e) {
+            throw new APPCException(e);
         }
-        if(!isValid) throw new APPCException(errorMsg);
     }
 
-    private static List<Map.Entry> getOperationalStateList(String xmlText) throws IOException, ParserConfigurationException, SAXException {
+    private boolean isNotEnabled(Map.Entry stateEntry) {
+        return !("ENABLED").equalsIgnoreCase((String)stateEntry.getValue());
+    }
+
+    private static Optional<List<Map.Entry>> getOperationalStateList(String xmlText) throws IOException, ParserConfigurationException, SAXException {
         List<Map.Entry> entryList = null;
-        if(StringUtils.isNotEmpty(xmlText)) {
-            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-            DocumentBuilder builder = factory.newDocumentBuilder();
-
-            Document document = builder.parse(new ByteArrayInputStream(xmlText.getBytes("UTF-8")));
-            if(document != null) {
-                Element rootElement = document.getDocumentElement();
-                NodeList nodeList = rootElement.getElementsByTagName(OPERATIONAL_STATE_ELEMENT_NAME);
-                if (nodeList != null && nodeList.getLength() > 0) {
-                    for (int i = 0; i < nodeList.getLength(); i++) {
-                        Node node = nodeList.item(i);
-                        String text = node.getTextContent();
-                        String id = getElementID(node);
-                        entryList = (entryList == null) ? new ArrayList<Map.Entry>() : entryList;
-                        Map.Entry entry = new AbstractMap.SimpleEntry<String, String>(id, text);
-                        entryList.add(entry);
-                    }
+
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        DocumentBuilder builder = factory.newDocumentBuilder();
+        Document document = builder.parse(new ByteArrayInputStream(xmlText.getBytes("UTF-8")));
+
+        if(document != null) {
+            Element rootElement = document.getDocumentElement();
+            NodeList nodeList = rootElement.getElementsByTagName(OPERATIONAL_STATE_ELEMENT_NAME);
+            if (nodeList != null && nodeList.getLength() > 0) {
+                entryList = new ArrayList<>();
+                for (int i = 0; i < nodeList.getLength(); i++) {
+                    Node node = nodeList.item(i);
+                    String text = node.getTextContent();
+                    String id = getElementID(node);
+                    Map.Entry entry = new AbstractMap.SimpleEntry<>(id, text);
+                    entryList.add(entry);
                 }
             }
         }
-        return entryList;
+        return Optional.ofNullable(entryList);
     }
 
     private static String getElementID(Node node) {
index 2d8c6f4..bb2a333 100644 (file)
@@ -71,26 +71,17 @@ public class NetconfAdapter {
         final NetconfMessage message = new NetconfMessage();
         final byte[] buf = new byte[1024];
 
-        //int readByte = 1;
         // Read data with timeout
-        Callable<Boolean> readTask = new Callable<Boolean>() {
-            @Override
-            public Boolean call() throws Exception {
-                int c;
-                while ((c = in.read(buf)) > 0) {
-                    if (c > 0) {
-                        message.append(buf, 0, c);
-                        if (message.isCompleted()) {
-                            break;
-                        }
-                    }
+        Callable<Boolean> readTask = () -> {
+            int c;
+            while ((c = in.read(buf)) > 0) {
+                message.append(buf, 0, c);
+                if (message.isCompleted()) {
+                    break;
                 }
-
-                if (c < 0) {
-                    return false;
-                }
-                return true;
             }
+
+            return c >= 0;
         };
 
         Future<Boolean> future = executor.submit(readTask);
@@ -101,7 +92,7 @@ public class NetconfAdapter {
             throw new IOException(e);
         }
 
-        if (status == false) {
+        if (!status) {
             throw new IOException("Failed to read netconf message");
         }
 
index c7ad9bc..897788e 100644 (file)
@@ -26,8 +26,10 @@ package org.onap.appc.adapter.netconf.internal;
 
 public class NetconfConstMessages {
 
+    private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+
     public static final String CAPABILITIES_START =
-            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+            XML_HEADER +
                     "<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
                     "  <capabilities>\n";
 
@@ -39,7 +41,7 @@ public class NetconfConstMessages {
                     "</hello>";
 
     public static final String GET_RUNNING_CONFIG =
-            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+            XML_HEADER +
                     "<rpc message-id=\"1\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
                     "    <get-config>\n" +
                     "        <source>\n" +
@@ -49,8 +51,10 @@ public class NetconfConstMessages {
                     "</rpc>";
 
     public static final String CLOSE_SESSION =
-            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+            XML_HEADER +
                     "<rpc message-id=\"terminateConnection\" xmlns:netconf=\"urn:ietf:params:xml:ns:netconf:base:1.0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" +
                     "    <close-session/>\n" +
                     "</rpc>";
+
+    private NetconfConstMessages() {}
 }
index 6ed181d..7a6848b 100644 (file)
@@ -41,18 +41,21 @@ public class NetconfDataAccessServiceImpl implements NetconfDataAccessService {
 
     private final EELFLogger logger = EELFManager.getInstance().getLogger(NetconfDataAccessServiceImpl.class);
 
+    private String schema;
+
+    private DbLibService dbLibService;
+
+    @Override
     public void setSchema(String schema) {
         this.schema = schema;
     }
 
-    private String schema;
-
+    @Override
     public void setDbLibService(DbLibService service) {dbLibService = service;}
 
-    private DbLibService dbLibService;
 
     @Override
-    public String retrieveConfigFileName(String xmlID) throws DataAccessException {
+    public String retrieveConfigFileName(String xmlID) {
         String fileContent = "";
 
         String queryString = "select " + Constants.FILE_CONTENT_TABLE_FIELD_NAME + " " +
@@ -76,8 +79,7 @@ public class NetconfDataAccessServiceImpl implements NetconfDataAccessService {
     }
 
     @Override
-    public boolean retrieveConnectionDetails(String vnfType, ConnectionDetails connectionDetails) throws
-                    DataAccessException {
+    public boolean retrieveConnectionDetails(String vnfType, ConnectionDetails connectionDetails) {
         boolean recordFound = false;
 
         String queryString = "select " + Constants.USER_NAME_TABLE_FIELD_NAME + "," +
@@ -105,8 +107,7 @@ public class NetconfDataAccessServiceImpl implements NetconfDataAccessService {
     }
 
     @Override
-    public boolean retrieveNetconfConnectionDetails(String vnfType, NetconfConnectionDetails connectionDetails)
-            throws DataAccessException {
+    public boolean retrieveNetconfConnectionDetails(String vnfType, NetconfConnectionDetails connectionDetails) {
         ConnectionDetails connDetails = new ConnectionDetails();
         if(this.retrieveConnectionDetails(vnfType, connDetails))
         {
@@ -119,8 +120,7 @@ public class NetconfDataAccessServiceImpl implements NetconfDataAccessService {
     }
 
     @Override
-    public boolean logDeviceInteraction(String instanceId, String requestId, String creationDate, String logText)
-            throws DataAccessException {
+    public boolean logDeviceInteraction(String instanceId, String requestId, String creationDate, String logText) {
         String queryString = "INSERT INTO "+ Constants.DEVICE_INTERFACE_LOG_TABLE_NAME+"("+
                 Constants.SERVICE_INSTANCE_ID_FIELD_NAME+","+
                 Constants.REQUEST_ID_FIELD_NAME+","+
index 700a51b..40e0096 100644 (file)
@@ -47,8 +47,9 @@ class NetconfMessage {
         }
     }
 
-    void append(byte[] bytes, int start, int end) {
+    void append(byte[] bytes, int start, int finish) {
         boolean eomFound = false;
+        int end = finish;
         for(int i = start; i < end; i++) {
             if(bytes[i] == EOM.charAt(eomNotch)) {
                 // advance notch
@@ -76,7 +77,7 @@ class NetconfMessage {
     }
 
     boolean isCompleted() {
-        return (text != null);
+        return text != null;
     }
 
     byte[] getFrame() {
index 37bb3b2..ffcd903 100644 (file)
@@ -58,6 +58,8 @@ public class JSchLogger implements com.jcraft.jsch.Logger {
             case com.jcraft.jsch.Logger.FATAL:
                 LOG.error(message);
                 break;
+            default:
+                break;
         }
     }
 }
index 7b9d7a4..c60fbbd 100644 (file)
@@ -75,17 +75,9 @@ public class NetconfClientJsch implements NetconfClient {
 
             session.connect(SESSION_CONNECT_TIMEOUT);
             session.setTimeout(10000);
-            try {
-//                session.setServerAliveCountMax(0); // If this is not set to '0', then socket timeout on all reads will not work!!!!
-                channel = session.openChannel("subsystem");
-                ((ChannelSubsystem)channel).setSubsystem("netconf");
-                netconfAdapter = new NetconfAdapter(channel.getInputStream(), channel.getOutputStream());
-                channel.connect(CHANNEL_CONNECT_TIMEOUT);
-                hello(connectionDetails.getCapabilities());
-            } catch(Exception e) {
-                disconnect();
-                throw e;
-            }
+
+            createConnection(connectionDetails);
+
         } catch(Exception e) {
             String message = EELFResourceManager.format(Msg.CANNOT_ESTABLISH_CONNECTION, host, String.valueOf(port), username);
             throw new APPCException(message, e);
@@ -138,6 +130,20 @@ public class NetconfClientJsch implements NetconfClient {
         }
     }
 
+    private void createConnection(NetconfConnectionDetails connectionDetails) throws APPCException {
+        try {
+//          session.setServerAliveCountMax(0); // If this is not set to '0', then socket timeout on all reads will not work!!!!
+            channel = session.openChannel("subsystem");
+            ((ChannelSubsystem)channel).setSubsystem("netconf");
+            netconfAdapter = new NetconfAdapter(channel.getInputStream(), channel.getOutputStream());
+            channel.connect(CHANNEL_CONNECT_TIMEOUT);
+            hello(connectionDetails.getCapabilities());
+        } catch(Exception e) {
+            disconnect();
+            throw new APPCException(e);
+        }
+    }
+
     private void hello(List<String> capabilities) throws IOException {
         String helloIn = netconfAdapter.receiveMessage();
         if(helloIn == null) {
index b559bc7..09281f4 100644 (file)
 
 package org.onap.appc.adapter.netconf.jsch;
 
+import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
+
 import java.util.Collections;
 import java.util.List;
 
-import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
-import org.onap.appc.adapter.netconf.jsch.NetconfClientJsch;
-import org.onap.appc.exceptions.APPCException;
-
 public class TestGetRunningConfig {
 
     private static final String HOST = "192.168.1.2";
@@ -39,7 +37,7 @@ public class TestGetRunningConfig {
     private static final int PORT = 830;
     private static final List<String> CAPABILITIES = Collections.singletonList("<capability>urn:org:onap:appc:capability:1.1.0</capability>");
 
-    public static void main(String[] args) throws APPCException {
+    public static void main(String[] args) {
         try {
             NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
             connectionDetails.setHost(HOST);
index 8096253..8750473 100644 (file)
 
 package org.onap.appc.adapter.netconf.jsch;
 
+import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
+
 import java.util.Collections;
 import java.util.List;
 
-import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
-import org.onap.appc.adapter.netconf.jsch.NetconfClientJsch;
-import org.onap.appc.exceptions.APPCException;
-
 public class TestModifyConfig {
 
     private static final String HOST = "192.168.1.2";
@@ -64,7 +62,7 @@ public class TestModifyConfig {
             "  </edit-config>\n" +
             "</rpc>";
 
-    public static void main(String[] args) throws APPCException {
+    public static void main(String[] args) {
         try {
             NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
             connectionDetails.setHost(HOST);
index 915721d..31dee09 100644 (file)
 
 package org.onap.appc.adapter.netconf.jsch;
 
+import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
+
 import java.util.Collections;
 import java.util.List;
 
-import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
-import org.onap.appc.adapter.netconf.jsch.NetconfClientJsch;
-import org.onap.appc.exceptions.APPCException;
-
 public class TestModifyConfigMock {
 
     private static final String HOST = "192.168.1.2";
@@ -64,7 +62,7 @@ public class TestModifyConfigMock {
             "  </edit-config>\n" +
             "</rpc>";
 
-    public static void main(String[] args) throws APPCException {
+    public static void main(String[] args) {
         try {
             NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
             connectionDetails.setHost(HOST);
index 83e62bc..1001c01 100644 (file)
 
 package org.onap.appc.adapter.netconf.jsch;
 
+import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
+
 import java.util.Collections;
 import java.util.List;
 
-import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
-import org.onap.appc.adapter.netconf.jsch.NetconfClientJsch;
-import org.onap.appc.exceptions.APPCException;
-
 public class TestModifyConfigRouterMock {
 
     private static final String HOST = "10.147.27.50"; // yuma netconf simulator
@@ -66,7 +64,7 @@ public class TestModifyConfigRouterMock {
             "  </edit-config>\n" +
             "</rpc>\n";
 
-    public static void main(String[] args) throws APPCException {
+    public static void main(String[] args) {
         try {
             NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
             connectionDetails.setHost(HOST);
index 263dd5a..a8c9e28 100644 (file)
 
 package org.onap.appc.adapter.netconf.jsch;
 
+import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
+
 import java.util.Collections;
 import java.util.List;
 
-import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
-import org.onap.appc.adapter.netconf.jsch.NetconfClientJsch;
-import org.onap.appc.exceptions.APPCException;
-
 public class TestOperationalStates {
 
     private static final String HOST = "192.168.1.2";
@@ -62,7 +60,7 @@ public class TestOperationalStates {
             "       </get>\n" +
             "</rpc>";
 
-    public static void main(String[] args) throws APPCException {
+    public static void main(String[] args) {
         try {
             NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
             connectionDetails.setHost(HOST);
index 1742264..1684f1c 100644 (file)
@@ -69,8 +69,8 @@ public class NetconfClientPluginImpl implements NetconfClientPlugin {
     public void configure(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
 
         try {
-            // by default, it uses the jsch Netconf Adapter implementation by calling GetNetconfClient(NetconfClientType.SSH).
-            NetconfClient client = clientFactory.GetNetconfClient(NetconfClientType.SSH);
+            // by default, it uses the jsch Netconf Adapter implementation by calling getNetconfClient(NetconfClientType.SSH).
+            NetconfClient client = clientFactory.getNetconfClient(NetconfClientType.SSH);
             try {
                 NetconfConnectionDetails connectionDetails = mapper.readValue(params.get("connection-details"), NetconfConnectionDetails.class);
                 String netconfMessage = params.get("file-content");
@@ -127,7 +127,7 @@ public class NetconfClientPluginImpl implements NetconfClientPlugin {
             }
 
             //connect checK Opertaions state and dissconnect
-            NetconfClient client = clientFactory.GetNetconfClient(NetconfClientType.SSH);
+            NetconfClient client = clientFactory.getNetconfClient(NetconfClientType.SSH);
             try {
                 client.connect(connectionDetails);
                 String response = null;
@@ -164,7 +164,7 @@ public class NetconfClientPluginImpl implements NetconfClientPlugin {
                 logger.debug("Entered backup to DEVICE_INTERFACE_LOG");
             }
 
-            client = clientFactory.GetNetconfClient(NetconfClientType.SSH);
+            client = clientFactory.getNetconfClient(NetconfClientType.SSH);
             //get connection details
             NetconfConnectionDetails connectionDetails = mapper.readValue(params.get("connection-details"), NetconfConnectionDetails.class);
             //connect the client and get configuration
@@ -199,7 +199,7 @@ public class NetconfClientPluginImpl implements NetconfClientPlugin {
                 BundleContext bctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
                 ServiceReference sref = bctx.getServiceReference(NETCONF_CLIENT_FACTORY_NAME);
                 NetconfClientFactory clientFactory = (NetconfClientFactory) bctx.getService(sref);
-                client = clientFactory.GetNetconfClient(NetconfClientType.SSH);
+                client = clientFactory.getNetconfClient(NetconfClientType.SSH);
                 //get connection details
                 NetconfConnectionDetails connectionDetails = mapper.readValue(params.get("connection-details"), NetconfConnectionDetails.class);
                 //connect the client and get configuration
@@ -245,7 +245,7 @@ public class NetconfClientPluginImpl implements NetconfClientPlugin {
             BundleContext bctx = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
             ServiceReference sref = bctx.getServiceReference(NETCONF_CLIENT_FACTORY_NAME);
             NetconfClientFactory clientFactory = (NetconfClientFactory) bctx.getService(sref);
-            client = clientFactory.GetNetconfClient(NetconfClientType.SSH);
+            client = clientFactory.getNetconfClient(NetconfClientType.SSH);
             //get connection details
             NetconfConnectionDetails connectionDetails = new NetconfConnectionDetails();
             connectionDetails.setHost(params.get("host-ip-address"));
index f61d188..52307b9 100644 (file)
@@ -36,7 +36,7 @@ public class NetconfClientFactoryMock extends NetconfClientFactory {
     private final NetconfClientJschMock jschClient = new NetconfClientJschMock();
 
     @Override
-    public NetconfClient GetNetconfClient(NetconfClientType type){
+    public NetconfClient getNetconfClient(NetconfClientType type){
 
             return jschClient;
 
index 0becff7..220328c 100644 (file)
@@ -34,7 +34,6 @@ 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.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -129,7 +128,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());
@@ -154,7 +153,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 {
@@ -174,7 +173,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);
 
 
@@ -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,7 +233,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);
 
 
@@ -270,7 +269,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("wrong");
 
 
@@ -303,7 +302,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);
         ((DAOServiceMock) dao).setConnection(getConnectionDetails());
 
@@ -331,7 +330,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);
         ((DAOServiceMock) dao).setConnection(getConnectionDetails());
 
@@ -359,7 +358,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);
 
@@ -383,7 +382,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);
         try {
             netconfClientPlugin.backupConfiguration(params, ctx);
@@ -408,7 +407,7 @@ 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);
 
 
@@ -500,7 +499,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 +518,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 {
index 2194fc1..9472b69 100644 (file)
@@ -30,7 +30,7 @@ import org.onap.appc.adapter.netconf.*;
 
 public class OperationStateValidatorFactoryMock extends OperationalStateValidatorFactory {
     public static OperationalStateValidator getOperationalStateValidator(String vnfType) {
-        VnfType vnfTypeEnum = null;
+        VnfType vnfTypeEnum;
         try {
             vnfTypeEnum = VnfType.getVnfType(vnfType);
         } catch (IllegalArgumentException e) {
@@ -45,6 +45,4 @@ public class OperationStateValidatorFactoryMock extends OperationalStateValidato
 
 
     }
-
-
 }