Revert "Omit descendants when not need in ncmp inventory queries"
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / CpsPersistenceSpec.groovy
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2023 Nordix Foundation
4  *  Modifications Copyright (C) 2023 TechMahindra Ltd.
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the 'License');
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an 'AS IS' BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.onap.cps.integration
23
24 import org.onap.cps.spi.FetchDescendantsOption
25
26 class CpsPersistenceSpec extends CpsIntegrationSpecBase{
27
28     def 'Test creation of test data'() {
29         when: 'A dataspace, schema set and anchor are persisted'
30             createDataspaceSchemaSetAnchor(TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'bookstore.yang', TEST_ANCHOR)
31         and: 'data nodes are persisted under the created anchor'
32             saveDataNodes(TEST_DATASPACE, TEST_ANCHOR, '/', 'BookstoreDataNodes.json')
33         then: 'The dataspace has been persisted successfully'
34             cpsAdminService.getDataspace(TEST_DATASPACE).getName() == TEST_DATASPACE
35         and: 'The schema set has been persisted successfully'
36             cpsModuleService.getSchemaSet(TEST_DATASPACE, BOOKSTORE_SCHEMA_SET).getName() == BOOKSTORE_SCHEMA_SET
37         and: 'The anchor has been persisted successfully'
38             cpsAdminService.getAnchor(TEST_DATASPACE, TEST_ANCHOR).getName() == TEST_ANCHOR
39         and: 'The data nodes have been persisted successfully'
40             cpsDataService.getDataNodes(TEST_DATASPACE, TEST_ANCHOR, '/bookstore', FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS).iterator().next().xpath == '/bookstore'
41     }
42
43     def 'Test deletion of all test data'() {
44         when: 'delete all from test dataspace method is called'
45             deleteAllFromTestDataspace()
46         and: 'the test dataspace is deleted'
47             cpsAdminService.deleteDataspace(TEST_DATASPACE)
48         then: 'there is no test dataspace'
49             !cpsAdminService.getAllDataspaces().contains(TEST_DATASPACE)
50     }
51
52     def 'Read test for persisted data nodes'() {
53         given:'There is a test dataspace created'
54             cpsAdminService.createDataspace(TEST_DATASPACE)
55         and: 'There is a schema set and anchor for the test dataspace'
56             createSchemaSetAnchor(TEST_DATASPACE, 'bookstoreSchemaSet', 'bookstore.yang', TEST_ANCHOR)
57         when: 'data is persisted to the database'
58             saveDataNodes(TEST_DATASPACE, TEST_ANCHOR, "/", "BookstoreDataNodes.json")
59         then: 'the correct data is saved'
60             cpsDataService.getDataNodes(TEST_DATASPACE, TEST_ANCHOR, '/bookstore', FetchDescendantsOption.OMIT_DESCENDANTS).iterator().next().leaves['bookstore-name'] == 'Easons'
61     }
62 }