diff options
Diffstat (limited to 'cps-ri/src/test')
2 files changed, 59 insertions, 14 deletions
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy index dace82ae5f..f5d5fc6456 100644 --- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy +++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy @@ -30,6 +30,7 @@ import org.onap.cps.spi.exceptions.DataspaceNotFoundException import org.onap.cps.spi.exceptions.AlreadyDefinedException import org.onap.cps.spi.exceptions.SchemaSetInUseException import org.onap.cps.spi.exceptions.SchemaSetNotFoundException +import org.onap.cps.spi.model.ModuleReference import org.onap.cps.spi.repository.AnchorRepository import org.onap.cps.spi.repository.SchemaSetRepository import org.springframework.beans.factory.annotation.Autowired @@ -57,10 +58,27 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase static final Long NEW_RESOURCE_ABSTRACT_ID = 0L static final String NEW_RESOURCE_NAME = 'some new resource' - static final String NEW_RESOURCE_CONTENT = 'some resource content' - static final String NEW_RESOURCE_CHECKSUM = '09002da02ee2683898d2c81c67f9e22cdbf8577d8c2de16c84d724e4ae44a0a6' + static final String NEW_RESOURCE_CONTENT = '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' + + ' }' + + '}' + static final String NEW_RESOURCE_CHECKSUM = 'b13faef573ed1374139d02c40d8ce09c80ea1dc70e63e464c1ed61568d48d539' + static final String NEW_RESOURCE_MODULE_NAME = 'stores' + static final String NEW_RESOURCE_REVISION = '2020-09-15' + static final ModuleReference newModuleReference = ModuleReference.builder().name(NEW_RESOURCE_MODULE_NAME) + .revision(NEW_RESOURCE_REVISION).build() def newYangResourcesNameToContentMap = [(NEW_RESOURCE_NAME):NEW_RESOURCE_CONTENT] + def allYangResourcesModuleAndRevisionList = [ModuleReference.builder().build(),ModuleReference.builder().build(), + ModuleReference.builder().build(),ModuleReference.builder().build(), + ModuleReference.builder().build(), newModuleReference] def dataspaceEntity def setup() { @@ -85,7 +103,7 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase objectUnderTest.storeSchemaSet(DATASPACE_NAME, SCHEMA_SET_NAME_NEW, newYangResourcesNameToContentMap) then: 'the schema set is persisted correctly' assertSchemaSetPersisted(DATASPACE_NAME, SCHEMA_SET_NAME_NEW, NEW_RESOURCE_ABSTRACT_ID, NEW_RESOURCE_NAME, - NEW_RESOURCE_CONTENT, NEW_RESOURCE_CHECKSUM) + NEW_RESOURCE_CONTENT, NEW_RESOURCE_CHECKSUM, NEW_RESOURCE_MODULE_NAME, NEW_RESOURCE_REVISION) } @Sql([CLEAR_DATA, SET_DATA]) @@ -101,18 +119,31 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase } @Sql([CLEAR_DATA, SET_DATA]) + def 'Retrieving all yang resources module references.'() { + given: 'a new schema set is stored' + objectUnderTest.storeSchemaSet(DATASPACE_NAME, SCHEMA_SET_NAME_NEW, newYangResourcesNameToContentMap) + when: 'all yang resources module references are retrieved' + def result = objectUnderTest.getAllYangResourcesModuleReferences() + then: 'the correct resources are returned' + result.sort() == allYangResourcesModuleAndRevisionList.sort() + } + + @Sql([CLEAR_DATA, SET_DATA]) def 'Storing duplicate schema content.'() { given: 'a new schema set with a resource with the same content as an existing resource' - def existingResourceContent = 'CONTENT-001' + def existingResourceContent = 'module test { yang-version 1.1; revision "2020-09-15"; }' def newYangResourcesNameToContentMap = [(NEW_RESOURCE_NAME):existingResourceContent] when: 'the schema set with duplicate resource is stored' objectUnderTest.storeSchemaSet(DATASPACE_NAME, SCHEMA_SET_NAME_NEW, newYangResourcesNameToContentMap) then: 'the schema persisted (re)uses the existing id, name and has the same checksum' - def existingResourceId = 3001L + def existingResourceId = 9L def existingResourceName = 'module1@2020-02-02.yang' - def existingResourceChecksum = 'e8bdda931099310de66532e08c3fafec391db29f55c81927b168f6aa8f81b73b' + def existingResourceChecksum = 'bea1afcc3d1517e7bf8cae151b3b6bfbd46db77a81754acdcb776a50368efa0a' + def existingResourceModelName = 'test' + def existingResourceRevision = '2020-09-15' assertSchemaSetPersisted(DATASPACE_NAME, SCHEMA_SET_NAME_NEW, - existingResourceId, existingResourceName, existingResourceContent, existingResourceChecksum) + existingResourceId, existingResourceName, existingResourceContent, existingResourceChecksum, + existingResourceModelName, existingResourceRevision) } @Sql([CLEAR_DATA, SET_DATA]) @@ -163,11 +194,13 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase } def assertSchemaSetPersisted(expectedDataspaceName, - expectedSchemaSetName, - expectedYangResourceId, - expectedYangResourceName, - expectedYangResourceContent, - expectedYangResourceChecksum) { + expectedSchemaSetName, + expectedYangResourceId, + expectedYangResourceName, + expectedYangResourceContent, + expectedYangResourceChecksum, + expectedYangResourceModuleName, + expectedYangResourceRevision) { // assert the schema set is persisted def schemaSetEntity = schemaSetRepository .findByDataspaceAndName(dataspaceEntity, expectedSchemaSetName).orElseThrow() @@ -188,6 +221,8 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase yangResourceEntity.name == expectedYangResourceName yangResourceEntity.content == expectedYangResourceContent yangResourceEntity.checksum == expectedYangResourceChecksum + yangResourceEntity.moduleName == expectedYangResourceModuleName + yangResourceEntity.revision == expectedYangResourceRevision } } 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 4455a6fa41..8bd7f86ea2 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 @@ -45,11 +45,21 @@ class CpsModulePersistenceServiceSpec extends Specification { // 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' + yangResourceChecksum = 'b13faef573ed1374139d02c40d8ce09c80ea1dc70e63e464c1ed61568d48d539' @Shared yangResourceChecksumDbConstraint = 'yang_resource_checksum_key' @Shared |