2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation
4 * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
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
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.cps.api.impl
24 import org.onap.cps.spi.CpsAdminPersistenceService
25 import org.onap.cps.spi.model.Anchor
26 import spock.lang.Specification
28 class CpsAdminServiceImplSpec extends Specification {
29 def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService)
30 def objectUnderTest = new CpsAdminServiceImpl()
33 objectUnderTest.cpsAdminPersistenceService = mockCpsAdminPersistenceService
36 def 'Create dataspace method invokes persistence service.'() {
37 when: 'Create dataspace method is invoked'
38 objectUnderTest.createDataspace('someDataspace')
39 then: 'The persistence service method is invoked with same parameters'
40 1 * mockCpsAdminPersistenceService.createDataspace('someDataspace')
43 def 'Create anchor method invokes persistence service.'() {
44 when: 'Create anchor method is invoked'
45 objectUnderTest.createAnchor('someDataspace', 'someSchemaSet', 'someAnchorName')
46 then: 'The persistence service method is invoked with same parameters'
47 1 * mockCpsAdminPersistenceService.createAnchor('someDataspace', 'someSchemaSet', 'someAnchorName')
50 def 'Retrieve all anchors for dataspace.'() {
51 given: 'that anchor is associated with the dataspace'
52 def anchors = [new Anchor()]
53 mockCpsAdminPersistenceService.getAnchors('someDataspace') >> anchors
54 expect: 'the collection provided by persistence service is returned as result'
55 objectUnderTest.getAnchors('someDataspace') == anchors
58 def 'Retrieve anchor for dataspace and provided anchor name.'() {
59 given: 'that anchor name is associated with the dataspace'
60 Anchor anchor = new Anchor()
61 mockCpsAdminPersistenceService.getAnchor('someDataspace','someAnchor') >> anchor
62 expect: 'the anchor provided by persistence service is returned as result'
63 objectUnderTest.getAnchor('someDataspace','someAnchor') == anchor
66 def 'Delete anchor.'() {
67 when: 'delete anchor is invoked'
68 objectUnderTest.deleteAnchor('someDataspace','someAnchor')
69 then: 'associated persistence service method is invoked with same parameters'
70 1 * mockCpsAdminPersistenceService.deleteAnchor('someDataspace','someAnchor')