Merge "Migrate query tests to integration-test module #1"
authorToine Siebelink <toine.siebelink@est.tech>
Tue, 11 Apr 2023 16:29:28 +0000 (16:29 +0000)
committerGerrit Code Review <gerrit@onap.org>
Tue, 11 Apr 2023 16:29:28 +0000 (16:29 +0000)
cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java
integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy

index aa631d1..369e528 100644 (file)
@@ -458,6 +458,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
         return new DataNodeBuilder()
                 .withXpath(fragmentEntity.getXpath())
                 .withLeaves(leaves)
+                .withDataspace(fragmentEntity.getAnchor().getDataspace().getName())
                 .withAnchor(fragmentEntity.getAnchor().getName())
                 .withChildDataNodes(childDataNodes).build();
     }
index 6fc36eb..e212933 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2021 Bell Canada. All rights reserved.
  *  Modifications Copyright (C) 2021 Pantheon.tech
- *  Modifications Copyright (C) 2022 Nordix Foundation.
+ *  Modifications Copyright (C) 2022-2023 Nordix Foundation.
  *  Modifications Copyright (C) 2022-2023 TechMahindra Ltd.
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
@@ -54,6 +54,7 @@ public class DataNodeBuilder {
     private String parentNodeXpath = "";
     private Map<String, Serializable> leaves = Collections.emptyMap();
     private Collection<DataNode> childDataNodes = Collections.emptySet();
+    private String dataspaceName;
     private String anchorName;
 
     /**
@@ -89,6 +90,17 @@ public class DataNodeBuilder {
         return this;
     }
 
+    /**
+     * To use dataspace name for creating {@link DataNode}.
+     *
+     * @param dataspaceName dataspace name for the data node
+     * @return DataNodeBuilder
+     */
+    public DataNodeBuilder withDataspace(final String dataspaceName) {
+        this.dataspaceName = dataspaceName;
+        return this;
+    }
+
     /**
      * To use anchor name for creating {@link DataNode}.
      *
@@ -165,6 +177,7 @@ public class DataNodeBuilder {
         dataNode.setModuleNamePrefix(moduleNamePrefix);
         dataNode.setLeaves(leaves);
         dataNode.setChildDataNodes(childDataNodes);
+        dataNode.setDataspace(dataspaceName);
         dataNode.setAnchorName(anchorName);
         return dataNode;
     }
index c333911..ddf8dcf 100644 (file)
 
 package org.onap.cps.integration.functional
 
+import org.onap.cps.api.CpsDataService
 import org.onap.cps.integration.base.FunctionalSpecBase
 import org.onap.cps.spi.FetchDescendantsOption
 
 class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
 
-    def objectUnderTest
+    CpsDataService objectUnderTest
 
     def setup() { objectUnderTest = cpsDataService }
 
@@ -44,4 +45,14 @@ class CpsDataServiceIntegrationSpec extends FunctionalSpecBase {
             FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS || 8
             new FetchDescendantsOption(2)                  || 8
     }
+
+    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, BOOKSTORE_ANCHOR, '/bookstore', FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS)
+        then: 'the correct dataspace was queried'
+            assert result.dataspace.toSet() == [FUNCTIONAL_TEST_DATASPACE].toSet()
+        and: 'the correct anchor was queried'
+            assert result.anchorName.toSet() == [BOOKSTORE_ANCHOR].toSet()
+    }
+
 }