2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation
4 * Modifications Copyright (C) 2020-2022 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.cps.api.impl
25 import org.onap.cps.spi.CpsAdminPersistenceService
26 import org.onap.cps.spi.model.Anchor
27 import spock.lang.Specification
29 class CpsAdminServiceImplSpec extends Specification {
30 def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService)
31 def objectUnderTest = new CpsAdminServiceImpl()
34 objectUnderTest.cpsAdminPersistenceService = mockCpsAdminPersistenceService
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')
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')
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
59 def 'Retrieve all anchors for schema-set.'() {
60 given: 'that anchor is associated with the dataspace and schemaset'
61 def anchors = [new Anchor()]
62 mockCpsAdminPersistenceService.getAnchors('someDataspace', 'someSchemaSet') >> anchors
63 expect: 'the collection provided by persistence service is returned as result'
64 objectUnderTest.getAnchors('someDataspace', 'someSchemaSet') == anchors
67 def 'Retrieve anchor for dataspace and provided anchor name.'() {
68 given: 'that anchor name is associated with the dataspace'
69 Anchor anchor = new Anchor()
70 mockCpsAdminPersistenceService.getAnchor('someDataspace','someAnchor') >> anchor
71 expect: 'the anchor provided by persistence service is returned as result'
72 assert objectUnderTest.getAnchor('someDataspace','someAnchor') == anchor
75 def 'Delete anchor.'() {
76 when: 'delete anchor is invoked'
77 objectUnderTest.deleteAnchor('someDataspace','someAnchor')
78 then: 'associated persistence service method is invoked with same parameters'
79 1 * mockCpsAdminPersistenceService.deleteAnchor('someDataspace','someAnchor')
82 def 'Query all anchor identifiers for a dataspace and module names.'() {
83 given: 'the persistence service is invoked with the expected parameters and returns a list of anchors'
84 mockCpsAdminPersistenceService.queryAnchors('some-dataspace-name', ['some-module-name']) >> [new Anchor(name:'some-anchor-identifier')]
85 expect: 'get anchor identifiers returns the same anchor identifier returned by the persistence layer'
86 objectUnderTest.queryAnchorNames('some-dataspace-name', ['some-module-name']) == ['some-anchor-identifier']
90 def 'Delete dataspace.'() {
91 when: 'delete dataspace is invoked'
92 objectUnderTest.deleteDataspace('someDataspace')
93 then: 'associated persistence service method is invoked with correct parameter'
94 1 * mockCpsAdminPersistenceService.deleteDataspace('someDataspace')