aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ri/src/test')
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/ri/CpsModulePersistenceServiceImplSpec.groovy32
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/ri/utils/CpsValidatorImplSpec.groovy78
2 files changed, 30 insertions, 80 deletions
diff --git a/cps-ri/src/test/groovy/org/onap/cps/ri/CpsModulePersistenceServiceImplSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/ri/CpsModulePersistenceServiceImplSpec.groovy
index 9abfdbeb33..4bf8c7ca09 100644
--- a/cps-ri/src/test/groovy/org/onap/cps/ri/CpsModulePersistenceServiceImplSpec.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/ri/CpsModulePersistenceServiceImplSpec.groovy
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (c) 2021 Bell Canada.
- * Modifications Copyright (C) 2022-2023 Nordix Foundation
+ * Modifications Copyright (C) 2022-2025 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
package org.onap.cps.ri
import org.hibernate.exception.ConstraintViolationException
+import org.onap.cps.ri.models.DataspaceEntity
import org.onap.cps.ri.models.SchemaSetEntity
import org.onap.cps.ri.repository.DataspaceRepository
import org.onap.cps.ri.repository.ModuleReferenceRepository
@@ -30,7 +31,6 @@ import org.onap.cps.api.exceptions.DuplicatedYangResourceException
import org.onap.cps.api.model.ModuleReference
import org.springframework.dao.DataIntegrityViolationException
import spock.lang.Specification
-
import java.sql.SQLException
/**
@@ -101,4 +101,32 @@ class CpsModulePersistenceServiceImplSpec extends Specification {
noExceptionThrown()
}
+ def 'Get yang schema resources.' () {
+ given: 'mocked methods for dataspace and schema set repositories'
+ mockDataspaceRepository.getByName('someDataspaceName') >> new DataspaceEntity()
+ mockSchemaSetRepository.getByDataspaceAndName(_,_) >> new SchemaSetEntity(yangResources: [])
+ when: 'the get yang schema resources method is called'
+ def result = objectUnderTest.getYangSchemaResources('someDataspaceName', 'someSchemaSetName')
+ then: 'an empty map is returned'
+ assert result.isEmpty()
+ }
+
+ def 'Get yang module references with just dataspace name.' () {
+ given: 'mocked method return yang resource repository'
+ mockYangResourceRepository.findAllModuleReferencesByDataspace('someDataspaceName') >> []
+ when: 'the get yang resource module reference method is called with 1 parameter'
+ def result = objectUnderTest.getYangResourceModuleReferences('someDataspaceName')
+ then: 'an empty collection is returned'
+ assert result.isEmpty()
+ }
+
+ def 'Get yang module references with dataspace name and anchor.' () {
+ given: 'mocked method return yang resource repository'
+ mockYangResourceRepository.findAllModuleReferencesByDataspaceAndAnchor('someDataspaceName', 'someAnchorName') >> []
+ when: 'the get yang resource module reference method is called with 2 parameters'
+ def result = objectUnderTest.getYangResourceModuleReferences('someDataspaceName','someAnchorName')
+ then: 'an empty collection is returned'
+ assert result.isEmpty()
+ }
+
}
diff --git a/cps-ri/src/test/groovy/org/onap/cps/ri/utils/CpsValidatorImplSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/ri/utils/CpsValidatorImplSpec.groovy
deleted file mode 100644
index f7c4798772..0000000000
--- a/cps-ri/src/test/groovy/org/onap/cps/ri/utils/CpsValidatorImplSpec.groovy
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.cps.ri.utils
-
-
-import org.onap.cps.api.parameters.PaginationOption
-import org.onap.cps.api.exceptions.DataValidationException
-import spock.lang.Specification
-
-class CpsValidatorImplSpec extends Specification {
-
- def objectUnderTest = new CpsValidatorImpl()
-
- def 'Validating a valid string.'() {
- when: 'the string is validated using a valid name'
- objectUnderTest.validateNameCharacters('name-with-no-spaces')
- then: 'no exception is thrown'
- noExceptionThrown()
- }
-
- def 'Validating an invalid string.'() {
- when: 'the string is validated using an invalid name'
- objectUnderTest.validateNameCharacters(name)
- then: 'a data validation exception is thrown'
- def exceptionThrown = thrown(DataValidationException)
- and: 'the error was encountered at the following index in #scenario'
- assert exceptionThrown.getDetails().contains(expectedErrorMessage)
- where: 'the following names are used'
- scenario | name || expectedErrorMessage
- 'position 5' | 'name with spaces' || 'name with spaces invalid token encountered at position 5'
- 'position 9' | 'nameWith Space' || 'nameWith Space invalid token encountered at position 9'
- }
-
- def 'Validating a list of valid names.'() {
- given: 'a list of valid names'
- def names = ['valid-name', 'another-valid-name']
- when: 'a list of strings is validated'
- objectUnderTest.validateNameCharacters(names)
- then: 'no exception is thrown'
- noExceptionThrown()
- }
-
- def 'Validating a list of names with invalid names.'() {
- given: 'a list of names with an invalid name'
- def names = ['valid-name', 'name with spaces']
- when: 'a list of strings is validated'
- objectUnderTest.validateNameCharacters(names)
- then: 'a data validation exception is thrown'
- thrown(DataValidationException)
- }
-
- def 'Validate Pagination option with invalid page index and size.'() {
- when: 'the pagination option is validated using invalid options'
- objectUnderTest.validatePaginationOption(new PaginationOption(-5, -2))
- then: 'a data validation exception is thrown'
- def exceptionThrown = thrown(DataValidationException)
- and: 'the error was encountered at the following index in #scenario'
- assert exceptionThrown.getDetails().contains("Invalid page index or size")
- }
-}