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.functional
23 import org.onap.cps.api.CpsAdminService
24 import org.onap.cps.integration.base.CpsIntegrationSpecBase
25 import org.onap.cps.spi.exceptions.AlreadyDefinedException
26 import org.onap.cps.spi.exceptions.AnchorNotFoundException
27 import org.onap.cps.spi.exceptions.DataspaceInUseException
28 import org.onap.cps.spi.exceptions.DataspaceNotFoundException
30 class CpsAdminServiceIntegrationSpec extends CpsIntegrationSpecBase {
32 CpsAdminService objectUnderTest
34 def setup() { objectUnderTest = cpsAdminService }
36 def 'Dataspace CRUD operations.'() {
37 when: 'a dataspace is created'
38 objectUnderTest.createDataspace('newDataspace')
39 then: 'the dataspace can be read'
40 assert objectUnderTest.getDataspace('newDataspace').name == 'newDataspace'
41 and: 'it can be deleted'
42 objectUnderTest.deleteDataspace('newDataspace')
43 then: 'the dataspace no longer exists i.e. an exception is thrown if an attempt is made to retrieve it'
46 objectUnderTest.getDataspace('newDataspace')
47 } catch(Exception e) {
50 assert thrown instanceof DataspaceNotFoundException
53 def 'Delete dataspace with error; #scenario.'() {
54 setup: 'add some anchors if needed'
55 numberOfAnchors.times {
56 objectUnderTest.createAnchor(GENERAL_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'anchor' + it)
58 when: 'attempt to delete dataspace'
59 objectUnderTest.deleteDataspace(dataspaceName)
60 then: 'the correct exception is thrown with the relevant details'
61 def thrownException = thrown(expectedException)
62 thrownException.details.contains(expectedMessageDetails)
64 numberOfAnchors.times {
65 objectUnderTest.deleteAnchor(GENERAL_TEST_DATASPACE, 'anchor' + it)
67 where: 'the following data is used'
68 scenario | dataspaceName | numberOfAnchors || expectedException | expectedMessageDetails
69 'dataspace name does not exist' | 'unknown' | 0 || DataspaceNotFoundException | 'unknown does not exist'
70 'dataspace contains schemasets' | GENERAL_TEST_DATASPACE | 0 || DataspaceInUseException | 'contains 1 schemaset(s)'
71 'dataspace contains anchors' | GENERAL_TEST_DATASPACE | 2 || DataspaceInUseException | 'contains 2 anchor(s)'
74 def 'Retrieve all dataspaces (depends on total test suite).'() {
75 given: 'two addtional dataspaces are created'
76 objectUnderTest.createDataspace('dataspace1')
77 objectUnderTest.createDataspace('dataspace2')
78 when: 'all datespaces are retreived'
79 def result = objectUnderTest.getAllDataspaces()
80 then: 'there are at least 3 dataspaces (2 new ones plus the general test dataspace)'
82 assert result.name.containsAll([GENERAL_TEST_DATASPACE, 'dataspace1', 'dataspace2'])
85 def 'Duplicate dataspaces.'() {
86 when: 'attempting to create a dataspace with the same name as an existing one'
87 objectUnderTest.createDataspace(GENERAL_TEST_DATASPACE)
88 then: 'an exception is thrown indicating the dataspace already exists'
89 thrown(AlreadyDefinedException)
92 def 'Anchor CRUD operations.'() {
93 when: 'an anchor is created'
94 objectUnderTest.createAnchor(GENERAL_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'newAnchor')
95 then: 'the anchor be read'
96 assert objectUnderTest.getAnchor(GENERAL_TEST_DATASPACE, 'newAnchor').name == 'newAnchor'
97 and: 'it can be deleted'
98 objectUnderTest.deleteAnchor(GENERAL_TEST_DATASPACE,'newAnchor')
99 then: 'the anchor no longer exists i.e. an exception is thrown if an attempt is made to retrieve it'
102 objectUnderTest.getAnchor(GENERAL_TEST_DATASPACE, 'newAnchor')
103 } catch(Exception e) {
106 assert thrown instanceof AnchorNotFoundException
109 def 'Filtering multiple anchors.'() {
110 when: '2 anchors with bookstore schema set are created'
111 objectUnderTest.createAnchor(GENERAL_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'anchor1')
112 objectUnderTest.createAnchor(GENERAL_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'anchor2')
113 and: '1 anchor with "other" schema set is created'
114 def bookstoreModelFileContent = readResourceDataFile('bookstore/bookstore.yang')
115 cpsModuleService.createSchemaSet(GENERAL_TEST_DATASPACE, 'otherSchemaSet', [someFileName: bookstoreModelFileContent])
116 objectUnderTest.createAnchor(GENERAL_TEST_DATASPACE, 'otherSchemaSet', 'anchor3')
117 then: 'there are 3 anchors in the general test database'
118 assert objectUnderTest.getAnchors(GENERAL_TEST_DATASPACE).size() == 3
119 and: 'there are 2 anchors associated with bookstore schema set'
120 assert objectUnderTest.getAnchors(GENERAL_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET).size() == 2
121 and: 'there is 1 anchor associated with other schema set'
122 assert objectUnderTest.getAnchors(GENERAL_TEST_DATASPACE, 'otherSchemaSet').size() == 1
125 def 'Querying anchor(name)s (depends on previous test!).'() {
126 expect: 'there are now 3 anchors using the "stores" module (both schema sets use the same modules) '
127 assert objectUnderTest.queryAnchorNames(GENERAL_TEST_DATASPACE, ['stores']).size() == 3
128 and: 'there are no anchors using both "stores" and a "unused-model"'
129 assert objectUnderTest.queryAnchorNames(GENERAL_TEST_DATASPACE, ['stores', 'unused-model']).size() == 0
132 def 'Duplicate anchors.'() {
133 given: 'an anchor is created'
134 objectUnderTest.createAnchor(GENERAL_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'newAnchor')
135 when: 'attempt to create another anchor with the same name'
136 objectUnderTest.createAnchor(GENERAL_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, 'newAnchor')
137 then: 'an exception is thrown that the anchor already is defined'
138 thrown(AlreadyDefinedException)
140 objectUnderTest.deleteAnchor(GENERAL_TEST_DATASPACE, 'newAnchor')
143 def 'Query anchors without any known modules and #scenario'() {
144 when: 'querying for anchors with #scenario'
145 def result = objectUnderTest.queryAnchorNames(dataspaceName, ['unknownModule'])
146 then: 'an empty result is returned (no error)'
149 scenario | dataspaceName
150 'non existing database' | 'nonExistingDataspace'
151 'just unknown module(s)' | GENERAL_TEST_DATASPACE