diff options
author | Renu Kumari <renu.kumari@bell.ca> | 2022-01-20 13:30:05 -0500 |
---|---|---|
committer | Renu Kumari <renu.kumari@bell.ca> | 2022-02-02 10:31:06 -0500 |
commit | c9af4eac4dc7f86bd3f33d923f9efe4a8523ed57 (patch) | |
tree | d10cfe4f1d5b2dcf8d0bf43ea04678262c4a287e /cps-service/src/test | |
parent | cdc85a32069485641b0c8c37f8d7c4e6727e336a (diff) |
Refactor Delete Anchor functionality
- Added a delete DataNode functionality in the CpsDataService
- CpsAdminService uses CpsDataService to delete DataNodes
Issue-ID: CPS-791
Signed-off-by: Renu Kumari <renu.kumari@bell.ca>
Change-Id: I090500dbc4a2ccf061dc105f979472137d43b06d
Diffstat (limited to 'cps-service/src/test')
3 files changed, 20 insertions, 22 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 fe6e460862..bb122d1ae2 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 @@ -22,17 +22,16 @@ package org.onap.cps.api.impl +import org.onap.cps.api.CpsDataService import org.onap.cps.spi.CpsAdminPersistenceService import org.onap.cps.spi.model.Anchor import spock.lang.Specification +import java.time.OffsetDateTime class CpsAdminServiceImplSpec extends Specification { def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService) - def objectUnderTest = new CpsAdminServiceImpl() - - def setup() { - objectUnderTest.cpsAdminPersistenceService = mockCpsAdminPersistenceService - } + def mockCpsDataService = Mock(CpsDataService) + def objectUnderTest = new CpsAdminServiceImpl(mockCpsAdminPersistenceService, mockCpsDataService) def 'Create dataspace method invokes persistence service.'() { when: 'create dataspace method is invoked' @@ -75,7 +74,9 @@ class CpsAdminServiceImplSpec extends Specification { def 'Delete anchor.'() { when: 'delete anchor is invoked' objectUnderTest.deleteAnchor('someDataspace','someAnchor') - then: 'associated persistence service method is invoked with same parameters' + then: 'delete data nodes is invoked on the data service with expected parameters' + 1 * mockCpsDataService.deleteDataNodes('someDataspace','someAnchor', _ as OffsetDateTime ) + and: 'the persistence service method is invoked with same parameters to delete anchor' 1 * mockCpsAdminPersistenceService.deleteAnchor('someDataspace','someAnchor') } diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy index a302eb5e75..56b0e2d53b 100644 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy @@ -44,14 +44,8 @@ class CpsDataServiceImplSpec extends Specification { def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache) def mockNotificationService = Mock(NotificationService) - def objectUnderTest = new CpsDataServiceImpl() - - def setup() { - objectUnderTest.cpsDataPersistenceService = mockCpsDataPersistenceService - objectUnderTest.cpsAdminService = mockCpsAdminService - objectUnderTest.yangTextSchemaSourceSetCache = mockYangTextSchemaSourceSetCache - objectUnderTest.notificationService = mockNotificationService - } + def objectUnderTest = new CpsDataServiceImpl(mockCpsDataPersistenceService, mockCpsAdminService, + mockYangTextSchemaSourceSetCache, mockNotificationService) def dataspaceName = 'some dataspace' def anchorName = 'some anchor' @@ -237,6 +231,15 @@ class CpsDataServiceImplSpec extends Specification { 1 * mockNotificationService.processDataUpdatedEvent(dataspaceName, anchorName, observedTimestamp, '/data-node', Operation.DELETE) } + def 'Delete all data nodes for a given anchor and dataspace.'() { + given: 'schema set for given anchor and dataspace references test tree model' + setupSchemaSetMocks('test-tree.yang') + when: 'delete data node method is invoked with correct parameters' + objectUnderTest.deleteDataNodes(dataspaceName, anchorName, observedTimestamp) + then: 'the persistence service method is invoked with the correct parameters' + 1 * mockCpsDataPersistenceService.deleteDataNodes(dataspaceName, anchorName) + } + def setupSchemaSetMocks(String... yangResources) { def anchor = Anchor.builder().name(anchorName).schemaSetName(schemaSetName).build() mockCpsAdminService.getAnchor(dataspaceName, anchorName) >> anchor 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 d18bcf55ef..52389522f8 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 @@ -37,23 +37,17 @@ class E2ENetworkSliceSpec extends Specification { def mockDataStoreService = Mock(CpsDataPersistenceService)
def mockCpsAdminService = Mock(CpsAdminService)
def mockNotificationService = Mock(NotificationService)
- def cpsDataServiceImpl = new CpsDataServiceImpl()
def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache)
def cpsModuleServiceImpl = new CpsModuleServiceImpl(mockModuleStoreService,
mockYangTextSchemaSourceSetCache,mockCpsAdminService )
+ def cpsDataServiceImpl = new CpsDataServiceImpl(mockDataStoreService, mockCpsAdminService,
+ mockYangTextSchemaSourceSetCache, mockNotificationService)
def dataspaceName = 'someDataspace'
def anchorName = 'someAnchor'
def schemaSetName = 'someSchemaSet'
def noTimestamp = null
- def setup() {
- cpsDataServiceImpl.cpsDataPersistenceService = mockDataStoreService
- cpsDataServiceImpl.cpsAdminService = mockCpsAdminService
- cpsDataServiceImpl.yangTextSchemaSourceSetCache = mockYangTextSchemaSourceSetCache
- cpsDataServiceImpl.notificationService = mockNotificationService
- }
-
def 'E2E model can be parsed by CPS.'() {
given: 'Valid yang resource as name-to-content map'
def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap(
|