Remove the dependency-cycle between beans
[cps.git] / cps-service / src / test / groovy / org / onap / cps / api / impl / CpsDataspaceServiceImplSpec.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.api.impl
22
23 import org.onap.cps.spi.CpsAdminPersistenceService
24 import org.onap.cps.spi.model.Dataspace
25 import org.onap.cps.spi.utils.CpsValidator
26 import spock.lang.Specification
27
28 class CpsDataspaceServiceImplSpec extends Specification {
29     def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService)
30     def mockCpsValidator = Mock(CpsValidator)
31     def objectUnderTest = new CpsDataspaceServiceImpl(mockCpsAdminPersistenceService,mockCpsValidator)
32
33     def 'Create dataspace method invokes persistence service.'() {
34         when: 'create dataspace method is invoked'
35             objectUnderTest.createDataspace('someDataspace')
36         then: 'the persistence service method is invoked with same parameters'
37             1 * mockCpsAdminPersistenceService.createDataspace('someDataspace')
38         and: 'the CpsValidator is called on the dataspaceName'
39             1 * mockCpsValidator.validateNameCharacters('someDataspace')
40     }
41
42     def 'Retrieve dataspace.'() {
43         given: 'a dataspace is already created'
44             def dataspace = new Dataspace(name: "someDataspace")
45             mockCpsAdminPersistenceService.getDataspace('someDataspace') >> dataspace
46         expect: 'the dataspace provided by persistence service is returned as result'
47           assert objectUnderTest.getDataspace('someDataspace') == dataspace
48     }
49
50     def 'Retrieve all dataspaces.'() {
51         given: 'that all given dataspaces are already created'
52         def dataspaces = [new Dataspace(name: "test-dataspace1"), new Dataspace(name: "test-dataspace2")]
53             mockCpsAdminPersistenceService.getAllDataspaces() >> dataspaces
54         expect: 'the dataspace provided by persistence service is returned as result'
55            assert objectUnderTest.getAllDataspaces() == dataspaces
56     }
57
58     def 'Delete dataspace.'() {
59         when: 'delete dataspace is invoked'
60             objectUnderTest.deleteDataspace('someDataspace')
61         then: 'associated persistence service method is invoked with correct parameter'
62             1 * mockCpsAdminPersistenceService.deleteDataspace('someDataspace')
63         and: 'the CpsValidator is called on the dataspaceName'
64             1 * mockCpsValidator.validateNameCharacters('someDataspace')
65     }
66
67 }