diff options
author | sourabh_sourabh <sourabh.sourabh@est.tech> | 2023-12-05 11:02:17 +0000 |
---|---|---|
committer | sourabh_sourabh <sourabh.sourabh@est.tech> | 2023-12-13 12:53:38 +0000 |
commit | 541ed451d1257f6eb72517f33f470db53fdd7fb4 (patch) | |
tree | 28ebef126cedbda25ce315cefb0798e8b8cd2401 /cps-ri/src/test | |
parent | 7e94b26a666907cc97d692b8dda8364bb0a0ef45 (diff) |
Introduce Schema Set upgrade method
- Incl. integration test
- Prod code is changed to use new method that update yand module.
- updated module resource to return multiple modules.
Issue-ID: CPS-1806
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Change-Id: I751d9393ce78a3be9daeaff6d0252738c02115e0
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
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() + } + } |