diff options
Diffstat (limited to 'cps-service/src')
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/spi/model/CmHandleQueryServiceParameters.java (renamed from cps-service/src/main/java/org/onap/cps/spi/model/CmHandleQueryParameters.java) | 2 | ||||
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java | 43 | ||||
-rwxr-xr-x | cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy | 1 | ||||
-rw-r--r-- | cps-service/src/test/groovy/org/onap/cps/utils/CmHandleQueryRestParametersValidatorSpec.groovy | 8 |
4 files changed, 28 insertions, 26 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/CmHandleQueryParameters.java b/cps-service/src/main/java/org/onap/cps/spi/model/CmHandleQueryServiceParameters.java index cf364db3a8..8dcf88b0eb 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/model/CmHandleQueryParameters.java +++ b/cps-service/src/main/java/org/onap/cps/spi/model/CmHandleQueryServiceParameters.java @@ -34,7 +34,7 @@ import lombok.Setter; @Getter @EqualsAndHashCode @JsonInclude(Include.NON_EMPTY) -public class CmHandleQueryParameters { +public class CmHandleQueryServiceParameters { @JsonProperty("cmHandleQueryParameters") @Valid private List<ConditionProperties> cmHandleQueryParameters = Collections.emptyList(); diff --git a/cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java b/cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java index c510a73af2..c3811eb485 100644 --- a/cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java +++ b/cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java @@ -27,7 +27,7 @@ import java.util.Map; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.onap.cps.spi.exceptions.DataValidationException; -import org.onap.cps.spi.model.CmHandleQueryParameters; +import org.onap.cps.spi.model.CmHandleQueryServiceParameters; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class CmHandleQueryRestParametersValidator { @@ -36,10 +36,11 @@ public class CmHandleQueryRestParametersValidator { /** * Validate cm handle query parameters. - * @param cmHandleQueryParameters name of data to be validated + * @param cmHandleQueryServiceParameters name of data to be validated */ - public static void validateCmHandleQueryParameters(final CmHandleQueryParameters cmHandleQueryParameters) { - cmHandleQueryParameters.getCmHandleQueryParameters().forEach( + public static void validateCmHandleQueryParameters( + final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) { + cmHandleQueryServiceParameters.getCmHandleQueryParameters().forEach( conditionApiProperty -> { if (Strings.isNullOrEmpty(conditionApiProperty.getConditionName())) { throwDataValidationException("Missing 'conditionName' - please supply a valid name."); @@ -54,27 +55,29 @@ public class CmHandleQueryRestParametersValidator { "Empty 'conditionsParameters' - please supply a valid condition parameter."); } conditionApiProperty.getConditionParameters().forEach( - conditionParameter -> { - if (conditionParameter.isEmpty()) { - throwDataValidationException( - "Empty 'conditionsParameter' - please supply a valid condition parameter."); - } - if (conditionParameter.size() > 1) { - throwDataValidationException("Too many name in one 'conditionsParameter' -" - + " please supply one name in one condition parameter."); - } - conditionParameter.forEach((key, value) -> { - if (Strings.isNullOrEmpty(key)) { - throwDataValidationException( - "Missing 'conditionsParameterName' - please supply a valid name."); - } - }); - } + CmHandleQueryRestParametersValidator::validateConditionParameter ); } ); } + private static void validateConditionParameter(final Map<String, String> conditionParameter) { + if (conditionParameter.isEmpty()) { + throwDataValidationException( + "Empty 'conditionsParameter' - please supply a valid condition parameter."); + } + if (conditionParameter.size() > 1) { + throwDataValidationException("Too many name in one 'conditionsParameter' -" + + " please supply one name in one condition parameter."); + } + conditionParameter.forEach((key, value) -> { + if (Strings.isNullOrEmpty(key)) { + throwDataValidationException( + "Missing 'conditionsParameterName' - please supply a valid name."); + } + }); + } + /** * Validate module name condition properties. * @param conditionProperty name of data to be validated diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy index def99e21f4..41fcb29edd 100755 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy @@ -26,7 +26,6 @@ import org.onap.cps.api.CpsDataService import org.onap.cps.spi.CpsAdminPersistenceService import org.onap.cps.spi.exceptions.DataValidationException import org.onap.cps.spi.model.Anchor -import org.onap.cps.spi.model.CmHandleQueryParameters import spock.lang.Specification import java.time.OffsetDateTime diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/CmHandleQueryRestParametersValidatorSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/CmHandleQueryRestParametersValidatorSpec.groovy index 645829b2a2..a9b04c1ced 100644 --- a/cps-service/src/test/groovy/org/onap/cps/utils/CmHandleQueryRestParametersValidatorSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/utils/CmHandleQueryRestParametersValidatorSpec.groovy @@ -21,14 +21,14 @@ package org.onap.cps.utils import org.onap.cps.spi.exceptions.DataValidationException -import org.onap.cps.spi.model.CmHandleQueryParameters +import org.onap.cps.spi.model.CmHandleQueryServiceParameters import org.onap.cps.spi.model.ConditionProperties import spock.lang.Specification class CmHandleQueryRestParametersValidatorSpec extends Specification { def 'CM Handle Query validation: empty query.'() { given: 'a cm handle query' - def cmHandleQueryParameters = new CmHandleQueryParameters() + def cmHandleQueryParameters = new CmHandleQueryServiceParameters() when: 'validator is invoked' CmHandleQueryRestParametersValidator.validateCmHandleQueryParameters(cmHandleQueryParameters) then: 'data validation exception is not thrown' @@ -37,7 +37,7 @@ class CmHandleQueryRestParametersValidatorSpec extends Specification { def 'CM Handle Query validation: normal query.'() { given: 'a cm handle query' - def cmHandleQueryParameters = new CmHandleQueryParameters() + def cmHandleQueryParameters = new CmHandleQueryServiceParameters() def condition = new ConditionProperties() condition.conditionName = 'hasAllProperties' condition.conditionParameters = [[key1:'value1'],[key2:'value2']] @@ -50,7 +50,7 @@ class CmHandleQueryRestParametersValidatorSpec extends Specification { def 'CM Handle Query validation: #scenario.'() { given: 'a cm handle query' - def cmHandleQueryParameters = new CmHandleQueryParameters() + def cmHandleQueryParameters = new CmHandleQueryServiceParameters() def condition = new ConditionProperties() condition.conditionName = conditionName condition.conditionParameters = conditionParameters |