diff options
author | Lukasz Muszkieta <lukasz.muszkieta@nokia.com> | 2021-11-19 16:54:25 +0100 |
---|---|---|
committer | Lukasz Muszkieta <lukasz.muszkieta@nokia.com> | 2021-11-19 16:54:25 +0100 |
commit | 4b896fb742ce79793957077450a7ba815bf64a7a (patch) | |
tree | 096e389b4573226fea851a4a65971109d0280d89 /so-optimization-clients/src | |
parent | 469cd2266c732713b01ebbe4d31b2e7640f91dd7 (diff) |
add junit coverage
Issue-ID: SO-3796
Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
Change-Id: Ic499c0ec10548f1f2297b66f60faa99e6cd6dd6c
Diffstat (limited to 'so-optimization-clients/src')
-rw-r--r-- | so-optimization-clients/src/main/java/org/onap/so/client/sniro/SniroValidator.java | 22 | ||||
-rw-r--r-- | so-optimization-clients/src/test/java/org/onap/so/client/sniro/SniroValidatorTest.java | 62 |
2 files changed, 74 insertions, 10 deletions
diff --git a/so-optimization-clients/src/main/java/org/onap/so/client/sniro/SniroValidator.java b/so-optimization-clients/src/main/java/org/onap/so/client/sniro/SniroValidator.java index fc16125433..9a66f75311 100644 --- a/so-optimization-clients/src/main/java/org/onap/so/client/sniro/SniroValidator.java +++ b/so-optimization-clients/src/main/java/org/onap/so/client/sniro/SniroValidator.java @@ -24,7 +24,7 @@ package org.onap.so.client.sniro; import static org.apache.commons.lang3.StringUtils.*; -import java.util.LinkedHashMap; +import java.util.Map; import org.json.JSONObject; import org.onap.so.client.exception.BadResponseException; import org.slf4j.Logger; @@ -38,12 +38,14 @@ public class SniroValidator { private static final Logger logger = LoggerFactory.getLogger(SniroValidator.class); + private static final String MESSAGE_NOT_PROVIDED = "error message not provided"; + /** * Validates the synchronous homing response from sniro manager * * @throws BadResponseException */ - public void validateDemandsResponse(LinkedHashMap<String, Object> response) throws BadResponseException { + public void validateDemandsResponse(Map<String, Object> response) throws BadResponseException { logger.debug("Validating Sniro Managers synchronous response"); if (!response.isEmpty()) { JSONObject jsonResponse = new JSONObject(response); @@ -54,10 +56,10 @@ public class SniroValidator { } else { String message = jsonResponse.getString("statusMessage"); if (isNotBlank(message)) { - logger.debug("Sniro Managers response indicates failed: " + message); + logger.debug("Sniro Managers response indicates failed: {}", message); } else { logger.debug("Sniro Managers response indicates failed: no status message provided"); - message = "error message not provided"; + message = MESSAGE_NOT_PROVIDED; } throw new BadResponseException("Sniro Managers synchronous response indicates failed: " + message); } @@ -67,7 +69,7 @@ public class SniroValidator { } } else { logger.debug("Sniro Managers synchronous response is empty"); - throw new BadResponseException("Sniro Managers synchronous response i is empty"); + throw new BadResponseException("Sniro Managers synchronous response is empty"); } } @@ -85,11 +87,11 @@ public class SniroValidator { } else { String message = jsonResponse.getJSONObject("serviceException").getString("text"); if (isNotBlank(message)) { - logger.debug("Sniro Managers response contains a service exception: " + message); + logger.debug("Sniro Managers response contains a service exception: {}", message); } else { logger.debug( "Sniro Managers response contains a service exception: no service exception text provided"); - message = "error message not provided"; + message = MESSAGE_NOT_PROVIDED; } throw new BadResponseException( "Sniro Managers asynchronous response contains a service exception: " + message); @@ -106,7 +108,7 @@ public class SniroValidator { * * @throws BadResponseException */ - public void validateReleaseResponse(LinkedHashMap<String, Object> response) throws BadResponseException { + public void validateReleaseResponse(Map<String, Object> response) throws BadResponseException { logger.debug("Validating Sniro Conductors response"); if (!response.isEmpty()) { String status = (String) response.get("status"); @@ -116,10 +118,10 @@ public class SniroValidator { } else { String message = (String) response.get("message"); if (isNotBlank(message)) { - logger.debug("Sniro Conductors response indicates failed: " + message); + logger.debug("Sniro Conductors response indicates failed: {}", message); } else { logger.debug("Sniro Conductors response indicates failed: error message not provided"); - message = "error message not provided"; + message = MESSAGE_NOT_PROVIDED; } throw new BadResponseException( "Sniro Conductors synchronous response indicates failed: " + message); diff --git a/so-optimization-clients/src/test/java/org/onap/so/client/sniro/SniroValidatorTest.java b/so-optimization-clients/src/test/java/org/onap/so/client/sniro/SniroValidatorTest.java new file mode 100644 index 0000000000..8288d70c21 --- /dev/null +++ b/so-optimization-clients/src/test/java/org/onap/so/client/sniro/SniroValidatorTest.java @@ -0,0 +1,62 @@ +package org.onap.so.client.sniro; + +import static org.assertj.core.api.Assertions.assertThat; +import java.util.LinkedHashMap; +import java.util.Map; +import org.junit.Test; +import org.onap.so.client.exception.BadResponseException; + +public class SniroValidatorTest { + + @Test + public void validateDemandsResponse_success() throws BadResponseException { + Map<String, Object> testMap = new LinkedHashMap<>(); + testMap.put("requestStatus", "accepted"); + new SniroValidator().validateDemandsResponse(testMap); + } + + @Test + public void validateDemandsResponse_emptyResponse() { + try { + new SniroValidator().validateDemandsResponse(new LinkedHashMap<>()); + } catch (BadResponseException e) { + assertThat(e.getMessage()).contains("Sniro Managers synchronous response is empty"); + } + } + + @Test + public void validateDemandsResponse_responseWithErrorMessage() { + String message = "An error occurred"; + Map<String, Object> testMap = new LinkedHashMap<>(); + testMap.put("requestStatus", "not_accepted"); + testMap.put("statusMessage", message); + try { + new SniroValidator().validateDemandsResponse(testMap); + } catch (BadResponseException e) { + assertThat(e.getMessage()).contains("Sniro Managers synchronous response indicates failed: " + message); + } + } + + @Test + public void validateDemandsResponse_responseWithoutMessage() { + Map<String, Object> testMap = new LinkedHashMap<>(); + testMap.put("requestStatus", "not_accepted"); + testMap.put("statusMessage", ""); + try { + new SniroValidator().validateDemandsResponse(testMap); + } catch (BadResponseException e) { + assertThat(e.getMessage()).contains("error message not provided"); + } + } + + @Test + public void validateDemandsResponse_responseWithoutRequestStatus() { + Map<String, Object> testMap = new LinkedHashMap<>(); + testMap.put("statusMessage", ""); + try { + new SniroValidator().validateDemandsResponse(testMap); + } catch (BadResponseException e) { + assertThat(e.getMessage()).contains("Sniro Managers synchronous response does not contain: request status"); + } + } +} |