Fetch CM handles by collection of xpaths
[cps.git] / cps-ri / src / test / groovy / org / onap / cps / spi / impl / CpsDataPersistenceServiceSpec.groovy
index 255e8e5..30d438c 100644 (file)
@@ -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()
@@ -208,11 +221,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