diff options
Diffstat (limited to 'cps-ri/src/test')
-rw-r--r-- | cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceSpec.groovy | 32 |
1 files changed, 21 insertions, 11 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/CpsModulePersistenceServiceSpec.groovy index 9696b28cd7..3447a1c599 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/CpsModulePersistenceServiceSpec.groovy @@ -20,16 +20,16 @@ package org.onap.cps.spi.impl import org.hibernate.exception.ConstraintViolationException -import org.onap.cps.spi.CpsAdminPersistenceService import org.onap.cps.spi.CpsModulePersistenceService +import org.onap.cps.spi.entities.SchemaSetEntity import org.onap.cps.spi.exceptions.DuplicatedYangResourceException +import org.onap.cps.spi.model.ModuleReference import org.onap.cps.spi.repository.DataspaceRepository import org.onap.cps.spi.repository.ModuleReferenceRepository import org.onap.cps.spi.repository.SchemaSetRepository import org.onap.cps.spi.repository.YangResourceRepository import org.springframework.dao.DataIntegrityViolationException import spock.lang.Specification - import java.sql.SQLException /** @@ -39,11 +39,10 @@ class CpsModulePersistenceServiceSpec extends Specification { CpsModulePersistenceService objectUnderTest - def dataspaceRepositoryMock = Mock(DataspaceRepository) - def yangResourceRepositoryMock = Mock(YangResourceRepository) - def schemaSetRepositoryMock = Mock(SchemaSetRepository) - def cpsAdminPersistenceServiceMock = Mock(CpsAdminPersistenceService) - def moduleReferenceRepositoryMock = Mock(ModuleReferenceRepository) + def mockDataspaceRepository = Mock(DataspaceRepository) + def mockYangResourceRepository = Mock(YangResourceRepository) + def mockSchemaSetRepository = Mock(SchemaSetRepository) + def mockModuleReferenceRepository = Mock(ModuleReferenceRepository) def yangResourceName = 'my-yang-resource-name' def yangResourceContent = 'module stores {\n' + @@ -68,15 +67,15 @@ class CpsModulePersistenceServiceSpec extends Specification { static otherIntegrityException = new DataIntegrityViolationException('another integrity exception') def setup() { - objectUnderTest = new CpsModulePersistenceServiceImpl(yangResourceRepositoryMock, schemaSetRepositoryMock, - dataspaceRepositoryMock, moduleReferenceRepositoryMock) + objectUnderTest = new CpsModulePersistenceServiceImpl(mockYangResourceRepository, mockSchemaSetRepository, + mockDataspaceRepository, mockModuleReferenceRepository) } def 'Store schema set error scenario: #scenario.'() { given: 'no yang resource are currently saved' - yangResourceRepositoryMock.findAllByChecksumIn(_ as Collection<String>) >> Collections.emptyList() + mockYangResourceRepository.findAllByChecksumIn(_ as Collection<String>) >> Collections.emptyList() and: 'persisting yang resource raises db constraint exception (in case of concurrent requests for example)' - yangResourceRepositoryMock.saveAll(_) >> { throw dbException } + mockYangResourceRepository.saveAll(_) >> { throw dbException } when: 'attempt to store schema set ' def newYangResourcesNameToContentMap = [(yangResourceName):yangResourceContent] objectUnderTest.storeSchemaSet('my-dataspace', 'my-schema-set', newYangResourcesNameToContentMap) @@ -90,4 +89,15 @@ class CpsModulePersistenceServiceSpec extends Specification { 'other data failure' | otherIntegrityException || DataIntegrityViolationException | 'another integrity exception' } + def 'Upgrade existing schema set'() { + given: 'old schema has empty yang resource' + mockYangResourceRepository.findAllByChecksumIn(_ as Collection<String>) >> Collections.emptyList() + def schemaSetEntity = new SchemaSetEntity(id: 1) + mockSchemaSetRepository.getByDataspaceAndName(_, _) >> schemaSetEntity + when: 'schema set update is requested' + objectUnderTest.updateSchemaSetFromModules('my-dataspace', 'my-schemaset', [:], [new ModuleReference('some module name', 'some revision name')]) + then: 'no exception is thrown ' + noExceptionThrown() + } + } |