2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation
4 * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.api.impl
23 import org.onap.cps.spi.CpsAdminPersistenceService
24 import org.onap.cps.spi.model.Anchor
25 import spock.lang.Specification
27 class CpsAdminServiceImplSpec extends Specification {
28 def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService)
29 def objectUnderTest = new CpsAdminServiceImpl()
32 objectUnderTest.cpsAdminPersistenceService = mockCpsAdminPersistenceService
35 def 'Create dataspace method invokes persistence service.'() {
36 when: 'Create dataspace method is invoked'
37 objectUnderTest.createDataspace('someDataspace')
38 then: 'The persistence service method is invoked with same parameters'
39 1 * mockCpsAdminPersistenceService.createDataspace('someDataspace')
42 def 'Create anchor method invokes persistence service.'() {
43 when: 'Create anchor method is invoked'
44 objectUnderTest.createAnchor('someDataspace', 'someSchemaSet', 'someAnchorName')
45 then: 'The persistence service method is invoked with same parameters'
46 1 * mockCpsAdminPersistenceService.createAnchor('someDataspace', 'someSchemaSet', 'someAnchorName')
49 def 'Retrieve all anchors for dataspace.'() {
50 given: 'that anchor is associated with the dataspace'
51 def anchors = [new Anchor()]
52 mockCpsAdminPersistenceService.getAnchors('someDataspace') >> anchors
53 expect: 'the collection provided by persistence service is returned as result'
54 objectUnderTest.getAnchors('someDataspace') == anchors
57 def 'Retrieve anchor for dataspace and provided anchor name.'() {
58 given: 'that anchor name is associated with the dataspace'
59 Anchor anchor = new Anchor()
60 mockCpsAdminPersistenceService.getAnchor('someDataspace','someAnchor') >> anchor
61 expect: 'the anchor provided by persistence service is returned as result'
62 objectUnderTest.getAnchor('someDataspace','someAnchor') == anchor