summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test/groovy
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service/src/test/groovy')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy58
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy39
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy18
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy75
4 files changed, 129 insertions, 61 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy
index c121ce076f..854c568e40 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceSpec.groovy
@@ -21,6 +21,7 @@
package org.onap.cps.ncmp.api.impl
import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService
+import org.onap.cps.ncmp.api.inventory.InventoryPersistence
import org.onap.cps.spi.CpsAdminPersistenceService
import org.onap.cps.spi.CpsDataPersistenceService
import org.onap.cps.spi.model.Anchor
@@ -33,11 +34,9 @@ import java.util.stream.Collectors
class NetworkCmProxyCmHandlerQueryServiceSpec extends Specification {
- def cpsDataPersistenceService = Mock(CpsDataPersistenceService)
- def cpsAdminPersistenceService = Mock(CpsAdminPersistenceService)
+ def inventoryPersistence = Mock(InventoryPersistence)
- NetworkCmProxyCmHandlerQueryService objectUnderTest = new NetworkCmProxyCmHandlerQueryServiceImpl(
- cpsDataPersistenceService, cpsAdminPersistenceService)
+ NetworkCmProxyCmHandlerQueryService objectUnderTest = new NetworkCmProxyCmHandlerQueryServiceImpl(inventoryPersistence)
def 'Retrieve cm handles with public properties when #scenario.'() {
given: 'a condition property'
@@ -130,25 +129,36 @@ class NetworkCmProxyCmHandlerQueryServiceSpec extends Specification {
def pNFDemo4 = new DataNode(xpath: '/dmi-registry/cm-handles[@id=\'PNFDemo4\']', leaves: ['id':'PNFDemo4'])
def dmiRegistry = new DataNode(xpath: '/dmi-registry', childDataNodes: [pNFDemo1, pNFDemo2, pNFDemo3, pNFDemo4])
- cpsDataPersistenceService.queryDataNodes(_, _, '//public-properties[@name=\'Contact\' and @value=\'newemailforstore@bookstore.com\']/ancestor::cm-handles', _) >> [pNFDemo1, pNFDemo2, pNFDemo4]
- cpsDataPersistenceService.queryDataNodes(_, _, '//public-properties[@name=\'wont_match\' and @value=\'wont_match\']/ancestor::cm-handles', _) >> []
- cpsDataPersistenceService.queryDataNodes(_, _, '//public-properties[@name=\'Contact2\' and @value=\'newemailforstore2@bookstore.com\']/ancestor::cm-handles', _) >> [pNFDemo4]
- cpsDataPersistenceService.queryDataNodes(_, _, '//public-properties[@name=\'Contact2\' and @value=\'\']/ancestor::cm-handles', _) >> []
-
- cpsDataPersistenceService.getDataNode(_, _, '/dmi-registry', _) >> dmiRegistry
-
- cpsDataPersistenceService.getDataNode(_, _, '/dmi-registry/cm-handles[@id=\'PNFDemo1\']', _) >> pNFDemo1
- cpsDataPersistenceService.getDataNode(_, _, '/dmi-registry/cm-handles[@id=\'PNFDemo2\']', _) >> pNFDemo2
- cpsDataPersistenceService.getDataNode(_, _, '/dmi-registry/cm-handles[@id=\'PNFDemo3\']', _) >> pNFDemo3
- cpsDataPersistenceService.getDataNode(_, _, '/dmi-registry/cm-handles[@id=\'PNFDemo4\']', _) >> pNFDemo4
-
- cpsAdminPersistenceService.queryAnchors(_, ['MODULE-NAME-001']) >> [new Anchor(name: 'PNFDemo1'), new Anchor(name: 'PNFDemo2'), new Anchor(name: 'PNFDemo3')]
- cpsAdminPersistenceService.queryAnchors(_, ['MODULE-NAME-004']) >> []
- cpsAdminPersistenceService.queryAnchors(_, ['MODULE-NAME-003', 'MODULE-NAME-002']) >> [new Anchor(name: 'PNFDemo4')]
- cpsAdminPersistenceService.queryAnchors(_, ['MODULE-NAME-002', 'MODULE-NAME-003']) >> [new Anchor(name: 'PNFDemo4')]
- cpsAdminPersistenceService.queryAnchors(_, ['MODULE-NAME-004', 'MODULE-NAME-002']) >> []
- cpsAdminPersistenceService.queryAnchors(_, ['MODULE-NAME-002', 'MODULE-NAME-004']) >> []
- cpsAdminPersistenceService.queryAnchors(_, ['MODULE-NAME-002']) >> [new Anchor(name: 'PNFDemo2'), new Anchor(name: 'PNFDemo4')]
- cpsAdminPersistenceService.getAnchors(_) >> [new Anchor(name: 'PNFDemo1'), new Anchor(name: 'PNFDemo2'), new Anchor(name: 'PNFDemo3'), new Anchor(name: 'PNFDemo4')]
+ inventoryPersistence.queryDataNodes('//public-properties[@name=\'Contact\' and @value=\'newemailforstore@bookstore.com\']/ancestor::cm-handles')
+ >> [pNFDemo1, pNFDemo2, pNFDemo4]
+ inventoryPersistence.queryDataNodes('//public-properties[@name=\'wont_match\' and @value=\'wont_match\']/ancestor::cm-handles')
+ >> []
+ inventoryPersistence.queryDataNodes('//public-properties[@name=\'Contact2\' and @value=\'newemailforstore2@bookstore.com\']/ancestor::cm-handles')
+ >> [pNFDemo4]
+ inventoryPersistence.queryDataNodes('//public-properties[@name=\'Contact2\' and @value=\'\']/ancestor::cm-handles')
+ >> []
+ inventoryPersistence.queryDataNodes('//public-properties/ancestor::cm-handles')
+ >> [pNFDemo1, pNFDemo2, pNFDemo3, pNFDemo4]
+
+ inventoryPersistence.queryDataNodes('//cm-handles[@id=\'PNFDemo\']') >> [pNFDemo1]
+ inventoryPersistence.queryDataNodes('//cm-handles[@id=\'PNFDemo2\']') >> [pNFDemo2]
+ inventoryPersistence.queryDataNodes('//cm-handles[@id=\'PNFDemo3\']') >> [pNFDemo3]
+ inventoryPersistence.queryDataNodes('//cm-handles[@id=\'PNFDemo4\']') >> [pNFDemo4]
+
+ inventoryPersistence.getDataNode('/dmi-registry') >> dmiRegistry
+
+ inventoryPersistence.getDataNode('/dmi-registry/cm-handles[@id=\'PNFDemo1\']') >> pNFDemo1
+ inventoryPersistence.getDataNode('/dmi-registry/cm-handles[@id=\'PNFDemo2\']') >> pNFDemo2
+ inventoryPersistence.getDataNode('/dmi-registry/cm-handles[@id=\'PNFDemo3\']') >> pNFDemo3
+ inventoryPersistence.getDataNode('/dmi-registry/cm-handles[@id=\'PNFDemo4\']') >> pNFDemo4
+
+ inventoryPersistence.queryAnchors(['MODULE-NAME-001']) >> [new Anchor(name: 'PNFDemo1'), new Anchor(name: 'PNFDemo2'), new Anchor(name: 'PNFDemo3')]
+ inventoryPersistence.queryAnchors(['MODULE-NAME-004']) >> []
+ inventoryPersistence.queryAnchors(['MODULE-NAME-003', 'MODULE-NAME-002']) >> [new Anchor(name: 'PNFDemo4')]
+ inventoryPersistence.queryAnchors(['MODULE-NAME-002', 'MODULE-NAME-003']) >> [new Anchor(name: 'PNFDemo4')]
+ inventoryPersistence.queryAnchors(['MODULE-NAME-004', 'MODULE-NAME-002']) >> []
+ inventoryPersistence.queryAnchors(['MODULE-NAME-002', 'MODULE-NAME-004']) >> []
+ inventoryPersistence.queryAnchors(['MODULE-NAME-002']) >> [new Anchor(name: 'PNFDemo2'), new Anchor(name: 'PNFDemo4')]
+ inventoryPersistence.getAnchors() >> [new Anchor(name: 'PNFDemo1'), new Anchor(name: 'PNFDemo2'), new Anchor(name: 'PNFDemo3'), new Anchor(name: 'PNFDemo4')]
}
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
index 02e6419c34..31cf31d777 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplRegistrationSpec.groovy
@@ -22,9 +22,8 @@
package org.onap.cps.ncmp.api.impl
import com.fasterxml.jackson.databind.ObjectMapper
-import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService
-import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
+import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService
import org.onap.cps.ncmp.api.impl.exception.DmiRequestException
import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations
import org.onap.cps.ncmp.api.inventory.InventoryPersistence
@@ -51,17 +50,12 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
@Shared
def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: 'some-cm-handle-id')
- @Shared
- def cmHandlesArray = ['cmHandle001']
-
- def mockCpsDataService = Mock(CpsDataService)
def mockCpsModuleService = Mock(CpsModuleService)
def spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper()))
def mockDmiDataOperations = Mock(DmiDataOperations)
def mockNetworkCmProxyDataServicePropertyHandler = Mock(NetworkCmProxyDataServicePropertyHandler)
def mockInventoryPersistence = Mock(InventoryPersistence)
def stubbedNetworkCmProxyCmHandlerQueryService = Stub(NetworkCmProxyCmHandlerQueryService)
- def noTimestamp = null
def objectUnderTest = getObjectUnderTest()
def 'DMI Registration: Create, Update & Delete operations are processed in the right order'() {
@@ -102,8 +96,6 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
response.getRemovedCmHandles() == removeResponses
response.getCreatedCmHandles() == createdResponses
response.getUpdatedCmHandles() == updateResponses
-
-
}
def 'Create CM-handle Validation: Registration with valid Service names: #scenario'() {
@@ -158,17 +150,12 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
assert it.status == Status.SUCCESS
assert it.cmHandle == 'cmhandle'
}
- and: 'save list elements is invoked with the expected parameters'
- interaction {
- 1 * mockCpsDataService.saveListElements('NCMP-Admin', 'ncmp-dmi-registry',
- '/dmi-registry', _, noTimestamp) >> {
+ and: 'save list elements is invoked once with the expected parameters'
+ 1 * mockInventoryPersistence.saveListElements(_) >> {
args -> {
- assert args[3].startsWith('{"cm-handles":[{"id":"cmhandle","dmi-service-name":"my-server","state":{"cm-handle-state":"ADVISED","last-update-time":"20')
- assert args[3].contains(expectedDmiProperties)
- assert args[3].contains(expectedPublicProperties)
+ assert args[0].startsWith('{"cm-handles":[{"id":"cmhandle","dmi-service-name":"my-server","state":{"cm-handle-state":"ADVISED","last-update-time":"20')
}
}
- }
where:
scenario | dmiProperties | publicProperties || expectedDmiProperties | expectedPublicProperties
'with dmi & public properties' | ['dmi-key': 'dmi-value'] | ['public-key': 'public-value'] || '[{"name":"dmi-key","value":"dmi-value"}]' | '[{"name":"public-key","value":"public-value"}]'
@@ -185,7 +172,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
new NcmpServiceCmHandle(cmHandleId: 'cmhandle2'),
new NcmpServiceCmHandle(cmHandleId: 'cmhandle3')])
and: 'cm-handle creation is successful for 1st and 3rd; failed for 2nd'
- mockCpsDataService.saveListElements(_, _, _, _, _) >> {} >> { throw new RuntimeException("Failed") } >> {}
+ mockInventoryPersistence.saveListElements(_) >> {} >> { throw new RuntimeException("Failed") } >> {}
when: 'registration is updated to create cm-handles'
def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
then: 'a response is received for all cm-handles'
@@ -213,7 +200,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server')
dmiPluginRegistration.createdCmHandles = [new NcmpServiceCmHandle(cmHandleId: cmHandleId)]
and: 'cm-handler registration fails: #scenario'
- mockCpsDataService.saveListElements(_, _, _, _, _) >> { throw exception }
+ mockInventoryPersistence.saveListElements(_) >> { throw exception }
when: 'registration is updated'
def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
then: 'a failure response is received'
@@ -258,7 +245,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
when: 'registration is updated to delete cmhandle'
def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
then: 'delete list or list element is called'
- 1 * mockCpsDataService.deleteListOrListElement(_, _, _, _)
+ 1 * mockInventoryPersistence.deleteListOrListElement(_)
and: 'successful response is received'
assert response.getRemovedCmHandles().size() == 1
with(response.getRemovedCmHandles().get(0)) {
@@ -276,7 +263,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
removedCmHandles: ['cmhandle1', 'cmhandle2', 'cmhandle3'])
and: 'cm-handle deletion is successful for 1st and 3rd; failed for 2nd'
- mockCpsDataService.deleteListOrListElement(_, _, _, _) >> {} >> { throw new RuntimeException("Failed") } >> {}
+ mockInventoryPersistence.deleteListOrListElement(_) >> {} >> { throw new RuntimeException("Failed") } >> {}
when: 'registration is updated to delete cmhandles'
def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
then: 'a response is received for all cm-handles'
@@ -304,13 +291,13 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
removedCmHandles: ['cmhandle'])
and: 'schema set deletion failed with unknown error'
- mockCpsModuleService.deleteSchemaSet(_, _, _) >> { throw new RuntimeException('Failed') }
+ mockInventoryPersistence.deleteSchemaSetWithCascade(_) >> { throw new RuntimeException('Failed') }
when: 'registration is updated to delete cmhandle'
def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
then: 'no exception is thrown'
noExceptionThrown()
and: 'cm-handle is not deleted'
- 0 * mockCpsDataService.deleteListOrListElement(_, _, _, _)
+ 0 * mockInventoryPersistence.deleteListOrListElement(_)
and: 'a failure response is received'
assert response.getRemovedCmHandles().size() == 1
with(response.getRemovedCmHandles().get(0)) {
@@ -326,7 +313,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
def dmiPluginRegistration = new DmiPluginRegistration(dmiPlugin: 'my-server',
removedCmHandles: ['cmhandle'])
and: 'cm-handle deletion throws exception'
- mockCpsDataService.deleteListOrListElement(_, _, _, _) >> { throw deleteListElementException }
+ mockInventoryPersistence.deleteListOrListElement(_) >> { throw deleteListElementException }
when: 'registration is updated to delete cmhandle'
def response = objectUnderTest.updateDmiRegistrationAndSyncModule(dmiPluginRegistration)
then: 'no exception is thrown'
@@ -347,7 +334,7 @@ class NetworkCmProxyDataServiceImplRegistrationSpec extends Specification {
}
def getObjectUnderTest() {
- return Spy(new NetworkCmProxyDataServiceImpl(mockCpsDataService, spiedJsonObjectMapper, mockDmiDataOperations,
- mockCpsModuleService, mockNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, stubbedNetworkCmProxyCmHandlerQueryService))
+ return Spy(new NetworkCmProxyDataServiceImpl(spiedJsonObjectMapper, mockDmiDataOperations,
+ mockNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, stubbedNetworkCmProxyCmHandlerQueryService))
}
}
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
index 0871a89967..1c8b561141 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy
@@ -47,7 +47,6 @@ import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum
import org.onap.cps.utils.JsonObjectMapper
import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.cps.api.CpsDataService
-import org.onap.cps.api.CpsModuleService
import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations
import org.onap.cps.spi.FetchDescendantsOption
import org.onap.cps.spi.model.DataNode
@@ -58,7 +57,6 @@ import spock.lang.Specification
class NetworkCmProxyDataServiceImplSpec extends Specification {
def mockCpsDataService = Mock(CpsDataService)
- def mockCpsModuleService = Mock(CpsModuleService)
def spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper()))
def mockDmiDataOperations = Mock(DmiDataOperations)
def nullNetworkCmProxyDataServicePropertyHandler = null
@@ -73,8 +71,8 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
@Shared
def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: 'some-cm-handle-id')
- def objectUnderTest = new NetworkCmProxyDataServiceImpl(mockCpsDataService, spiedJsonObjectMapper, mockDmiDataOperations,
- mockCpsModuleService, nullNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, mockCpsCmHandlerQueryService)
+ def objectUnderTest = new NetworkCmProxyDataServiceImpl(spiedJsonObjectMapper, mockDmiDataOperations,
+ nullNetworkCmProxyDataServicePropertyHandler, mockInventoryPersistence, mockCpsCmHandlerQueryService)
def cmHandleXPath = "/dmi-registry/cm-handles[@id='testCmHandle']"
@@ -152,7 +150,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
when: 'yang resources is called'
objectUnderTest.getYangResourcesModuleReferences('some-cm-handle')
then: 'CPS module services is invoked for the correct dataspace and cm handle'
- 1 * mockCpsModuleService.getYangResourcesModuleReferences('NFP-Operational','some-cm-handle')
+ 1 * mockInventoryPersistence.getYangResourcesModuleReferences('some-cm-handle')
}
def 'Getting Yang Resources with an invalid #scenario.'() {
@@ -161,7 +159,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
then: 'a data validation exception is thrown'
thrown(DataValidationException)
and: 'CPS module services is not invoked'
- 0 * mockCpsModuleService.getYangResourcesModuleReferences(*_)
+ 0 * mockInventoryPersistence.getYangResourcesModuleReferences(*_)
}
def 'Get a cm handle.'() {
@@ -273,11 +271,11 @@ class NetworkCmProxyDataServiceImplSpec extends Specification {
when: 'parse and create cm handle in dmi registration then sync module'
objectUnderTest.parseAndCreateCmHandlesInDmiRegistrationAndSyncModules(mockDmiPluginRegistration)
then: 'validate params for creating anchor and list elements'
- 1 * mockCpsDataService.saveListElements('NCMP-Admin', 'ncmp-dmi-registry', '/dmi-registry', _, null) >> {
- args -> {
- assert args[3].startsWith('{"cm-handles":[{"id":"some-cm-handle-id","state":{"cm-handle-state":"ADVISED","last-update-time":"20')
+ 1 * mockInventoryPersistence.saveListElements(_) >> {
+ args -> {
+ assert args[0].startsWith('{"cm-handles":[{"id":"some-cm-handle-id","state":{"cm-handle-state":"ADVISED","last-update-time":"20')
+ }
}
- }
}
def 'Execute cm handle id search'() {
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy
index 638af32e2c..9b50c5ad47 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/inventory/InventoryPersistenceSpec.groovy
@@ -25,11 +25,14 @@ import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
+import org.onap.cps.spi.CascadeDeleteAllowed
import org.onap.cps.spi.CpsDataPersistenceService
+import org.onap.cps.spi.CpsAdminPersistenceService
import org.onap.cps.spi.FetchDescendantsOption
import org.onap.cps.spi.exceptions.DataValidationException
import org.onap.cps.spi.model.DataNode
import org.onap.cps.spi.model.ModuleDefinition
+import org.onap.cps.spi.model.ModuleReference
import org.onap.cps.utils.JsonObjectMapper
import spock.lang.Shared
import spock.lang.Specification
@@ -51,7 +54,10 @@ class InventoryPersistenceSpec extends Specification {
def mockCpsDataPersistenceService = Mock(CpsDataPersistenceService)
- def objectUnderTest = new InventoryPersistence(spiedJsonObjectMapper, mockCpsDataService, mockCpsModuleService, mockCpsDataPersistenceService)
+ def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService)
+
+ def objectUnderTest = new InventoryPersistence(spiedJsonObjectMapper, mockCpsDataService, mockCpsModuleService,
+ mockCpsDataPersistenceService, mockCpsAdminPersistenceService)
def formattedDateAndTime = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
.format(OffsetDateTime.of(2022, 12, 31, 20, 30, 40, 1, ZoneOffset.UTC))
@@ -210,4 +216,71 @@ class InventoryPersistenceSpec extends Specification {
assert result == moduleDefinitions
}
+ def 'Get module references'() {
+ given: 'cps module service returns a collection of module references'
+ def moduleReferences = [new ModuleReference('moduleName','revision','namespace')]
+ mockCpsModuleService.getYangResourcesModuleReferences('NFP-Operational','some-cmHandle-Id') >> moduleReferences
+ when: 'get yang resources module references by cmHandle is invoked'
+ def result = objectUnderTest.getYangResourcesModuleReferences('some-cmHandle-Id')
+ then: 'the returned result is a collection of module definitions'
+ assert result == moduleReferences
+ }
+
+ def 'Save list elements'() {
+ when: 'the method to save list elements is called'
+ objectUnderTest.saveListElements('sample Json data')
+ then: 'the data service method to save list elements is called once'
+ 1 * mockCpsDataService.saveListElements('NCMP-Admin','ncmp-dmi-registry','/dmi-registry','sample Json data',null)
+ }
+
+ def 'Delete list or list elements'() {
+ when: 'the method to delete list or list elements is called'
+ objectUnderTest.deleteListOrListElement('sample xPath')
+ then: 'the data service method to save list elements is called once'
+ 1 * mockCpsDataService.deleteListOrListElement('NCMP-Admin','ncmp-dmi-registry','sample xPath',null)
+ }
+
+ def 'Delete schema set with a valid schema set name'() {
+ when: 'the method to delete schema set is called with valid schema set name'
+ objectUnderTest.deleteSchemaSetWithCascade('validSchemaSetName')
+ then: 'the module service to delete schemaSet is invoked once'
+ 1 * mockCpsModuleService.deleteSchemaSet('NFP-Operational', 'validSchemaSetName', CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED)
+ }
+
+ def 'Delete schema set with an invalid schema set name'() {
+ when: 'the method to delete schema set is called with an invalid schema set name'
+ objectUnderTest.deleteSchemaSetWithCascade('invalid SchemaSet name')
+ then: 'a data validation exception is thrown'
+ thrown(DataValidationException)
+ and: 'the module service to delete schemaSet is not called'
+ 0 * mockCpsModuleService.deleteSchemaSet('NFP-Operational', 'sampleSchemaSetName', CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED)
+ }
+
+ def 'Query data nodes via cpsPath'() {
+ when: 'the method to query data nodes is called'
+ objectUnderTest.queryDataNodes('sample cpsPath')
+ then: 'the data persistence service method to query data nodes is invoked once'
+ 1 * mockCpsDataPersistenceService.queryDataNodes('NCMP-Admin','ncmp-dmi-registry','sample cpsPath', INCLUDE_ALL_DESCENDANTS)
+ }
+
+ def 'Get data node via xPath'() {
+ when: 'the method to get data nodes is called'
+ objectUnderTest.getDataNode('sample xPath')
+ then: 'the data persistence service method to get data node is invoked once'
+ 1 * mockCpsDataPersistenceService.getDataNode('NCMP-Admin','ncmp-dmi-registry','sample xPath', INCLUDE_ALL_DESCENDANTS)
+ }
+
+ def 'Query anchors'() {
+ when: 'the method to query anchors is called'
+ objectUnderTest.queryAnchors(['sample-module-name'])
+ then: 'the admin persistence service method to query anchors is invoked once with the same parameter'
+ 1 * mockCpsAdminPersistenceService.queryAnchors('NFP-Operational',['sample-module-name'])
+ }
+
+ def 'Get anchors'() {
+ when: 'the method to get anchors with no parameters is called'
+ objectUnderTest.getAnchors()
+ then: 'the admin persistence service method to query anchors is invoked once with a specific dataspace name'
+ 1 * mockCpsAdminPersistenceService.getAnchors('NFP-Operational')
+ }
}