diff options
author | Renu Kumari <renu.kumari@bell.ca> | 2022-01-20 12:07:38 -0500 |
---|---|---|
committer | Renu Kumari <renu.kumari@bell.ca> | 2022-01-28 20:07:41 +0000 |
commit | 5427ef054effb1aadfaaab300282545c99c37a61 (patch) | |
tree | cf4be05c318083cb98d4669857c50772a8f72e71 /cps-service/src/test/groovy/org/onap | |
parent | 63132cec2c18363a8224646039cc23b6144d8e6c (diff) |
Refactored Delete SchemaSet functionality
- Added get anchors by schemaset in cpsAdminService
- Changed DeleteSchemaSet functionality
- Use CPSAdminService to getAnchors associated with schemaset
- Use CPSAdminService to delete Anchors
- Moved Cascade allowed validation into Service from Persistence
Issue-ID: CPS-791
Signed-off-by: Renu Kumari <renu.kumari@bell.ca>
Change-Id: Ife7644551183cb8c3eb686a654b0a43a427ac1e5
Diffstat (limited to 'cps-service/src/test/groovy/org/onap')
3 files changed, 63 insertions, 19 deletions
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy index 6d1f586295..fe6e460862 100755 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Nordix Foundation - * Modifications Copyright (C) 2020 Bell Canada. + * Modifications Copyright (C) 2020-2022 Bell Canada. * Modifications Copyright (C) 2021 Pantheon.tech * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -56,6 +56,14 @@ class CpsAdminServiceImplSpec extends Specification { objectUnderTest.getAnchors('someDataspace') == anchors } + def 'Retrieve all anchors for schema-set.'() { + given: 'that anchor is associated with the dataspace and schemaset' + def anchors = [new Anchor()] + mockCpsAdminPersistenceService.getAnchors('someDataspace', 'someSchemaSet') >> anchors + expect: 'the collection provided by persistence service is returned as result' + objectUnderTest.getAnchors('someDataspace', 'someSchemaSet') == anchors + } + def 'Retrieve anchor for dataspace and provided anchor name.'() { given: 'that anchor name is associated with the dataspace' Anchor anchor = new Anchor() diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy index 2c23aa1bc8..b0205705a7 100644 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2020-2021 Nordix Foundation * Modifications Copyright (C) 2020-2021 Pantheon.tech - * Modifications Copyright (C) 2020-2021 Bell Canada. + * Modifications Copyright (C) 2020-2022 Bell Canada. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,11 @@ package org.onap.cps.api.impl import org.onap.cps.TestUtils +import org.onap.cps.api.CpsAdminService import org.onap.cps.spi.CpsModulePersistenceService import org.onap.cps.spi.exceptions.ModelValidationException +import org.onap.cps.spi.exceptions.SchemaSetInUseException +import org.onap.cps.spi.model.Anchor import org.onap.cps.spi.model.ExtendedModuleReference import org.onap.cps.spi.model.ModuleReference import org.spockframework.spring.SpringBean @@ -35,19 +38,21 @@ import org.springframework.cache.annotation.EnableCaching import org.springframework.cache.caffeine.CaffeineCacheManager import org.springframework.test.context.ContextConfiguration import spock.lang.Specification - import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED @SpringBootTest @EnableCaching -@ContextConfiguration(classes = [YangTextSchemaSourceSetCache.class, CpsModuleServiceImpl.class]) +@ContextConfiguration(classes = [YangTextSchemaSourceSetCache, CpsModuleServiceImpl]) class CpsModuleServiceImplSpec extends Specification { @SpringBean CpsModulePersistenceService mockModuleStoreService = Mock() @SpringBean + CpsAdminService mockCpsAdminService = Mock() + + @SpringBean CacheManager cacheManager = new CaffeineCacheManager("yangSchema") @Autowired @@ -105,18 +110,51 @@ class CpsModuleServiceImplSpec extends Specification { 1 * mockModuleStoreService.getYangSchemaResources('someDataspace', 'someSchemaSet') >> yangResourcesNameToContentMap } - def 'Delete set by name and dataspace with #cascadeDeleteOption.'() { - when: 'schema set deletion is requested' - objectUnderTest.deleteSchemaSet(dataspaceName, schemaSetname, cascadeDeleteOption) - then: 'persistence service method is invoked with same parameters' - mockModuleStoreService.deleteSchemaSet(dataspaceName, schemaSetname, cascadeDeleteOption) + def 'Delete schema-set when cascade is allowed.'() { + given: '#numberOfAnchors anchors are associated with schemaset' + def associatedAnchors = createAnchors(numberOfAnchors) + mockCpsAdminService.getAnchors('my-dataspace', 'my-schemaset') >> associatedAnchors + when: 'schema set deletion is requested with cascade allowed' + objectUnderTest.deleteSchemaSet('my-dataspace', 'my-schemaset', CASCADE_DELETE_ALLOWED) + then: 'anchor deletion is called #numberOfAnchors times' + numberOfAnchors * mockCpsAdminService.deleteAnchor('my-dataspace', _) + and: 'persistence service method is invoked with same parameters' + 1 * mockModuleStoreService.deleteSchemaSet('my-dataspace', 'my-schemaset') + and: 'orphan yang resources are deleted' + 1 * mockModuleStoreService.deleteUnusedYangResourceModules() where: 'following parameters are used' - dataspaceName | schemaSetname | cascadeDeleteOption - 'dataspace-1' | 'schemas-set-1' | CASCADE_DELETE_ALLOWED - 'dataspace-2' | 'schemas-set-2' | CASCADE_DELETE_PROHIBITED + numberOfAnchors << [0, 3] + } + + def 'Delete schema-set when cascade is prohibited.'() { + given: 'no anchors are associated with schemaset' + mockCpsAdminService.getAnchors('my-dataspace', 'my-schemaset') >> Collections.emptyList() + when: 'schema set deletion is requested with cascade allowed' + objectUnderTest.deleteSchemaSet('my-dataspace', 'my-schemaset', CASCADE_DELETE_PROHIBITED) + then: 'no anchors are deleted' + 0 * mockCpsAdminService.deleteAnchor(_, _) + and: 'persistence service method is invoked with same parameters' + 1 * mockModuleStoreService.deleteSchemaSet('my-dataspace', 'my-schemaset') + and: 'orphan yang resources are deleted' + 1 * mockModuleStoreService.deleteUnusedYangResourceModules() + } + + def 'Delete schema-set when cascade is prohibited and schema-set has anchors.'() { + given: '2 anchors are associated with schemaset' + mockCpsAdminService.getAnchors('my-dataspace', 'my-schemaset') >> createAnchors(2) + when: 'schema set deletion is requested with cascade allowed' + objectUnderTest.deleteSchemaSet('my-dataspace', 'my-schemaset', CASCADE_DELETE_PROHIBITED) + then: 'Schema-Set in Use exception is thrown' + thrown(SchemaSetInUseException) + } + + def createAnchors(int anchorCount) { + def anchors = [] + (0..<anchorCount).each { anchors.add(new Anchor("my-anchor-$it", 'my-dataspace', 'my-schemaset')) } + return anchors } - def 'Get all yang resources module references.'(){ + def 'Get all yang resources module references.'() { given: 'an already present module reference' def moduleReferences = [new ExtendedModuleReference()] mockModuleStoreService.getYangResourceModuleReferences('someDataspaceName') >> moduleReferences @@ -125,7 +163,7 @@ class CpsModuleServiceImplSpec extends Specification { } - def 'Get all yang resources module references for the given dataspace name and anchor name.'(){ + def 'Get all yang resources module references for the given dataspace name and anchor name.'() { given: 'the module store service service returns a list module references' def moduleReferences = [new ModuleReference()] mockModuleStoreService.getYangResourceModuleReferences('someDataspaceName', 'someAnchorName') >> moduleReferences diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy index eefa86e903..d18bcf55ef 100755 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy @@ -1,7 +1,7 @@ /*
* ============LICENSE_START=======================================================
* Copyright (C) 2021 Nordix Foundation.
- * Modifications Copyright (C) 2021 Bell Canada.
+ * Modifications Copyright (C) 2021-2022 Bell Canada.
* Modifications Copyright (C) 2021 Pantheon.tech
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,6 @@ package org.onap.cps.api.impl
-import java.time.OffsetDateTime
import org.onap.cps.TestUtils
import org.onap.cps.api.CpsAdminService
import org.onap.cps.notification.NotificationService
@@ -38,9 +37,10 @@ class E2ENetworkSliceSpec extends Specification { def mockDataStoreService = Mock(CpsDataPersistenceService)
def mockCpsAdminService = Mock(CpsAdminService)
def mockNotificationService = Mock(NotificationService)
- def cpsModuleServiceImpl = new CpsModuleServiceImpl()
def cpsDataServiceImpl = new CpsDataServiceImpl()
def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache)
+ def cpsModuleServiceImpl = new CpsModuleServiceImpl(mockModuleStoreService,
+ mockYangTextSchemaSourceSetCache,mockCpsAdminService )
def dataspaceName = 'someDataspace'
def anchorName = 'someAnchor'
@@ -52,8 +52,6 @@ class E2ENetworkSliceSpec extends Specification { cpsDataServiceImpl.cpsAdminService = mockCpsAdminService
cpsDataServiceImpl.yangTextSchemaSourceSetCache = mockYangTextSchemaSourceSetCache
cpsDataServiceImpl.notificationService = mockNotificationService
- cpsModuleServiceImpl.yangTextSchemaSourceSetCache = mockYangTextSchemaSourceSetCache
- cpsModuleServiceImpl.cpsModulePersistenceService = mockModuleStoreService
}
def 'E2E model can be parsed by CPS.'() {
|