95afeb4172617441bdb15598a01799401a1a09ad
[cps.git] / cps-service / src / test / groovy / org / onap / cps / api / impl / CpsAdminServiceImplSpec.groovy
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix Foundation
4  *  Modifications Copyright (C) 2020 Bell Canada.
5  *  Modifications Copyright (C) 2021 Pantheon.tech
6  *  ================================================================================
7  *  Licensed under the Apache License, Version 2.0 (the "License");
8  *  you may not use this file except in compliance with the License.
9  *  You may obtain a copy of the License at
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
13  *  Unless required by applicable law or agreed to in writing, software
14  *  distributed under the License is distributed on an "AS IS" BASIS,
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *  See the License for the specific language governing permissions and
17  *  limitations under the License.
18  *
19  *  SPDX-License-Identifier: Apache-2.0
20  *  ============LICENSE_END=========================================================
21  */
22
23 package org.onap.cps.api.impl
24
25 import org.onap.cps.spi.CpsAdminPersistenceService
26 import org.onap.cps.spi.model.Anchor
27 import spock.lang.Specification
28
29 class CpsAdminServiceImplSpec extends Specification {
30     def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService)
31     def objectUnderTest = new CpsAdminServiceImpl()
32
33     def setup() {
34         objectUnderTest.cpsAdminPersistenceService = mockCpsAdminPersistenceService
35     }
36
37     def 'Create dataspace method invokes persistence service.'() {
38         when: 'create dataspace method is invoked'
39             objectUnderTest.createDataspace('someDataspace')
40         then: 'the persistence service method is invoked with same parameters'
41             1 * mockCpsAdminPersistenceService.createDataspace('someDataspace')
42     }
43
44     def 'Create anchor method invokes persistence service.'() {
45         when: 'create anchor method is invoked'
46             objectUnderTest.createAnchor('someDataspace', 'someSchemaSet', 'someAnchorName')
47         then: 'the persistence service method is invoked with same parameters'
48             1 * mockCpsAdminPersistenceService.createAnchor('someDataspace', 'someSchemaSet', 'someAnchorName')
49     }
50
51     def 'Retrieve all anchors for dataspace.'() {
52         given: 'that anchor is associated with the dataspace'
53             def anchors = [new Anchor()]
54             mockCpsAdminPersistenceService.getAnchors('someDataspace') >> anchors
55         expect: 'the collection provided by persistence service is returned as result'
56             objectUnderTest.getAnchors('someDataspace') == anchors
57     }
58
59     def 'Retrieve anchor for dataspace and provided anchor name.'() {
60         given: 'that anchor name is associated with the dataspace'
61             Anchor anchor = new Anchor()
62             mockCpsAdminPersistenceService.getAnchor('someDataspace','someAnchor') >>  anchor
63         expect: 'the anchor provided by persistence service is returned as result'
64             assert objectUnderTest.getAnchor('someDataspace','someAnchor') == anchor
65     }
66
67     def 'Delete anchor.'() {
68         when: 'delete anchor is invoked'
69             objectUnderTest.deleteAnchor('someDataspace','someAnchor')
70         then: 'associated persistence service method is invoked with same parameters'
71              1 * mockCpsAdminPersistenceService.deleteAnchor('someDataspace','someAnchor')
72     }
73
74     def 'Query all anchor identifiers for a dataspace and module names.'() {
75         given: 'the persistence service is invoked with the expected parameters and returns a list of anchors'
76             mockCpsAdminPersistenceService.queryAnchors('some-dataspace-name', ['some-module-name']) >> [new Anchor(name:'some-anchor-identifier')]
77         expect: 'get anchor identifiers returns the same anchor identifier returned by the persistence layer'
78             objectUnderTest.queryAnchorNames('some-dataspace-name', ['some-module-name']) == ['some-anchor-identifier']
79
80     }
81 }