Move integration test (DataService)
- 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
diff --git a/cps-ri/pom.xml b/cps-ri/pom.xml
index 3162aa8..3ef57cf 100644
--- a/cps-ri/pom.xml
+++ b/cps-ri/pom.xml
@@ -33,7 +33,8 @@
<artifactId>cps-ri</artifactId>
<properties>
- <minimum-coverage>0.79</minimum-coverage>
+ <minimum-coverage>0.45</minimum-coverage>
+ <!-- Coverage is provided by integration-test module instead -->
</properties>
<dependencies>
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
index 3d2b87d..d0154e1 100644
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
@@ -87,13 +87,6 @@
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) {
final AnchorEntity anchorEntity = getAnchorEntity(dataspaceName, anchorName);
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
old mode 100755
new mode 100644
index 080e348..6d6dfd2
--- 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
@@ -562,7 +562,7 @@
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'
diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
index 4fb25e9..9674bbe 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java
@@ -44,15 +44,6 @@
*/
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.
diff --git a/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy b/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy
index e721414..bf86e13 100644
--- a/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy
+++ b/integration-test/src/test/groovy/org/onap/cps/integration/functional/CpsDataServiceIntegrationSpec.groovy
@@ -30,11 +30,17 @@
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 @@
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 @@
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.'() {
diff --git a/integration-test/src/test/resources/data/bookstore/bookstore.yang b/integration-test/src/test/resources/data/bookstore/bookstore.yang
index 62ebc73..f3219a0 100644
--- a/integration-test/src/test/resources/data/bookstore/bookstore.yang
+++ b/integration-test/src/test/resources/data/bookstore/bookstore.yang
@@ -21,6 +21,15 @@
type string;
}
+ container webinfo {
+ leaf domain-name {
+ type string;
+ }
+ leaf contact-email {
+ type string;
+ }
+ }
+
container premises {
list addresses {
key "house-number street";