summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/test
diff options
context:
space:
mode:
authorSourabh Sourabh <sourabh.sourabh@est.tech>2023-01-16 08:40:23 +0000
committerGerrit Code Review <gerrit@onap.org>2023-01-16 08:40:23 +0000
commitecfce9d3e46410e1158c0f640fa833c101c4bda4 (patch)
tree8642f87d0c5b8961e847deab5f57d67cfc69c182 /cps-ri/src/test
parentef2b1518cf984f34b0640eb16ed44b26c9192efe (diff)
parent9c56b3032222b57549aa17dd281e4794fd9e25b6 (diff)
Merge "Fetch CM handles by collection of xpaths"
Diffstat (limited to 'cps-ri/src/test')
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceQueryDataNodeSpec.groovy31
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy22
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/performance/CpsDataPersistenceServicePerfTest.groovy30
3 files changed, 63 insertions, 20 deletions
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceQueryDataNodeSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceQueryDataNodeSpec.groovy
index 56e388335e..b6d2c5d65e 100644
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceQueryDataNodeSpec.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceQueryDataNodeSpec.groovy
@@ -26,6 +26,8 @@ import org.onap.cps.spi.exceptions.CpsPathException
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.jdbc.Sql
+import java.util.stream.Collectors
+
import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS
import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS
@@ -147,27 +149,30 @@ class CpsDataPersistenceQueryDataNodeSpec extends CpsPersistenceSpecBase {
def result = objectUnderTest.queryDataNodes(DATASPACE_NAME, ANCHOR_FOR_SHOP_EXAMPLE, cpsPath, INCLUDE_ALL_DESCENDANTS)
then: 'the xpaths of the retrieved data nodes are as expected'
result.size() == expectedXPaths.size()
- for (int i = 0; i < result.size(); i++) {
- assert result[i].getXpath() == expectedXPaths[i]
- assert result[i].childDataNodes.size() == expectedNumberOfChildren[i]
+ if (result.size() > 0) {
+ def resultXpaths = result.stream().map(it -> it.xpath).collect(Collectors.toSet())
+ resultXpaths.containsAll(expectedXPaths)
+ result.each {
+ assert it.childDataNodes.size() == expectedNumberOfChildren
+ }
}
where: 'the following data is used'
scenario | cpsPath || expectedXPaths || expectedNumberOfChildren
- 'multiple list-ancestors' | '//book/ancestor::categories' || ["/shops/shop[@id='1']/categories[@code='1']", "/shops/shop[@id='1']/categories[@code='2']"] || [1, 1]
- 'one ancestor with list value' | '//book/ancestor::categories[@code=1]' || ["/shops/shop[@id='1']/categories[@code='1']"] || [1]
- 'top ancestor' | '//shop[@id=1]/ancestor::shops' || ['/shops'] || [5]
- 'list with index value in the xpath prefix' | '//categories[@code=1]/book/ancestor::shop[@id=1]' || ["/shops/shop[@id='1']"] || [3]
- 'ancestor with parent list' | '//book/ancestor::shop[@id=1]/categories[@code=2]' || ["/shops/shop[@id='1']/categories[@code='2']"] || [1]
- 'ancestor with parent' | '//phonenumbers[@type="mob"]/ancestor::info/contact' || ["/shops/shop[@id='3']/info/contact"] || [3]
- 'ancestor combined with text condition' | '//book/title[text()="Dune"]/ancestor::shop' || ["/shops/shop[@id='1']"] || [3]
- 'ancestor with parent that does not exist' | '//book/ancestor::parentDoesNoExist/categories' || [] || []
- 'ancestor does not exist' | '//book/ancestor::ancestorDoesNotExist' || [] || []
+ 'multiple list-ancestors' | '//book/ancestor::categories' || ["/shops/shop[@id='1']/categories[@code='2']", "/shops/shop[@id='1']/categories[@code='1']"] || 1
+ 'one ancestor with list value' | '//book/ancestor::categories[@code=1]' || ["/shops/shop[@id='1']/categories[@code='1']"] || 1
+ 'top ancestor' | '//shop[@id=1]/ancestor::shops' || ['/shops'] || 5
+ 'list with index value in the xpath prefix' | '//categories[@code=1]/book/ancestor::shop[@id=1]' || ["/shops/shop[@id='1']"] || 3
+ 'ancestor with parent list' | '//book/ancestor::shop[@id=1]/categories[@code=2]' || ["/shops/shop[@id='1']/categories[@code='2']"] || 1
+ 'ancestor with parent' | '//phonenumbers[@type="mob"]/ancestor::info/contact' || ["/shops/shop[@id='3']/info/contact"] || 3
+ 'ancestor combined with text condition' | '//book/title[text()="Dune"]/ancestor::shop' || ["/shops/shop[@id='1']"] || 3
+ 'ancestor with parent that does not exist' | '//book/ancestor::parentDoesNoExist/categories' || [] || null
+ 'ancestor does not exist' | '//book/ancestor::ancestorDoesNotExist' || [] || null
}
def 'Cps Path query with syntax error throws a CPS Path Exception.'() {
when: 'trying to execute a query with a syntax (parsing) error'
objectUnderTest.queryDataNodes(DATASPACE_NAME, ANCHOR_FOR_SHOP_EXAMPLE, 'cpsPath that cannot be parsed' , OMIT_DESCENDANTS)
- then: 'exception is thrown'
+ then: 'a cps path exception is thrown'
thrown(CpsPathException)
}
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy
index 8234d32a8e..01c1dc70ec 100644
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy
@@ -107,7 +107,6 @@ class CpsDataPersistenceServiceSpec extends Specification {
assert thrown.details.contains('/node3')
}
-
def 'Retrieving a data node with a property JSON value of #scenario'() {
given: 'the db has a fragment with an attribute property JSON value of #scenario'
mockFragmentWithJson("{\"some attribute\": ${dataString}}")
@@ -142,6 +141,20 @@ class CpsDataPersistenceServiceSpec extends Specification {
thrown(DataValidationException)
}
+ def 'Retrieving multiple data nodes.'() {
+ given: 'db contains an anchor'
+ def anchorEntity = new AnchorEntity(id:123)
+ mockAnchorRepository.getByDataspaceAndName(*_) >> anchorEntity
+ and: 'fragment repository returns a collection of fragments'
+ def fragmentEntity1 = new FragmentEntity(xpath: 'xpath1', childFragments: [])
+ def fragmentEntity2 = new FragmentEntity(xpath: 'xpath2', childFragments: [])
+ mockFragmentRepository.findByAnchorAndMultipleCpsPaths(123, ['xpath1','xpath2']) >> [ fragmentEntity1, fragmentEntity2 ]
+ when: 'getting data nodes for 2 xpaths'
+ def result = objectUnderTest.getDataNodes('some-dataspace', 'some-anchor', ['xpath1','xpath2'],FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS)
+ then: '2 data nodes are returned'
+ assert result.size() == 2
+ }
+
def 'start session'() {
when: 'start session'
objectUnderTest.startSession()
@@ -227,11 +240,8 @@ class CpsDataPersistenceServiceSpec extends Specification {
}
def mockFragmentWithJson(json) {
- def anchorName = 'some anchor'
- def mockAnchor = Mock(AnchorEntity)
- mockAnchor.getId() >> 123
- mockAnchor.getName() >> anchorName
- mockAnchorRepository.getByDataspaceAndName(*_) >> mockAnchor
+ def anchorEntity = new AnchorEntity(id:123)
+ mockAnchorRepository.getByDataspaceAndName(*_) >> anchorEntity
def mockFragmentExtract = Mock(FragmentExtract)
mockFragmentExtract.getId() >> 456
mockFragmentExtract.getAttributes() >> json
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/performance/CpsDataPersistenceServicePerfTest.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/performance/CpsDataPersistenceServicePerfTest.groovy
index 910d8a4601..45cdb4d075 100644
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/performance/CpsDataPersistenceServicePerfTest.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/performance/CpsDataPersistenceServicePerfTest.groovy
@@ -25,6 +25,9 @@ import org.onap.cps.spi.CpsDataPersistenceService
import org.onap.cps.spi.impl.CpsPersistenceSpecBase
import org.onap.cps.spi.model.DataNode
import org.onap.cps.spi.model.DataNodeBuilder
+import org.onap.cps.spi.repository.AnchorRepository
+import org.onap.cps.spi.repository.DataspaceRepository
+import org.onap.cps.spi.repository.FragmentRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.jdbc.Sql
@@ -40,6 +43,15 @@ class CpsDataPersistenceServicePerfTest extends CpsPersistenceSpecBase {
@Autowired
CpsDataPersistenceService objectUnderTest
+ @Autowired
+ DataspaceRepository dataspaceRepository
+
+ @Autowired
+ AnchorRepository anchorRepository
+
+ @Autowired
+ FragmentRepository fragmentRepository
+
static def PERF_TEST_PARENT = '/perf-parent-1'
static def NUMBER_OF_CHILDREN = 200
static def NUMBER_OF_GRAND_CHILDREN = 50
@@ -48,6 +60,8 @@ class CpsDataPersistenceServicePerfTest extends CpsPersistenceSpecBase {
static def ALLOWED_READ_TIME_AL_NODES_MS = 500
def stopWatch = new StopWatch()
+ def readStopWatch = new StopWatch()
+ static def xpathsToAllGrandChildren = []
@Sql([CLEAR_DATA, PERF_TEST_DATA])
def 'Create a node with many descendants (please note, subsequent tests depend on this running first).'() {
@@ -88,6 +102,19 @@ class CpsDataPersistenceServicePerfTest extends CpsPersistenceSpecBase {
assert countDataNodes(result) == TOTAL_NUMBER_OF_NODES
}
+ def 'Performance of finding multiple xpaths'() {
+ when: 'we query for all grandchildren (except 1 for fun) with the new native method'
+ xpathsToAllGrandChildren.remove(0)
+ readStopWatch.start()
+ def result = objectUnderTest.getDataNodes('PERF-DATASPACE', 'PERF-ANCHOR', xpathsToAllGrandChildren, INCLUDE_ALL_DESCENDANTS)
+ readStopWatch.stop()
+ def readDurationInMillis = readStopWatch.getTotalTimeMillis()
+ then: 'the returned number of entities equal to the number of children * number of grandchildren'
+ assert result.size() == xpathsToAllGrandChildren.size()
+ and: 'it took less then 4000ms'
+ assert readDurationInMillis < 4000
+ }
+
def 'Query many descendants by cps-path with #scenario'() {
when: 'query is executed with all descendants'
stopWatch.start()
@@ -107,7 +134,7 @@ class CpsDataPersistenceServicePerfTest extends CpsPersistenceSpecBase {
def 'Delete 50 grandchildren (that have no descendants)'() {
when: 'target nodes are deleted'
stopWatch.start()
- (1..50).each {
+ (1..NUMBER_OF_GRAND_CHILDREN).each {
def grandchildPath = "${PERF_TEST_PARENT}/perf-test-child-1/perf-test-grand-child-${it}".toString();
objectUnderTest.deleteDataNode('PERF-DATASPACE', 'PERF-ANCHOR', grandchildPath)
}
@@ -152,6 +179,7 @@ class CpsDataPersistenceServicePerfTest extends CpsPersistenceSpecBase {
def grandChildren = []
(1..NUMBER_OF_GRAND_CHILDREN).each {
def grandChild = new DataNodeBuilder().withXpath("${parentXpath}/${childName}/perf-test-grand-child-${it}").build()
+ xpathsToAllGrandChildren.add(grandChild.xpath)
grandChildren.add(grandChild)
}
return new DataNodeBuilder().withXpath("${parentXpath}/${childName}").withChildDataNodes(grandChildren).build()