From 91d66108379d7cd397aedc30da4801d20643ee68 Mon Sep 17 00:00:00 2001 From: mpriyank Date: Fri, 26 Aug 2022 13:26:01 +0100 Subject: Performance Improvement:save cmhandles capability - add saveCmHandleBatch in InventoryPersistence - add saveListElementsBatch in CpsDataService - have addListElementsBatch in CpsDataPersistenceService - Test scenarios for the same Issue-ID: CPS-1229 Issue-ID: CPS-1126 Change-Id: I0a1401818da5a4e523d7d0751cac6a526d1611b2 Signed-off-by: mpriyank --- .../onap/cps/api/impl/CpsDataServiceImplSpec.groovy | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'cps-service/src/test') 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 cb352bcce..ab960df6a 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 @@ -37,6 +37,7 @@ import org.onap.cps.yang.YangTextSchemaSourceSetBuilder import spock.lang.Specification import java.time.OffsetDateTime +import java.util.stream.Collectors class CpsDataServiceImplSpec extends Specification { def mockCpsDataPersistenceService = Mock(CpsDataPersistenceService) @@ -135,6 +136,26 @@ class CpsDataServiceImplSpec extends Specification { 1 * mockNotificationService.processDataUpdatedEvent(dataspaceName, anchorName, '/test-tree', Operation.UPDATE, observedTimestamp) } + def 'Saving collection of a batch with data fragment under existing node.'() { + given: 'schema set for given anchor and dataspace references test-tree model' + setupSchemaSetMocks('test-tree.yang') + when: 'save data method is invoked with list element json data' + def jsonData = '{"branch": [{"name": "A"}, {"name": "B"}]}' + objectUnderTest.saveListElementsBatch(dataspaceName, anchorName, '/test-tree', [jsonData], observedTimestamp) + then: 'the persistence service method is invoked with correct parameters' + 1 * mockCpsDataPersistenceService.addListElementsBatch(dataspaceName, anchorName, '/test-tree',_) >> { + args -> { + def listElementsCollection = args[3] as Collection> + assert listElementsCollection.size() == 1 + def listOfXpaths = listElementsCollection.stream().flatMap(x -> x.stream()).map(it-> it.xpath).collect(Collectors.toList()) + assert listOfXpaths.size() == 2 + assert listOfXpaths.containsAll(['/test-tree/branch[@name=\'B\']','/test-tree/branch[@name=\'A\']']) + } + } + and: 'data updated event is sent to notification service' + 1 * mockNotificationService.processDataUpdatedEvent(dataspaceName, anchorName, '/test-tree', Operation.UPDATE, observedTimestamp) + } + def 'Saving empty list element data fragment.'() { given: 'schema set for given anchor and dataspace references test-tree model' setupSchemaSetMocks('test-tree.yang') -- cgit 1.2.3-korg