2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023-2024 Nordix Foundation
4 * Modifications Copyright (C) 2022-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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.cps.integration.base
24 import java.time.OffsetDateTime
26 class FunctionalSpecBase extends CpsIntegrationSpecBase {
28 def static FUNCTIONAL_TEST_DATASPACE_1 = 'functionalTestDataspace1'
29 def static FUNCTIONAL_TEST_DATASPACE_2 = 'functionalTestDataspace2'
30 def static FUNCTIONAL_TEST_DATASPACE_3 = 'functionalTestDataspace3'
31 def static NUMBER_OF_ANCHORS_PER_DATASPACE_WITH_BOOKSTORE_DATA = 2
32 def static NUMBER_OF_ANCHORS_PER_DATASPACE_WITH_BOOKSTORE_DELTA_DATA = 1
33 def static BOOKSTORE_ANCHOR_1 = 'bookstoreAnchor1'
34 def static BOOKSTORE_ANCHOR_2 = 'bookstoreAnchor2'
35 def static BOOKSTORE_ANCHOR_3 = 'bookstoreSourceAnchor1'
36 def static BOOKSTORE_ANCHOR_4 = 'copyOfSourceAnchor1'
37 def static BOOKSTORE_ANCHOR_5 = 'bookstoreAnchorForDeltaReport1'
39 def static initialized = false
40 def static bookstoreJsonData = readResourceDataFile('bookstore/bookstoreData.json')
41 def static bookstoreJsonDataForDeltaReport = readResourceDataFile('bookstore/bookstoreDataForDeltaReport.json')
45 setupBookstoreInfraStructure()
52 def setupBookstoreInfraStructure() {
53 cpsDataspaceService.createDataspace(FUNCTIONAL_TEST_DATASPACE_1)
54 cpsDataspaceService.createDataspace(FUNCTIONAL_TEST_DATASPACE_2)
55 cpsDataspaceService.createDataspace(FUNCTIONAL_TEST_DATASPACE_3)
56 def bookstoreYangModelAsString = readResourceDataFile('bookstore/bookstore.yang')
57 cpsModuleService.createSchemaSet(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_SCHEMA_SET, [bookstore: bookstoreYangModelAsString])
58 cpsModuleService.createSchemaSet(FUNCTIONAL_TEST_DATASPACE_2, BOOKSTORE_SCHEMA_SET, [bookstore: bookstoreYangModelAsString])
59 cpsModuleService.createSchemaSet(FUNCTIONAL_TEST_DATASPACE_3, BOOKSTORE_SCHEMA_SET, [bookstore: bookstoreYangModelAsString])
63 def addBookstoreData() {
64 addAnchorsWithData(NUMBER_OF_ANCHORS_PER_DATASPACE_WITH_BOOKSTORE_DATA, FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_SCHEMA_SET, 'bookstoreAnchor', bookstoreJsonData)
65 addAnchorsWithData(NUMBER_OF_ANCHORS_PER_DATASPACE_WITH_BOOKSTORE_DATA, FUNCTIONAL_TEST_DATASPACE_2, BOOKSTORE_SCHEMA_SET, 'bookstoreAnchor', bookstoreJsonData)
69 addAnchorsWithData(NUMBER_OF_ANCHORS_PER_DATASPACE_WITH_BOOKSTORE_DELTA_DATA, FUNCTIONAL_TEST_DATASPACE_3, BOOKSTORE_SCHEMA_SET, 'bookstoreSourceAnchor', bookstoreJsonData)
70 addAnchorsWithData(NUMBER_OF_ANCHORS_PER_DATASPACE_WITH_BOOKSTORE_DELTA_DATA, FUNCTIONAL_TEST_DATASPACE_3, BOOKSTORE_SCHEMA_SET, 'copyOfSourceAnchor', bookstoreJsonData)
71 addAnchorsWithData(NUMBER_OF_ANCHORS_PER_DATASPACE_WITH_BOOKSTORE_DELTA_DATA, FUNCTIONAL_TEST_DATASPACE_3, BOOKSTORE_SCHEMA_SET, 'bookstoreAnchorForDeltaReport', bookstoreJsonDataForDeltaReport)
74 def restoreBookstoreDataAnchor(anchorNumber) {
75 def anchorName = 'bookstoreAnchor' + anchorNumber
76 cpsAnchorService.deleteAnchor(FUNCTIONAL_TEST_DATASPACE_1, anchorName)
77 cpsAnchorService.createAnchor(FUNCTIONAL_TEST_DATASPACE_1, BOOKSTORE_SCHEMA_SET, anchorName)
78 cpsDataService.saveData(FUNCTIONAL_TEST_DATASPACE_1, anchorName, bookstoreJsonData.replace('Easons', 'Easons-'+anchorNumber.toString()), OffsetDateTime.now())