X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-ri%2Fsrc%2Ftest%2Fgroovy%2Forg%2Fonap%2Fcps%2Fspi%2Fimpl%2FCpsModulePersistenceServiceSpec.groovy;h=5e42ce04e7486333533944952329047357bf8f51;hb=240ac3d9cd8107250574dd0f7221ae2f1afa3bd7;hp=4455a6fa412f8b99eb6c9464a29be85b66c33e6d;hpb=0e210d77ec39915046a95615f5f9d2a2dc65162b;p=cps.git 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 4455a6fa4..5e42ce04e 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 @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (c) 2021 Bell Canada. + * Modifications Copyright (C) 2022 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +20,11 @@ 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.exceptions.DuplicatedYangResourceException 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 @@ -42,36 +45,43 @@ class CpsModulePersistenceServiceSpec extends Specification { def dataspaceRepositoryMock = Mock(DataspaceRepository) def yangResourceRepositoryMock = Mock(YangResourceRepository) def schemaSetRepositoryMock = Mock(SchemaSetRepository) + def cpsAdminPersistenceServiceMock = Mock(CpsAdminPersistenceService) + def moduleReferenceRepositoryMock = Mock(ModuleReferenceRepository) // Constants def yangResourceName = 'my-yang-resource-name' - def yangResourceContent = 'my-yang-resource-content' + def yangResourceContent = 'module stores {\n' + + ' yang-version 1.1;\n' + + ' namespace "org:onap:ccsdk:sample";\n' + + '\n' + + ' prefix book-store;\n' + + '\n' + + ' revision "2020-09-15" {\n' + + ' description\n' + + ' "Sample Model";\n' + + ' }' + + '}' // Scenario data - @Shared - yangResourceChecksum = 'ac2352cc20c10467528b2390bbf2d72d48b0319152ebaabcda207786b4a641c2' - @Shared - yangResourceChecksumDbConstraint = 'yang_resource_checksum_key' - @Shared - sqlExceptionMessage = String.format('(checksum)=(%s)', yangResourceChecksum) - @Shared - checksumIntegrityException = - new DataIntegrityViolationException( + static yangResourceChecksum = 'b13faef573ed1374139d02c40d8ce09c80ea1dc70e63e464c1ed61568d48d539' + static yangResourceChecksumDbConstraint = 'yang_resource_checksum_key' + static sqlExceptionMessage = String.format('(checksum)=(%s)', yangResourceChecksum) + static checksumIntegrityException = new DataIntegrityViolationException( "checksum integrity exception", new ConstraintViolationException('', new SQLException(sqlExceptionMessage), yangResourceChecksumDbConstraint)) - @Shared - anotherIntegrityException = new DataIntegrityViolationException("another integrity exception") + static checksumIntegrityExceptionWithoutChecksum = new DataIntegrityViolationException( + "checksum integrity exception", + new ConstraintViolationException('', new SQLException('no checksum'), yangResourceChecksumDbConstraint)) + static anotherIntegrityException = new DataIntegrityViolationException("another integrity exception") def setup() { - objectUnderTest = new CpsModulePersistenceServiceImpl() - objectUnderTest.dataspaceRepository = dataspaceRepositoryMock - objectUnderTest.yangResourceRepository = yangResourceRepositoryMock - objectUnderTest.schemaSetRepository = schemaSetRepositoryMock + objectUnderTest = new CpsModulePersistenceServiceImpl(yangResourceRepositoryMock, schemaSetRepositoryMock, + dataspaceRepositoryMock, cpsAdminPersistenceServiceMock, moduleReferenceRepositoryMock) } def 'Store schema set error scenario: #scenario.'() { given: 'no yang resource are currently saved' - yangResourceRepositoryMock.findAllByChecksumIn(_) >> Collections.emptyList() + yangResourceRepositoryMock.findAllByChecksumIn(_ as Collection) >> 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 ' @@ -79,11 +89,12 @@ class CpsModulePersistenceServiceSpec extends Specification { objectUnderTest.storeSchemaSet('my-dataspace', 'my-schema-set', newYangResourcesNameToContentMap) then: 'an #expectedThrownException is thrown' def e = thrown(expectedThrownException) - e.getMessage().contains(expectedThrownExceptionMessage) + assert 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' + scenario | dbException || expectedThrownException | expectedThrownExceptionMessage + 'checksum data failure' | checksumIntegrityException || DuplicatedYangResourceException | yangResourceChecksum + 'checksum failure without checksum' | checksumIntegrityExceptionWithoutChecksum || DuplicatedYangResourceException | 'no checksum found' + 'other data failure' | anotherIntegrityException || DataIntegrityViolationException | 'another integrity exception' } }