Remove the dependency-cycle between beans
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / functional / CpsDataspaceServiceIntegrationSpec.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.api.CpsDataspaceService
24 import org.onap.cps.integration.base.CpsIntegrationSpecBase
25 import org.onap.cps.spi.exceptions.AlreadyDefinedException
26 import org.onap.cps.spi.exceptions.DataspaceInUseException
27 import org.onap.cps.spi.exceptions.DataspaceNotFoundException
28
29 class CpsDataspaceServiceIntegrationSpec extends CpsIntegrationSpecBase {
30
31     CpsDataspaceService objectUnderTest
32
33     def setup() { objectUnderTest = cpsDataspaceService }
34
35     def 'Dataspace CRUD operations.'() {
36         when: 'a dataspace is created'
37             objectUnderTest.createDataspace('newDataspace')
38         then: 'the dataspace can be read'
39             assert objectUnderTest.getDataspace('newDataspace').name == 'newDataspace'
40         and: 'it can be deleted'
41             objectUnderTest.deleteDataspace('newDataspace')
42         then: 'the dataspace no longer exists i.e. an exception is thrown if an attempt is made to retrieve it'
43             def thrown = null
44             try {
45                 objectUnderTest.getDataspace('newDataspace')
46             } catch(Exception exception) {
47                 thrown = exception
48             }
49            assert thrown instanceof DataspaceNotFoundException
50     }
51
52     def 'Attempt to delete a non-existing dataspace'() {
53         when: 'attempt to delete a non-existing dataspace'
54             objectUnderTest.deleteDataspace('non-existing-name')
55         then: 'a not found exception is thrown with the relevant dataspace name'
56             def thrownException = thrown(DataspaceNotFoundException)
57             assert thrownException.details.contains('non-existing-name does not exist')
58     }
59
60     def 'Attempt Delete dataspace with a schema set and anchor'() {
61         setup: 'a dataspace with a schema set and anchor'
62             objectUnderTest.createDataspace('targetDataspace')
63             cpsModuleService.createSchemaSet('targetDataspace','someSchemaSet',[:])
64             cpsAnchorService.createAnchor('targetDataspace', 'someSchemaSet', 'some_anchor')
65         when: 'attempt to delete dataspace'
66             objectUnderTest.deleteDataspace('targetDataspace')
67         then: 'an in-use exception is thrown mentioning anchors'
68             def thrownException = thrown(DataspaceInUseException)
69             assert thrownException.details.contains('contains 1 anchor(s)')
70         cleanup:
71             cpsModuleService.deleteSchemaSetsWithCascade('targetDataspace',['someSchemaSet'])
72             objectUnderTest.deleteDataspace('targetDataspace')
73     }
74
75     def 'Attempt to delete dataspace with just a schema set'() {
76         setup: 'a dataspace with a schema set'
77             objectUnderTest.createDataspace('targetDataspace')
78             cpsModuleService.createSchemaSet('targetDataspace','someSchemaSet',[:])
79         when: 'attempt to delete dataspace'
80             objectUnderTest.deleteDataspace('targetDataspace')
81         then: 'an in-use exception is thrown mentioning schemasets'
82             def thrownException = thrown(DataspaceInUseException)
83             assert thrownException.details.contains('contains 1 schemaset(s)')
84         cleanup:
85             cpsModuleService.deleteSchemaSetsWithCascade('targetDataspace',['someSchemaSet'])
86             objectUnderTest.deleteDataspace('targetDataspace')
87     }
88
89     def 'Retrieve all dataspaces (depends on total test suite).'() {
90         given: 'two addtional dataspaces are created'
91             objectUnderTest.createDataspace('dataspace1')
92             objectUnderTest.createDataspace('dataspace2')
93         when: 'all datespaces are retreived'
94             def result = objectUnderTest.getAllDataspaces()
95         then: 'there are at least 3 dataspaces (2 new ones plus the general test dataspace)'
96             result.size() >= 3
97             assert result.name.containsAll([GENERAL_TEST_DATASPACE, 'dataspace1', 'dataspace2'])
98     }
99
100     def 'Duplicate dataspaces.'() {
101         when: 'attempting to create a dataspace with the same name as an existing one'
102             objectUnderTest.createDataspace(GENERAL_TEST_DATASPACE)
103         then: 'an exception is thrown indicating the dataspace already exists'
104             thrown(AlreadyDefinedException)
105     }
106
107 }