d504a9e0dd8fd75309046884d43c34957df15384
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / functional / CpsAdminServiceIntegrationSpec.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.functional
22
23 import org.onap.cps.integration.base.CpsIntegrationSpecBase
24 import org.onap.cps.spi.exceptions.AlreadyDefinedException
25 import org.onap.cps.spi.exceptions.AnchorNotFoundException
26 import org.onap.cps.spi.exceptions.DataspaceNotFoundException
27
28 class CpsAdminServiceIntegrationSpec extends CpsIntegrationSpecBase {
29
30     def objectUnderTest
31
32     def setup() { objectUnderTest = cpsAdminService }
33
34     def 'Dataspace CRUD operations.'() {
35         when: 'a dataspace is created'
36             objectUnderTest.createDataspace('newDataspace')
37         then: 'the dataspace can be read'
38             assert objectUnderTest.getDataspace('newDataspace').name == 'newDataspace'
39         and: 'it can be deleted'
40             objectUnderTest.deleteDataspace('newDataspace')
41         then: 'the dataspace no longer exists i.e. an exception is thrown if an attempt is made to retrieve it'
42             def thrown = null
43             try {
44                 objectUnderTest.getDataspace('newDataspace')
45             } catch(Exception e) {
46                 thrown = e
47             }
48            assert thrown instanceof DataspaceNotFoundException
49     }
50
51     def 'Retrieve all dataspaces (depends on total test suite).'() {
52         given: 'two addtional dataspaces are created'
53             objectUnderTest.createDataspace('dataspace1')
54             objectUnderTest.createDataspace('dataspace2')
55         when: 'all datespaces are retreived'
56             def result = objectUnderTest.getAllDataspaces()
57         then: 'there are at least 3 dataspaces (2 new ones plus the general test dataspace)'
58             result.size() >= 3
59             assert result.name.containsAll([GENERAL_TEST_DATASPACE, 'dataspace1', 'dataspace2'])
60     }
61
62     def 'Duplicate dataspaces.'() {
63         when: 'attempting to create a dataspace with the same name as an existing one'
64             objectUnderTest.createDataspace(GENERAL_TEST_DATASPACE)
65         then: 'an exception is thrown indicating the dataspace already exists'
66             thrown(AlreadyDefinedException)
67     }
68
69     def 'Anchor CRUD operations.'() {
70         when: 'a anchor is created'
71             objectUnderTest.createAnchor(GENERAL_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'newAnchor')
72         then: 'the anchor be read'
73             assert objectUnderTest.getAnchor(GENERAL_TEST_DATASPACE, 'newAnchor').name == 'newAnchor'
74         and: 'it can be deleted'
75             objectUnderTest.deleteAnchor(GENERAL_TEST_DATASPACE,'newAnchor')
76         then: 'the anchor no longer exists i.e. an exception is thrown if an attempt is made to retrieve it'
77             def thrown = null
78             try {
79                 objectUnderTest.getAnchor(GENERAL_TEST_DATASPACE, 'newAnchor')
80             } catch(Exception e) {
81                 thrown = e
82             }
83             assert thrown instanceof AnchorNotFoundException
84     }
85
86     def 'Filtering multiple anchors.'() {
87         when: '2 anchors with bookstore schema set are created'
88             objectUnderTest.createAnchor(GENERAL_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'anchor1')
89             objectUnderTest.createAnchor(GENERAL_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'anchor2')
90         and: '1 anchor with "other" schema set is created'
91             def bookstoreModelFileContent = readResourceFile('bookstore.yang')
92             cpsModuleService.createSchemaSet(GENERAL_TEST_DATASPACE, 'otherSchemaSet', [someFileName: bookstoreModelFileContent])
93             objectUnderTest.createAnchor(GENERAL_TEST_DATASPACE, 'otherSchemaSet', 'anchor3')
94         then: 'there are 3 anchors in the general test database'
95             assert objectUnderTest.getAnchors(GENERAL_TEST_DATASPACE).size() == 3
96         and: 'there are 2 anchors associated with bookstore schema set'
97             assert objectUnderTest.getAnchors(GENERAL_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET).size() == 2
98         and: 'there is 1 anchor associated with other schema set'
99             assert objectUnderTest.getAnchors(GENERAL_TEST_DATASPACE, 'otherSchemaSet').size() == 1
100     }
101
102     def 'Querying anchor(name)s (depends on previous test!).'() {
103         expect: 'there are now 3 anchors using the "stores" module (both schema sets use the same modules) '
104             assert objectUnderTest.queryAnchorNames(GENERAL_TEST_DATASPACE, ['stores']).size() == 3
105         and: 'there are no anchors using both "stores" and a "unused-model"'
106             assert objectUnderTest.queryAnchorNames(GENERAL_TEST_DATASPACE, ['stores', 'unused-model']).size() == 0
107     }
108
109 }