diff options
author | liamfallon <liam.fallon@ericsson.com> | 2018-09-28 22:48:30 +0100 |
---|---|---|
committer | liamfallon <liam.fallon@ericsson.com> | 2018-09-30 22:17:06 +0100 |
commit | acb59c7b0ccbb86f4c38a94b72e7bab73b2acf8f (patch) | |
tree | e2f4a368b3a04572babc1df900369f6954fcc6da /client/client-monitoring/src/main/java | |
parent | 4ee8953bc55f2b905dee845728b3287eb4e8e795 (diff) |
Unit test for client monitoring
Coverage for the client monitoring module.
Issue-ID: POLICY-1034
Change-Id: I6bb6dab26ce0572923c3d451a3b5f4745d40d088
Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'client/client-monitoring/src/main/java')
2 files changed, 80 insertions, 3 deletions
diff --git a/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestResource.java b/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestResource.java index 6b7f12061..07e2efd13 100644 --- a/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestResource.java +++ b/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestResource.java @@ -213,7 +213,7 @@ public class ApexMonitoringRestResource { } /** - * Start/Stop and Apex engine. + * Start/Stop Apex engine Periodic Events. * * @param hostName the host name of the engine service to connect to. * @param port the port number of the engine service to connect to. @@ -332,6 +332,41 @@ public class ApexMonitoringRestResource { return super.add(elm); } + private ApexMonitoringRestResource getOuterType() { + return ApexMonitoringRestResource.this; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + getOuterType().hashCode(); + result = prime * result + maxEntries; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (!super.equals(obj)) { + return false; + } + + if (getClass() != obj.getClass()) { + return false; + } + + @SuppressWarnings("unchecked") + SlidingWindowList<V> other = (SlidingWindowList<V>) obj; + if (!getOuterType().equals(other.getOuterType())) { + return false; + } + + return maxEntries == other.maxEntries; + } } /** diff --git a/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ParameterCheck.java b/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ParameterCheck.java index acaee5fdb..34bacb974 100644 --- a/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ParameterCheck.java +++ b/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ParameterCheck.java @@ -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; |