2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.utils
23 import org.onap.cps.spi.exceptions.DataValidationException
24 import spock.lang.Specification
26 class CpsValidatorSpec extends Specification {
29 def 'Validating a valid string.'() {
30 when: 'the string is validated using a valid name'
31 CpsValidator.validateNameCharacters('name-with-no-spaces')
32 then: 'no exception is thrown'
36 def 'Validating an invalid string.'() {
37 when: 'the string is validated using an invalid name'
38 CpsValidator.validateNameCharacters(name)
39 then: 'a data validation exception is thrown'
40 def exceptionThrown = thrown(DataValidationException)
41 and: 'the error was encountered at the following index in #scenario'
42 assert exceptionThrown.getDetails().contains(expectedErrorMessage)
43 where: 'the following names are used'
44 scenario | name || expectedErrorMessage
45 'position 5' | 'name with spaces' || 'name with spaces invalid token encountered at position 5'
46 'position 9' | 'nameWith Space' || 'nameWith Space invalid token encountered at position 9'
49 def 'Validating topic names.'() {
50 when: 'the topic name is validated'
51 def isValidTopicName = CpsValidator.validateTopicName(topicName)
52 then: 'boolean response will be returned for #scenario'
53 assert isValidTopicName == booleanResponse
54 where: 'the following names are used'
55 scenario | topicName || booleanResponse
56 'valid topic' | 'my-topic-name' || true
57 'empty topic' | '' || false
58 'blank topic' | ' ' || false
59 'null topic' | null || false
60 'invalid non empty topic' | '1_5_*_#' || false