Move integration test (DataService) 05/134505/2
authorToineSiebelink <toine.siebelink@est.tech>
Mon, 8 May 2023 16:07:54 +0000 (17:07 +0100)
committerToine Siebelink <toine.siebelink@est.tech>
Wed, 10 May 2023 12:38:57 +0000 (12:38 +0000)
- dropped ri module coverage to alow for move
- removed performance tests (already better tests in intergration module)
- added 'save' iue cases in new integration-test
- removed no longer used version for save single data node
(todo: remove old tests for similar functionality, will wait until new test cover same)

Issue-ID: CPS-1687
Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
Change-Id: I4c2e788e0a313938a923cd1e7e52584d739ec6f4

cps-ri/pom.xml
cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy [changed mode: 0755->0644]
cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy
integration-test/src/test/resources/data/bookstore/bookstore.yang

index 3162aa8..3ef57cf 100644 (file)
@@ -33,7 +33,8 @@
     <artifactId>cps-ri</artifactId>\r
 \r
     <properties>\r
-        <minimum-coverage>0.79</minimum-coverage>\r
+        <minimum-coverage>0.45</minimum-coverage>\r
+        <!-- Coverage is provided by integration-test module instead -->\r
     </properties>\r
 \r
     <dependencies>\r
index 3d2b87d..d0154e1 100644 (file)
@@ -86,13 +86,6 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
     private static final String QUERY_ACROSS_ANCHORS = null;
     private static final AnchorEntity ALL_ANCHORS = null;
 
