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