diff options
author | Toine Siebelink <toine.siebelink@est.tech> | 2022-09-02 12:00:13 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2022-09-02 12:00:13 +0000 |
commit | 3c29b33cb1f9398106921e5d9510c62c34cc7694 (patch) | |
tree | be5ff4746518584bb76e3105b2d233915bcc7115 /cps-service | |
parent | 99ac70ab25a0c650e7f1ded19fd48296adff7f73 (diff) | |
parent | bbaf501627a69707bd797c535750996a9dd205aa (diff) |
Merge "Implement merging all ncmp datastore endpoints into one"
Diffstat (limited to 'cps-service')
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/utils/CpsValidator.java | 18 | ||||
-rw-r--r-- | cps-service/src/test/groovy/org/onap/cps/utils/CpsValidatorSpec.groovy | 14 |
2 files changed, 6 insertions, 26 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/utils/CpsValidator.java b/cps-service/src/main/java/org/onap/cps/utils/CpsValidator.java index 28b49c9666..f3774d9529 100644 --- a/cps-service/src/main/java/org/onap/cps/utils/CpsValidator.java +++ b/cps-service/src/main/java/org/onap/cps/utils/CpsValidator.java @@ -22,7 +22,6 @@ package org.onap.cps.utils; import com.google.common.collect.Lists; import java.util.Collection; -import java.util.regex.Pattern; import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -33,30 +32,25 @@ import org.onap.cps.spi.exceptions.DataValidationException; public final class CpsValidator { private static final char[] UNSUPPORTED_NAME_CHARACTERS = "!\" #$%&'()*+,./\\:;<=>?@[]^`{|}~".toCharArray(); - private static final Pattern TOPIC_NAME_PATTERN = Pattern.compile("^[a-zA-Z0-9]([._-](?![._-])|" - + "[a-zA-Z0-9]){0,120}[a-zA-Z0-9]$"); /** * Validate characters in names within cps. + * * @param names names of data to be validated */ public static void validateNameCharacters(final String... names) { for (final String name : names) { - final Collection<Character> charactersOfName = Lists.charactersOf(name); + final Collection<Character> charactersOfName = Lists.charactersOf(name); for (final char unsupportedCharacter : UNSUPPORTED_NAME_CHARACTERS) { if (charactersOfName.contains(unsupportedCharacter)) { throw new DataValidationException("Name or ID Validation Error.", - name + " invalid token encountered at position " + (name.indexOf(unsupportedCharacter) + 1)); + name + " invalid token encountered at position " + + (name.indexOf(unsupportedCharacter) + 1)); } } } } - /** - * Validate kafka topic name pattern. - * @param topicName name of the topic to be validated - */ - public static boolean validateTopicName(final String topicName) { - return topicName != null && TOPIC_NAME_PATTERN.matcher(topicName).matches(); - } + + } diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/CpsValidatorSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/CpsValidatorSpec.groovy index ce728ef1c1..ea7a5d6d1d 100644 --- a/cps-service/src/test/groovy/org/onap/cps/utils/CpsValidatorSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/utils/CpsValidatorSpec.groovy @@ -25,7 +25,6 @@ import spock.lang.Specification class CpsValidatorSpec extends Specification { - def 'Validating a valid string.'() { when: 'the string is validated using a valid name' CpsValidator.validateNameCharacters('name-with-no-spaces') @@ -46,17 +45,4 @@ class CpsValidatorSpec extends Specification { 'position 9' | 'nameWith Space' || 'nameWith Space invalid token encountered at position 9' } - def 'Validating topic names.'() { - when: 'the topic name is validated' - def isValidTopicName = CpsValidator.validateTopicName(topicName) - then: 'boolean response will be returned for #scenario' - assert isValidTopicName == booleanResponse - where: 'the following names are used' - scenario | topicName || booleanResponse - 'valid topic' | 'my-topic-name' || true - 'empty topic' | '' || false - 'blank topic' | ' ' || false - 'null topic' | null || false - 'invalid non empty topic' | '1_5_*_#' || false - } } |