summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/test/groovy/org/onap
diff options
context:
space:
mode:
authorRenu Kumari <renu.kumari@bell.ca>2022-02-07 13:44:29 +0000
committerGerrit Code Review <gerrit@onap.org>2022-02-07 13:44:29 +0000
commite1537e7c389950dd8ad845e46a9e7b647f427eba (patch)
tree91bbaabf716db8b691303b2500e36aa569a5156e /cps-ri/src/test/groovy/org/onap
parentc70300200de2ccc2a8db8a5a905c46c73c50de75 (diff)
parentc9af4eac4dc7f86bd3f33d923f9efe4a8523ed57 (diff)
Merge "Refactor Delete Anchor functionality"
Diffstat (limited to 'cps-ri/src/test/groovy/org/onap')
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsAdminPersistenceServiceSpec.groovy8
-rwxr-xr-xcps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy19
2 files changed, 20 insertions, 7 deletions
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsAdminPersistenceServiceSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsAdminPersistenceServiceSpec.groovy
index 2218014ec1..063bd5b5ae 100644
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsAdminPersistenceServiceSpec.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsAdminPersistenceServiceSpec.groovy
@@ -41,8 +41,7 @@ class CpsAdminPersistenceServiceSpec extends CpsPersistenceSpecBase {
static final String SET_DATA = '/data/anchor.sql'
static final String SAMPLE_DATA_FOR_ANCHORS_WITH_MODULES = '/data/anchors-schemaset-modules.sql'
static final String DATASPACE_WITH_NO_DATA = 'DATASPACE-002-NO-DATA'
- static final Integer DELETED_ANCHOR_ID = 3001
- static final Long DELETED_FRAGMENT_ID = 4001
+ static final Integer DELETED_ANCHOR_ID = 3002
@Sql(CLEAR_DATA)
def 'Create and retrieve a new dataspace.'() {
@@ -150,10 +149,9 @@ class CpsAdminPersistenceServiceSpec extends CpsPersistenceSpecBase {
@Sql([CLEAR_DATA, SET_DATA])
def 'Delete anchor'() {
when: 'delete anchor action is invoked'
- objectUnderTest.deleteAnchor(DATASPACE_NAME, ANCHOR_NAME1)
- then: 'anchor and associated data fragment are deleted'
+ objectUnderTest.deleteAnchor(DATASPACE_NAME, ANCHOR_NAME2)
+ then: 'anchor is deleted'
assert anchorRepository.findById(DELETED_ANCHOR_ID).isEmpty()
- assert fragmentRepository.findById(DELETED_FRAGMENT_ID).isEmpty()
}
@Sql([CLEAR_DATA, SET_DATA])
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy
index 60d7774cca..41e7a419a5 100755
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2021-2022 Nordix Foundation
* Modifications Copyright (C) 2021 Pantheon.tech
- * Modifications Copyright (C) 2021 Bell Canada.
+ * Modifications Copyright (C) 2021-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.
@@ -35,7 +35,6 @@ import org.onap.cps.spi.model.DataNodeBuilder
import org.onap.cps.utils.JsonObjectMapper
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.jdbc.Sql
-
import javax.validation.ConstraintViolationException
import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
@@ -49,6 +48,8 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
static final JsonObjectMapper jsonObjectMapper = new JsonObjectMapper(new ObjectMapper())
static final String SET_DATA = '/data/fragment.sql'
+ static final int DATASPACE_1001_ID = 1001L
+ static final int ANCHOR_3003_ID = 3003L
static final long ID_DATA_NODE_WITH_DESCENDANTS = 4001
static final String XPATH_DATA_NODE_WITH_DESCENDANTS = '/parent-1'
static final String XPATH_DATA_NODE_WITH_LEAVES = '/parent-100'
@@ -524,6 +525,20 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
'invalid list element' | '/parent-206/child-206/grand-child-206@key="A"]'
}
+ @Sql([CLEAR_DATA, SET_DATA])
+ def 'Delete data node for an anchor.'() {
+ given: 'a data-node exists for an anchor'
+ assert fragmentsExistInDB(DATASPACE_1001_ID, ANCHOR_3003_ID)
+ when: 'data nodes are deleted '
+ objectUnderTest.deleteDataNodes(DATASPACE_NAME, ANCHOR_NAME3)
+ then: 'all data-nodes are deleted successfully'
+ assert !fragmentsExistInDB(DATASPACE_1001_ID, ANCHOR_3003_ID)
+ }
+
+ def fragmentsExistInDB(dataSpaceId, anchorId) {
+ !fragmentRepository.findRootsByDataspaceAndAnchor(dataSpaceId, anchorId).isEmpty()
+ }
+
static Collection<DataNode> toDataNodes(xpaths) {
return xpaths.collect { new DataNodeBuilder().withXpath(it).build() }
}