Move integration test (DataService)
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / base / FunctionalSpecBase.groovy
1 /*
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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 package org.onap.cps.integration.base
22
23 import java.time.OffsetDateTime
24
25 class FunctionalSpecBase extends CpsIntegrationSpecBase {
26
27     def static FUNCTIONAL_TEST_DATASPACE_1 = 'functionalTestDataspace1'
28     def static FUNCTIONAL_TEST_DATASPACE_2 = 'functionalTestDataspace2'
29     def static NUMBER_OF_ANCHORS_PER_DATASPACE_WITH_BOOKSTORE_DATA = 2
30     def static BOOKSTORE_ANCHOR_1 = 'bookstoreAnchor1'
31     def static BOOKSTORE_ANCHOR_2 = 'bookstoreAnchor2'
32
33     def static initialized = false
34     def static bookstoreJsonData = readResourceDataFile('bookstore/bookstoreData.json')
35
36     def setup() {
37         if (!initialized) {
38             setupBookstoreInfraStructure()
39             addBookstoreData()
40             initialized = true
41         }
42     }
43
44     def setupBookstoreInfraStructure() {
45         cpsAdminService.createDataspace(FUNCTIONAL_TEST_DATASPACE_1)
46         cpsAdminService.createDataspace(FUNCTIONAL_TEST_DATASPACE_2)
47         def bookstoreYangModelAsString = readResourceDataFile('bookstore/bookstore.yang')
48         cpsModuleService.createSchemaSet(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_SCHEMA_SET, [bookstore: bookstoreYangModelAsString])
49         cpsModuleService.createSchemaSet(FUNCTIONAL_TEST_DATASPACE_2, BOOKSTORE_SCHEMA_SET, [bookstore: bookstoreYangModelAsString])
50     }
51
52     def addBookstoreData() {
53         addAnchorsWithData(NUMBER_OF_ANCHORS_PER_DATASPACE_WITH_BOOKSTORE_DATA, FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_SCHEMA_SET, 'bookstoreAnchor', bookstoreJsonData)
54         addAnchorsWithData(NUMBER_OF_ANCHORS_PER_DATASPACE_WITH_BOOKSTORE_DATA, FUNCTIONAL_TEST_DATASPACE_2, BOOKSTORE_SCHEMA_SET, 'bookstoreAnchor', bookstoreJsonData)
55     }
56
57     def restoreBookstoreDataAnchor(anchorNumber) {
58         def anchorName = 'bookstoreAnchor' + anchorNumber
59         cpsAdminService.deleteAnchor(FUNCTIONAL_TEST_DATASPACE_1, anchorName)
60         cpsAdminService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_SCHEMA_SET, anchorName)
61         cpsDataService.saveData(FUNCTIONAL_TEST_DATASPACE_1, anchorName, bookstoreJsonData, OffsetDateTime.now())
62     }
63
64 }