diff options
author | sourabh_sourabh <sourabh.sourabh@est.tech> | 2022-11-08 11:46:05 +0000 |
---|---|---|
committer | sourabh_sourabh <sourabh.sourabh@est.tech> | 2022-11-11 12:30:57 +0000 |
commit | 1d5a12201981035805add15dbad3637e182ee061 (patch) | |
tree | 3a8325862c36d18a12e20121ee2c181943a9cb2a /cps-ri/src/test/groovy/org/onap | |
parent | b99f0f00cb964af7b88a85c09bbb11f6c0b1f04d (diff) |
Node API - Find root by anchor method performance
- Modified findFirstRootByAnchor
- Used fragment extract to build fragment entity to get root data node.
Reviewers : Toine, Priyank and Joe
Issue-ID: CPS-1171
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Change-Id: I843f270e4781f91ae496f39b976e2a7f2a14d55e
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Diffstat (limited to 'cps-ri/src/test/groovy/org/onap')
-rwxr-xr-x | cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy | 36 | ||||
-rw-r--r-- | cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsPersistenceSpecBase.groovy | 1 |
2 files changed, 19 insertions, 18 deletions
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 a5e17cfefd..fbf414d2ad 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 @@ -56,7 +56,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { 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' + static final String XPATH_DATA_NODE_WITH_LEAVES = '/parent-207' static final long DATA_NODE_202_FRAGMENT_ID = 4202L static final long CHILD_OF_DATA_NODE_202_FRAGMENT_ID = 4203L static final long LIST_DATA_NODE_PARENT201_FRAGMENT_ID = 4206L @@ -69,10 +69,10 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { static DataNode existingChildDataNode def expectedLeavesByXpathMap = [ - '/parent-100' : ['parent-leaf': 'parent-leaf value'], - '/parent-100/child-001' : ['first-child-leaf': 'first-child-leaf value'], - '/parent-100/child-002' : ['second-child-leaf': 'second-child-leaf value'], - '/parent-100/child-002/grand-child': ['grand-child-leaf': 'grand-child-leaf value'] + '/parent-207' : ['parent-leaf': 'parent-leaf value'], + '/parent-207/child-001' : ['first-child-leaf': 'first-child-leaf value'], + '/parent-207/child-002' : ['second-child-leaf': 'second-child-leaf value'], + '/parent-207/child-002/grand-child': ['grand-child-leaf': 'grand-child-leaf value'] ] static { @@ -196,24 +196,24 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { @Sql([CLEAR_DATA, SET_DATA]) def 'Add multiple list with a mix of existing and new elements'() { given: 'two new child list elements for an existing parent' - def existingDataNode = dataNodeBuilder.withXpath('/parent-100/child-001').withLeaves(['id': '001']).build() - def newDataNode1 = dataNodeBuilder.withXpath('/parent-100/child-new1').withLeaves(['id': 'new1']).build() + def existingDataNode = dataNodeBuilder.withXpath('/parent-207/child-001').withLeaves(['id': '001']).build() + def newDataNode1 = dataNodeBuilder.withXpath('/parent-207/child-new1').withLeaves(['id': 'new1']).build() def newDataNode2 = dataNodeBuilder.withXpath('/parent-200/child-new2').withLeaves(['id': 'new2']).build() def dataNodeList1 = [existingDataNode, newDataNode1] def dataNodeList2 = [newDataNode2] when: 'duplicate data node is requested to be added' - objectUnderTest.addMultipleLists(DATASPACE_NAME, ANCHOR_NAME3, '/', [dataNodeList1,dataNodeList2]) + objectUnderTest.addMultipleLists(DATASPACE_NAME, ANCHOR_HAVING_SINGLE_TOP_LEVEL_FRAGMENT, '/', [dataNodeList1, dataNodeList2]) then: 'already defined batch exception is thrown' def thrown = thrown(AlreadyDefinedExceptionBatch) and: 'it only contains the xpath(s) of the duplicated elements' assert thrown.alreadyDefinedXpaths.size() == 1 - assert thrown.alreadyDefinedXpaths.contains('/parent-100/child-001') + assert thrown.alreadyDefinedXpaths.contains('/parent-207/child-001') and: 'it does NOT contains the xpaths of the new element that were not combined with existing elements' - assert !thrown.alreadyDefinedXpaths.contains('/parent-100/child-new1') - assert !thrown.alreadyDefinedXpaths.contains('/parent-100/child-new1') + assert !thrown.alreadyDefinedXpaths.contains('/parent-207/child-new1') + assert !thrown.alreadyDefinedXpaths.contains('/parent-207/child-new1') and: 'the new entity is inserted correctly' def dataspaceEntity = dataspaceRepository.getByName(DATASPACE_NAME) - def anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, ANCHOR_NAME3) + def anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, ANCHOR_HAVING_SINGLE_TOP_LEVEL_FRAGMENT) fragmentRepository.findByDataspaceAndAnchorAndXpath(dataspaceEntity, anchorEntity, '/parent-200/child-new2').isPresent() } @@ -234,7 +234,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { @Sql([CLEAR_DATA, SET_DATA]) def 'Get data node by xpath without descendants.'() { when: 'data node is requested' - def result = objectUnderTest.getDataNode(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, + def result = objectUnderTest.getDataNode(DATASPACE_NAME, ANCHOR_HAVING_SINGLE_TOP_LEVEL_FRAGMENT, inputXPath, OMIT_DESCENDANTS) then: 'data node is returned with no descendants' assert result.xpath == XPATH_DATA_NODE_WITH_LEAVES @@ -243,7 +243,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { assertLeavesMaps(result.leaves, expectedLeavesByXpathMap[XPATH_DATA_NODE_WITH_LEAVES]) where: 'the following data is used' scenario | inputXPath - 'some xpath' | '/parent-100' + 'some xpath' | '/parent-207' 'root xpath' | '/' 'empty xpath' | '' } @@ -260,20 +260,20 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase { @Sql([CLEAR_DATA, SET_DATA]) def 'Get data node by xpath with all descendants.'() { when: 'data node is requested with all descendants' - def result = objectUnderTest.getDataNode(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, + def result = objectUnderTest.getDataNode(DATASPACE_NAME, ANCHOR_HAVING_SINGLE_TOP_LEVEL_FRAGMENT, inputXPath, INCLUDE_ALL_DESCENDANTS) def mappedResult = treeToFlatMapByXpath(new HashMap<>(), result) then: 'data node is returned with all the descendants populated' assert mappedResult.size() == 4 assert result.childDataNodes.size() == 2 - assert mappedResult.get('/parent-100/child-001').childDataNodes.size() == 0 - assert mappedResult.get('/parent-100/child-002').childDataNodes.size() == 1 + assert mappedResult.get('/parent-207/child-001').childDataNodes.size() == 0 + assert mappedResult.get('/parent-207/child-002').childDataNodes.size() == 1 and: 'extracted leaves maps are matching expected' mappedResult.forEach( (xPath, dataNode) -> assertLeavesMaps(dataNode.leaves, expectedLeavesByXpathMap[xPath])) where: 'the following data is used' scenario | inputXPath - 'some xpath' | '/parent-100' + 'some xpath' | '/parent-207' 'root xpath' | '/' 'empty xpath' | '' } 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 d6f10d809d..1ecad4e68c 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 @@ -68,4 +68,5 @@ class CpsPersistenceSpecBase extends Specification { static final String ANCHOR_NAME3 = 'ANCHOR-003' static final String ANCHOR_FOR_DATA_NODES_WITH_LEAVES = 'ANCHOR-003' static final String ANCHOR_FOR_SHOP_EXAMPLE = 'ANCHOR-004' + static final String ANCHOR_HAVING_SINGLE_TOP_LEVEL_FRAGMENT = 'ANCHOR-005' } |