-    @Override
-    public void addChildDataNode(final String dataspaceName, final String anchorName, final String parentNodeXpath,
-                                 final DataNode newChildDataNode) {
-        final AnchorEntity anchorEntity = getAnchorEntity(dataspaceName, anchorName);
-        addNewChildDataNode(anchorEntity, parentNodeXpath, newChildDataNode);
-    }
-
     @Override
     public void addChildDataNodes(final String dataspaceName, final String anchorName,
                                   final String parentNodeXpath, final Collection<DataNode> dataNodes) {
old mode 100755 (executable)
new mode 100644 (file)
index 080e348..6d6dfd2
@@ -562,7 +562,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
         given: 'a data nodes with list-element child with "/" in index value (and grandchild)'
             def grandChild = new DataNodeBuilder().withXpath(deleteTestGrandChildXPath).build()
             def child = new DataNodeBuilder().withXpath(deleteTestChildXpath).withChildDataNodes([grandChild]).build()
-            objectUnderTest.addChildDataNode(DATASPACE_NAME, ANCHOR_NAME3, deleteTestParentXPath, child)
+            objectUnderTest.addChildDataNodes(DATASPACE_NAME, ANCHOR_NAME3, deleteTestParentXPath, [child])
         and: 'number of children before delete is stored'
             def numberOfChildrenBeforeDelete = objectUnderTest.getDataNodes(DATASPACE_NAME, ANCHOR_NAME3, pathToParentOfDeletedNode, INCLUDE_ALL_DESCENDANTS)[0].childDataNodes.size()
         when: 'target node is deleted'
index 4fb25e9..9674bbe 100644 (file)
@@ -44,15 +44,6 @@ public interface CpsDataPersistenceService {
      */
     void storeDataNodes(String dataspaceName, String anchorName, Collection<DataNode> dataNodes);
 
-    /**
-     * Add a child to a Fragment.
-     *
-     * @param dataspaceName dataspace name
-     * @param anchorName    anchor name
-     * @param parentXpath   parent xpath
-     * @param dataNode      dataNode
-     */
-    void addChildDataNode(String dataspaceName, String anchorName, String parentXpath, DataNode dataNode);
 
     /**
      * Add multiple children to a Fragment.
index e721414..bf86e13 100644 (file)
@@ -30,11 +30,17 @@ import org.onap.cps.spi.exceptions.DataspaceNotFoundException
 
 import java.time.OffsetDateTime
 
+import java.time.OffsetDateTime
+
 class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
 
     CpsDataService objectUnderTest
+    def originalCountBookstoreChildNodes
 
-    def setup() { objectUnderTest = cpsDataService }
+    def setup() {
+        objectUnderTest = cpsDataService
+        originalCountBookstoreChildNodes = countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', FetchDescendantsOption.DIRECT_CHILDREN_ONLY))
+    }
 
     def 'Read bookstore top-level container(s) using #fetchDescendantsOption.'() {
         when: 'get data nodes for bookstore container'
@@ -43,6 +49,10 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
             assert countDataNodesInTree(result) == expectNumberOfDataNodes
         and: 'the top level data node has the expected attribute and value'
             assert result.leaves['bookstore-name'] == ['Easons']
+        and: 'they are from the correct dataspace'
+            assert result.dataspace == [FUNCTIONAL_TEST_DATASPACE_1]
+        and: 'they are from the correct anchor'
+            assert result.anchorName == [BOOKSTORE_ANCHOR_1]
         where: 'the following option is used'
             fetchDescendantsOption                         || expectNumberOfDataNodes
             FetchDescendantsOption.OMIT_DESCENDANTS        || 1
@@ -51,13 +61,56 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
             new FetchDescendantsOption(2)                  || 17
     }
 
-    def 'Read bookstore top-level container(s) has correct dataspace and anchor.'() {
-        when: 'get data nodes for bookstore container'
-            def result = objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS)
-        then: 'the correct dataspace was queried'
-            assert result.dataspace.toSet() == [FUNCTIONAL_TEST_DATASPACE_1].toSet()
-        and: 'the correct anchor was queried'
-            assert result.anchorName.toSet() == [BOOKSTORE_ANCHOR_1].toSet()
+    def 'Add and Delete a (container) datanode.'() {
+        given: 'new (webinfo) datanode'
+            def json = '{"webinfo": {"domain-name":"ourbookstore.com" ,"contact-email":"info@ourbookstore.com" }}'
+        when: 'the new datanode is saved'
+            objectUnderTest.saveData(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore', json, OffsetDateTime.now())
+        then: 'it can be retrieved by its xpath'
+            def result = objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/webinfo', FetchDescendantsOption.DIRECT_CHILDREN_ONLY)
+            assert result.size() == 1
+            assert result[0].xpath == '/bookstore/webinfo'
+        and: 'there is now one extra datanode'
+            assert originalCountBookstoreChildNodes + 1 == countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', FetchDescendantsOption.DIRECT_CHILDREN_ONLY))
+        when: 'the new datanode is deleted'
+            objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/webinfo', OffsetDateTime.now())
+        then: 'the original number of datanodes is restored'
+            assert originalCountBookstoreChildNodes == countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', FetchDescendantsOption.DIRECT_CHILDREN_ONLY))
+    }
+
+    def 'Add and Delete list (element) datanodes.'() {
+        given: 'two new (categories) datanodes'
+            def json = '{"categories": [ {"code":"new1"}, {"code":"new2" } ] }'
+        when: 'the new list elements are saved'
+            objectUnderTest.saveListElements(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore', json, OffsetDateTime.now())
+        then: 'they can be retrieved by their xpaths'
+            objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new1"]', FetchDescendantsOption.DIRECT_CHILDREN_ONLY).size() == 1
+            objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new2"]', FetchDescendantsOption.DIRECT_CHILDREN_ONLY).size() == 1
+        and: 'there are now two extra datanodes'
+            assert originalCountBookstoreChildNodes + 2 == countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', FetchDescendantsOption.DIRECT_CHILDREN_ONLY))
+        when: 'the new elements are deleted'
+            objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new1"]', OffsetDateTime.now())
+            objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new2"]', OffsetDateTime.now())
+        then: 'the original number of datanodes is restored'
+            assert originalCountBookstoreChildNodes == countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', FetchDescendantsOption.DIRECT_CHILDREN_ONLY))
+    }
+
+    def 'Add and Delete a batch of lists (element) datanodes.'() {
+        given: 'two new (categories) datanodes in two separate batches'
+            def json1 = '{"categories": [ {"code":"new1"} ] }'
+            def json2 = '{"categories": [ {"code":"new2"} ] }'
+        when: 'the batches of new list element(s) are saved'
+            objectUnderTest.saveListElementsBatch(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1 , '/bookstore', [json1, json2], OffsetDateTime.now())
+        then: 'they can be retrieved by their xpaths'
+            objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new1"]', FetchDescendantsOption.DIRECT_CHILDREN_ONLY).size() == 1
+            objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new2"]', FetchDescendantsOption.DIRECT_CHILDREN_ONLY).size() == 1
+        and: 'there are now two extra datanodes'
+            assert originalCountBookstoreChildNodes + 2 == countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', FetchDescendantsOption.DIRECT_CHILDREN_ONLY))
+        when: 'the new elements are deleted'
+            objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new1"]', OffsetDateTime.now())
+            objectUnderTest.deleteDataNode(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore/categories[@code="new2"]', OffsetDateTime.now())
+        then: 'the original number of datanodes is restored'
+            assert originalCountBookstoreChildNodes == countDataNodesInTree(objectUnderTest.getDataNodes(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_ANCHOR_1, '/bookstore', FetchDescendantsOption.DIRECT_CHILDREN_ONLY))
     }
 
     def 'Update multiple data node leaves.'() {
index 62ebc73..f3219a0 100644 (file)
@@ -21,6 +21,15 @@ module stores {
             type string;
         }
 
+        container webinfo {
+            leaf domain-name {
+                type string;
+            }
+            leaf contact-email {
+                type string;
+            }
+        }
+
         container premises {
             list addresses {
                 key "house-number street";