summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ri/src/test')
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy45
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy1
-rw-r--r--cps-ri/src/test/resources/data/schemaset.sql28
3 files changed, 48 insertions, 26 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 7a16a97d4..a139830a2 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
@@ -20,22 +20,23 @@
*/
package org.onap.cps.spi.impl
-import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED
-import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED
-
import org.onap.cps.spi.CpsAdminPersistenceService
import org.onap.cps.spi.CpsModulePersistenceService
import org.onap.cps.spi.entities.YangResourceEntity
-import org.onap.cps.spi.exceptions.DataspaceNotFoundException
import org.onap.cps.spi.exceptions.AlreadyDefinedException
+import org.onap.cps.spi.exceptions.DataspaceNotFoundException
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.model.ExtendedModuleReference
import org.onap.cps.spi.repository.AnchorRepository
import org.onap.cps.spi.repository.SchemaSetRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.jdbc.Sql
+import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED
+import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED
+
class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
@Autowired
@@ -71,13 +72,13 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase
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)
+ static final ExtendedModuleReference newModuleReference = ExtendedModuleReference.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 allYangResourcesModuleAndRevisionList = [new ExtendedModuleReference(name: 'MODULE-NAME-002',namespace:null, revision: 'REVISION-002'), new ExtendedModuleReference(name: 'MODULE-NAME-003',namespace:null, revision: 'REVISION-003'),
+ new ExtendedModuleReference(name: 'MODULE-NAME-004',namespace:null, revision: 'REVISION-004'), ExtendedModuleReference.builder().build(),
+ ExtendedModuleReference.builder().build(), newModuleReference]
def dataspaceEntity
def setup() {
@@ -109,7 +110,7 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase
def 'Store and retrieve new schema set from new modules and existing modules.'() {
given: 'map of new modules, a list of existing modules, module reference'
def mapOfNewModules = [newModule1: 'module newmodule { yang-version 1.1; revision "2021-10-12" { } }']
- def moduleReferenceForExistingModule = new ModuleReference("test","test.org","2021-10-12")
+ def moduleReferenceForExistingModule = new ModuleReference("test","2021-10-12")
def listOfExistingModulesModuleReference = [moduleReferenceForExistingModule]
def mapOfExistingModule = [test: 'module test { yang-version 1.1; revision "2021-10-12" { } }']
objectUnderTest.storeSchemaSet(DATASPACE_NAME, "someSchemaSetName", mapOfExistingModule)
@@ -135,13 +136,27 @@ 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()
+ def 'Retrieving all yang resources module references for the given dataspace.'() {
+ given: 'a dataspace name'
+ def dataspaceName = 'DATASPACE-002'
+ when: 'all yang resources module references are retrieved for the given dataspace name'
+ def result = objectUnderTest.getAllYangResourceModuleReferences(dataspaceName)
then: 'the correct resources are returned'
- result.sort() == allYangResourcesModuleAndRevisionList.sort()
+ result.sort() == [new ModuleReference(moduleName: 'MODULE-NAME-005', revision: 'REVISION-002'),
+ new ModuleReference(moduleName: 'MODULE-NAME-006', revision: 'REVISION-006')]
+ }
+
+ @Sql([CLEAR_DATA, SET_DATA])
+ def 'Retrieving module names and revisions for the given anchor.'() {
+ given: 'a dataspace name and anchor name'
+ def dataspaceName = 'DATASPACE-001'
+ def anchorName = 'ANCHOR1'
+ when: 'all yang resources module references are retrieved for the given anchor'
+ def result = objectUnderTest.getAllYangResourceModuleReferences(dataspaceName, anchorName)
+ then: 'the correct module names and revisions are returned'
+ result.sort() == [new ModuleReference(moduleName: null, revision: null), new ModuleReference(moduleName: 'MODULE-NAME-002', revision: 'REVISION-002'),
+ new ModuleReference(moduleName: 'MODULE-NAME-003', revision: 'REVISION-002'),
+ new ModuleReference(moduleName: 'MODULE-NAME-004', revision: 'REVISION-004')]
}
@Sql([CLEAR_DATA, SET_DATA])
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy
index 513263245..8ec5c90e9 100644
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy
@@ -55,6 +55,7 @@ class CpsPersistenceSpecBase extends Specification {
static final String CLEAR_DATA = '/data/clear-all.sql'
static final String DATASPACE_NAME = 'DATASPACE-001'
+ static final String DATASPACE_NAME2 = 'DATASPACE-002'
static final String SCHEMA_SET_NAME1 = 'SCHEMA-SET-001'
static final String SCHEMA_SET_NAME2 = 'SCHEMA-SET-002'
static final String ANCHOR_NAME1 = 'ANCHOR-001'
diff --git a/cps-ri/src/test/resources/data/schemaset.sql b/cps-ri/src/test/resources/data/schemaset.sql
index adfcfa172..61600356b 100644
--- a/cps-ri/src/test/resources/data/schemaset.sql
+++ b/cps-ri/src/test/resources/data/schemaset.sql
@@ -24,26 +24,32 @@ INSERT INTO DATASPACE (ID, NAME) VALUES
(1001, 'DATASPACE-001'), (1002, 'DATASPACE-002');
INSERT INTO SCHEMA_SET (ID, NAME, DATASPACE_ID) VALUES
- (2001, 'SCHEMA-SET-001', 1001), (2002, 'SCHEMA-SET-002', 1001),
+ (2001, 'SCHEMA-SET-001', 1001),
+ (2002, 'SCHEMA-SET-002', 1001),
(2100, 'SCHEMA-SET-100', 1001), -- for removal, not referenced by anchors
- (2101, 'SCHEMA-SET-101', 1001); -- for removal, having anchor and data associated
-
-INSERT INTO YANG_RESOURCE (ID, NAME, CONTENT, CHECKSUM) VALUES
- (3001, 'module1@2020-02-02.yang', 'CONTENT-001', 'e8bdda931099310de66532e08c3fafec391db29f55c81927b168f6aa8f81b73b'),
- (3002, 'module2@2020-02-02.yang', 'CONTENT-002', '7e7d48afbe066ed0a890a09081859046d3dde52300dfcdb13be5b20780353a11'),
- (3003, 'module3@2020-02-02.yang', 'CONTENT-003', 'ca20c45fec8547633f05ff8905c48ffa7b02b94ec3ad4ed79922e6ba40779df3'),
- (3004, 'module4@2020-02-02.yang', 'CONTENT-004', 'f6ed09d343562e4d4ae5140f3c6a55df9c53f6da8e30dda8cbd9eaf9cd449be0'),
- (3100, 'orphan@2020-02-02.yang', 'ORPHAN', 'checksum'); -- for auto-removal as orphan
+ (2101, 'SCHEMA-SET-101', 1001), -- for removal, having anchor and data associated
+ (2003, 'SCHEMA-SET-003', 1002),
+ (2004, 'SCHEMA-SET-004', 1002);
+
+INSERT INTO YANG_RESOURCE (ID, NAME, CONTENT, CHECKSUM, MODULE_NAME, REVISION) VALUES
+ (3001, 'module1@2020-02-02.yang', 'CONTENT-001', 'e8bdda931099310de66532e08c3fafec391db29f55c81927b168f6aa8f81b73b',null,null),
+ (3002, 'module2@2020-02-02.yang', 'CONTENT-002', '7e7d48afbe066ed0a890a09081859046d3dde52300dfcdb13be5b20780353a11','MODULE-NAME-002','REVISION-002'),
+ (3003, 'module3@2020-02-02.yang', 'CONTENT-003', 'ca20c45fec8547633f05ff8905c48ffa7b02b94ec3ad4ed79922e6ba40779df3','MODULE-NAME-003','REVISION-002'),
+ (3004, 'module4@2020-02-02.yang', 'CONTENT-004', 'f6ed09d343562e4d4ae5140f3c6a55df9c53f6da8e30dda8cbd9eaf9cd449be0','MODULE-NAME-004','REVISION-004'),
+ (3100, 'orphan@2020-02-02.yang', 'ORPHAN', 'checksum',null,null), -- for auto-removal as orphan
+ (3005, 'module5@2020-02-02.yang', 'CONTENT-005', 'checksum-005','MODULE-NAME-005','REVISION-002'),
+ (3006, 'module6@2020-02-02.yang', 'CONTENT-006', 'checksum-006','MODULE-NAME-006','REVISION-006');
INSERT INTO SCHEMA_SET_YANG_RESOURCES (SCHEMA_SET_ID, YANG_RESOURCE_ID) VALUES
(2001, 3001), (2001, 3002),
(2002, 3003), (2002, 3004),
(2100, 3003), (2100, 3100), -- orphan removal case
- (2101, 3003), (2101, 3004);
+ (2101, 3003), (2101, 3004),
+ (2003, 3005), (2004, 3006);
INSERT INTO ANCHOR (ID, NAME, DATASPACE_ID, SCHEMA_SET_ID) VALUES -- anchors for removal
(6001, 'ANCHOR1', 1001, 2101),
(6002, 'ANCHOR2', 1001, 2101);
INSERT INTO FRAGMENT (ID, XPATH, ANCHOR_ID, DATASPACE_ID) VALUES
- (7001, '/XPATH', 6001, 1001);
+ (7001, '/XPATH', 6001, 1001); \ No newline at end of file