2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020-2022 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.api.CpsDataService
26 import org.onap.cps.spi.CpsAdminPersistenceService
27 import org.onap.cps.spi.model.Anchor
28 import org.onap.cps.spi.model.CmHandleQueryParameters
29 import spock.lang.Specification
30 import java.time.OffsetDateTime
32 class CpsAdminServiceImplSpec extends Specification {
33 def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService)
34 def mockCpsDataService = Mock(CpsDataService)
35 def objectUnderTest = new CpsAdminServiceImpl(mockCpsAdminPersistenceService, mockCpsDataService)
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: 'delete data nodes is invoked on the data service with expected parameters'
79 1 * mockCpsDataService.deleteDataNodes('someDataspace','someAnchor', _ as OffsetDateTime )
80 and: 'the persistence service method is invoked with same parameters to delete anchor'
81 1 * mockCpsAdminPersistenceService.deleteAnchor('someDataspace','someAnchor')
84 def 'Query all anchor identifiers for a dataspace and module names.'() {
85 given: 'the persistence service is invoked with the expected parameters and returns a list of anchors'
86 mockCpsAdminPersistenceService.queryAnchors('some-dataspace-name', ['some-module-name']) >> [new Anchor(name:'some-anchor-identifier')]
87 expect: 'get anchor identifiers returns the same anchor identifier returned by the persistence layer'
88 objectUnderTest.queryAnchorNames('some-dataspace-name', ['some-module-name']) == ['some-anchor-identifier']
92 def 'Delete dataspace.'() {
93 when: 'delete dataspace is invoked'
94 objectUnderTest.deleteDataspace('someDataspace')
95 then: 'associated persistence service method is invoked with correct parameter'
96 1 * mockCpsAdminPersistenceService.deleteDataspace('someDataspace')
99 def 'Query CM Handles.'() {
100 given: 'a cm handle query'
101 def cmHandleQueryParameters = new CmHandleQueryParameters()
102 when: 'query cm handles is invoked'
103 objectUnderTest.queryCmHandles(cmHandleQueryParameters)
104 then: 'associated persistence service method is invoked with correct parameter'
105 1 * mockCpsAdminPersistenceService.queryCmHandles(cmHandleQueryParameters)