diff options
author | Niamh Core <niamh.core@est.tech> | 2021-07-12 15:18:57 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-07-12 15:18:57 +0000 |
commit | b69ec9851b4af28ed4f8f21b01962561bfa1ec8b (patch) | |
tree | 917edc848f7e080d3be92f11b906e547f1659aa2 /cps-ri/src/test/groovy | |
parent | 7b5674c679796d5a568eeaeb63776c87468f3c9d (diff) | |
parent | 9be188dd7a5d0507a94e2ce321d3f3390d195a4e (diff) |
Merge "Support concurrent requests to create schema sets"
Diffstat (limited to 'cps-ri/src/test/groovy')
-rw-r--r-- | cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy (renamed from cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceSpec.groovy) | 3 | ||||
-rw-r--r-- | cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceUnitSpec.groovy | 89 |
2 files changed, 91 insertions, 1 deletions
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy index f08aa03579..b4a4c7e17d 100644 --- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceSpec.groovy +++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2021 Nordix Foundation + * Modifications Copyright (C) 2021 Bell Canada. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the 'License'); * you may not use this file except in compliance with the License. @@ -33,7 +34,7 @@ import org.onap.cps.spi.repository.SchemaSetRepository import org.springframework.beans.factory.annotation.Autowired import org.springframework.test.context.jdbc.Sql -class CpsModulePersistenceServiceSpec extends CpsPersistenceSpecBase { +class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { @Autowired CpsModulePersistenceService objectUnderTest diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceUnitSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceUnitSpec.groovy new file mode 100644 index 0000000000..ffbac485ea --- /dev/null +++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceUnitSpec.groovy @@ -0,0 +1,89 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (c) 2021 Bell Canada. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= +*/ + +package org.onap.cps.spi.impl + +import org.hibernate.exception.ConstraintViolationException +import org.onap.cps.spi.CpsModulePersistenceService +import org.onap.cps.spi.exceptions.DuplicatedYangResourceException +import org.onap.cps.spi.repository.DataspaceRepository +import org.onap.cps.spi.repository.SchemaSetRepository +import org.onap.cps.spi.repository.YangResourceRepository +import org.springframework.dao.DataIntegrityViolationException +import spock.lang.Shared +import spock.lang.Specification + +import java.sql.SQLException + +/** + * Specification unit test class for CPS module persistence service. + */ +class CpsModulePersistenceServiceUnitSpec extends Specification { + + // Instance to test + CpsModulePersistenceService objectUnderTest + + // Mocks + def dataspaceRepositoryMock = Mock(DataspaceRepository) + def yangResourceRepositoryMock = Mock(YangResourceRepository) + def schemaSetRepositoryMock = Mock(SchemaSetRepository) + + // Constants + def yangResourceName = 'my-yang-resource-name' + def yangResourceContent = 'my-yang-resource-content' + + // Scenario data + @Shared + yangResourceChecksum = 'ac2352cc20c10467528b2390bbf2d72d48b0319152ebaabcda207786b4a641c2' + @Shared + yangResourceChecksumDbConstraint = 'yang_resource_checksum_key' + @Shared + sqlExceptionMessage = String.format('(checksum)=(%s)', yangResourceChecksum) + @Shared + checksumIntegrityException = + new DataIntegrityViolationException( + "checksum integrity exception", + new ConstraintViolationException('', new SQLException(sqlExceptionMessage), yangResourceChecksumDbConstraint)) + @Shared + anotherIntegrityException = new DataIntegrityViolationException("another integrity exception") + + def setup() { + objectUnderTest = new CpsModulePersistenceServiceImpl() + objectUnderTest.dataspaceRepository = dataspaceRepositoryMock + objectUnderTest.yangResourceRepository = yangResourceRepositoryMock + objectUnderTest.schemaSetRepository = schemaSetRepositoryMock + } + + def 'Store schema set error scenario: #scenario.'() { + given: 'no yang resource are currently saved' + yangResourceRepositoryMock.findAllByChecksumIn(_) >> Collections.emptyList() + and: 'persisting yang resource raises db constraint exception (in case of concurrent requests for example)' + yangResourceRepositoryMock.saveAll(_) >> { throw dbException } + when: 'attempt to store schema set ' + def newYangResourcesNameToContentMap = [(yangResourceName):yangResourceContent] + objectUnderTest.storeSchemaSet('my-dataspace', 'my-schema-set', newYangResourcesNameToContentMap) + then: 'an #expectedThrownException is thrown' + def e = thrown(expectedThrownException) + e.getMessage().contains(expectedThrownExceptionMessage) + where: 'the following data is used' + scenario | dbException || expectedThrownException | expectedThrownExceptionMessage + 'checksum data failure' | checksumIntegrityException || DuplicatedYangResourceException | yangResourceChecksum + 'other data failure' | anotherIntegrityException || DataIntegrityViolationException | 'another integrity exception' + } + +} |