aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri/src/test/groovy/org/onap
diff options
context:
space:
mode:
authorniamhcore <niamh.core@est.tech>2021-10-21 15:19:04 +0100
committerniamhcore <niamh.core@est.tech>2021-10-29 09:20:39 +0100
commita1c6e6ac56f9e53f08b329ce7f5069514c62fc77 (patch)
tree124ea9506d021c70d430e213015b9e9522f0f184 /cps-ri/src/test/groovy/org/onap
parentd5bc2ef86b68ba6e8fdc8cf808e9cc0065ce2ae2 (diff)
Add get cm handles by modules names - persistence layer
- Add sql query to anchor repository - Add sql query to yang resource repository Issue-ID: CPS-644 Signed-off-by: niamhcore <niamh.core@est.tech> Change-Id: I85ab1fcb343e6be77628695153d8d9f303dc3112
Diffstat (limited to 'cps-ri/src/test/groovy/org/onap')
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsAdminPersistenceServiceSpec.groovy35
1 files changed, 35 insertions, 0 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 cff8d56321..c37651089f 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
@@ -26,6 +26,7 @@ import org.onap.cps.spi.exceptions.AlreadyDefinedException
import org.onap.cps.spi.exceptions.AnchorNotFoundException
import org.onap.cps.spi.exceptions.DataspaceNotFoundException
import org.onap.cps.spi.exceptions.SchemaSetNotFoundException
+import org.onap.cps.spi.exceptions.ModuleNamesNotFoundException
import org.onap.cps.spi.model.Anchor
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.jdbc.Sql
@@ -37,6 +38,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 EMPTY_DATASPACE_NAME = 'DATASPACE-002'
static final Integer DELETED_ANCHOR_ID = 3001
static final Long DELETED_FRAGMENT_ID = 4001
@@ -140,4 +142,37 @@ class CpsAdminPersistenceServiceSpec extends CpsPersistenceSpecBase {
'dataspace does not exist' | 'unknown' | 'not-relevant' || DataspaceNotFoundException
'anchor does not exists' | DATASPACE_NAME | 'unknown' || AnchorNotFoundException
}
+
+ @Sql([CLEAR_DATA, SAMPLE_DATA_FOR_ANCHORS_WITH_MODULES])
+ def 'Get anchors that have #scenario.'() {
+ when: 'all anchor are retrieved for the given dataspace name and module names'
+ def anchors = objectUnderTest.getAnchors('DATASPACE-001', inputModuleNames)
+ then: 'the expected anchors are returned'
+ anchors.size() == expectedAnchors.size()
+ anchors.containsAll(expectedAnchors)
+ where: 'the following data is used'
+ scenario | inputModuleNames || expectedAnchors
+ 'one module' | ['MODULE-NAME-001'] || [buildAnchor('ANCHOR1', 'DATASPACE-001', 'SCHEMA-SET-001')]
+ 'two modules' | ['MODULE-NAME-001', 'MODULE-NAME-002'] || [buildAnchor('ANCHOR1', 'DATASPACE-001', 'SCHEMA-SET-001'), buildAnchor('ANCHOR2', 'DATASPACE-001', 'SCHEMA-SET-002'), buildAnchor('ANCHOR3', 'DATASPACE-001', 'SCHEMA-SET-004')]
+ 'a module attached to multiple anchors' | ['MODULE-NAME-003'] || [buildAnchor('ANCHOR1', 'DATASPACE-001', 'SCHEMA-SET-001'), buildAnchor('ANCHOR2', 'DATASPACE-001', 'SCHEMA-SET-002')]
+ 'same module with different revisions' | ['MODULE-NAME-002'] || [buildAnchor('ANCHOR2', 'DATASPACE-001', 'SCHEMA-SET-002'), buildAnchor('ANCHOR3', 'DATASPACE-001', 'SCHEMA-SET-004')]
+ }
+
+ @Sql([CLEAR_DATA, SAMPLE_DATA_FOR_ANCHORS_WITH_MODULES])
+ def 'Get all anchors for an #scenario.'() {
+ when: 'attempt to get anchors'
+ objectUnderTest.getAnchors(dataspaceName, moduleNames)
+ then: 'the correct exception is thrown with the relevant details'
+ def thrownException = thrown(expectedException)
+ thrownException.details.contains(expectedMessageDetails)
+ where: 'the following data is used'
+ scenario | dataspaceName | moduleNames || expectedException | expectedMessageDetails
+ 'existing module in an unknown dataspace' | 'db-does-not-exist' | ['does-not-matter'] || DataspaceNotFoundException | 'db-does-not-exist'
+ 'unknown module in an existing dataspace' | 'DATASPACE-001' | ['module-does-not-exist'] || ModuleNamesNotFoundException | 'module-does-not-exist'
+ 'unknown module and known module in an existing dataspace' | 'DATASPACE-001' | ['MODULE-NAME-001', 'module-does-not-exist'] || ModuleNamesNotFoundException | 'module-does-not-exist'
+ }
+
+ def buildAnchor(def anchorName, def dataspaceName, def SchemaSetName) {
+ return Anchor.builder().name(anchorName).dataspaceName(dataspaceName).schemaSetName(SchemaSetName).build()
+ }
}