2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022-2023 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.spi.impl.utils
23 import org.onap.cps.spi.exceptions.DataValidationException
24 import spock.lang.Specification
26 class CpsValidatorSpec extends Specification {
28 def objectUnderTest = new CpsValidatorImpl()
30 def 'Validating a valid string.'() {
31 when: 'the string is validated using a valid name'
32 objectUnderTest.validateNameCharacters('name-with-no-spaces')
33 then: 'no exception is thrown'
37 def 'Validating an invalid string.'() {
38 when: 'the string is validated using an invalid name'
39 objectUnderTest.validateNameCharacters(name)
40 then: 'a data validation exception is thrown'
41 def exceptionThrown = thrown(DataValidationException)
42 and: 'the error was encountered at the following index in #scenario'
43 assert exceptionThrown.getDetails().contains(expectedErrorMessage)
44 where: 'the following names are used'
45 scenario | name || expectedErrorMessage
46 'position 5' | 'name with spaces' || 'name with spaces invalid token encountered at position 5'
47 'position 9' | 'nameWith Space' || 'nameWith Space invalid token encountered at position 9'
50 def 'Validating a list of valid names.'() {
51 given: 'a list of valid names'
52 def names = ['valid-name', 'another-valid-name']
53 when: 'a list of strings is validated'
54 objectUnderTest.validateNameCharacters(names)
55 then: 'no exception is thrown'
59 def 'Validating a list of names with invalid names.'() {
60 given: 'a list of names with an invalid name'
61 def names = ['valid-name', 'name with spaces']
62 when: 'a list of strings is validated'
63 objectUnderTest.validateNameCharacters(names)
64 then: 'a data validation exception is thrown'
65 thrown(DataValidationException)