Unit test for client monitoring
[policy/apex-pdp.git] / client / client-monitoring / src / main / java / org / onap / policy / apex / client / monitoring / rest / ParameterCheck.java
index acaee5f..34bacb9 100644 (file)
@@ -69,6 +69,10 @@ public final class ParameterCheck {
      * @return the host name
      */
     public static String getHostName(final Map<String, String[]> parameterMap) {
+        if (parameterMap == null) {
+            return null;
+        }
+        
         if (!parameterMap.containsKey(HOSTNAME_PAR)) {
             LOGGER.warn(PARAMETER + HOSTNAME_PAR + NOT_FOUND);
             return null;
@@ -76,6 +80,10 @@ public final class ParameterCheck {
 
         final String[] hostNameValue = parameterMap.get(HOSTNAME_PAR);
 
+        if (hostNameValue == null) {
+            return null;
+        }
+
         if (hostNameValue.length == 0 || hostNameValue[0].trim().length() == 0) {
             LOGGER.warn("value of parameter \"" + HOSTNAME_PAR + NOT_FOUND);
             return null;
@@ -91,13 +99,21 @@ public final class ParameterCheck {
      * @return the port
      */
     public static int getPort(final Map<String, String[]> parameterMap) {
+        if (parameterMap == null) {
+            return -1;
+        }
+        
         if (!parameterMap.containsKey(PORT_PAR)) {
             LOGGER.warn(PARAMETER + PORT_PAR + NOT_FOUND);
             return -1;
         }
 
         final String[] portValue = parameterMap.get(PORT_PAR);
-
+        
+        if (portValue == null) {
+            return -1;
+        }
+        
         if (portValue.length == 0 || portValue[0].trim().length() == 0) {
             LOGGER.warn("value of parameter \"" + PORT_PAR + NOT_FOUND);
             return -1;
@@ -127,6 +143,10 @@ public final class ParameterCheck {
      * @return the engine key
      */
     public static AxArtifactKey getEngineKey(final Map<String, String[]> parameterMap) {
+        if (parameterMap == null) {
+            return null;
+        }
+        
         String artifactKeyParameter = null;
         for (final String parameter : parameterMap.keySet()) {
             // Check for an AxArtifactKey parameter
@@ -147,7 +167,13 @@ public final class ParameterCheck {
             return null;
         }
 
-        return new AxArtifactKey(axArtifactKeyArray[1]);
+        try {
+            return new AxArtifactKey(axArtifactKeyArray[1]);
+        }
+        catch (Exception apEx) {
+            LOGGER.trace("invalid artifact key ID {}", axArtifactKeyArray[1], apEx);
+            return null;
+        }
     }
 
     /**
@@ -159,6 +185,10 @@ public final class ParameterCheck {
      */
     public static ParameterCheck.StartStop getStartStop(final Map<String, String[]> parameterMap,
                     final AxArtifactKey engineKey) {
+        if (parameterMap == null || engineKey == null) {
+            return null;
+        }
+        
         final String startStopPar = AXARTIFACTKEY_PAR + '#' + engineKey.getId();
         if (!parameterMap.containsKey(startStopPar)) {
             LOGGER.warn("parameter \"{}\" not found", startStopPar);
@@ -166,6 +196,10 @@ public final class ParameterCheck {
         }
 
         final String[] startStopValue = parameterMap.get(startStopPar);
+        
+        if (startStopValue == null) {
+            return null;
+        }
 
         if (startStopValue.length == 0 || startStopValue[0].trim().length() == 0) {
             LOGGER.warn("value of parameter \"{}\" not found", startStopPar);
@@ -193,6 +227,10 @@ public final class ParameterCheck {
      * @return The long value
      */
     public static long getLong(final Map<String, String[]> parameterMap, final String longName) {
+        if (parameterMap == null || longName == null) {
+            return -1;
+        }
+        
         if (!parameterMap.containsKey(longName)) {
             LOGGER.warn("parameter \"{}\" not found", longName);
             return -1;
@@ -200,6 +238,10 @@ public final class ParameterCheck {
 
         final String[] longValue = parameterMap.get(longName);
 
+        if (longValue == null) {
+            return -1;
+        }
+        
         if (longValue.length == 0 || longValue[0].trim().length() == 0) {
             LOGGER.warn("value of parameter \"{}\" not found", longName);
             return -1;