From a966bab93a17fcba4e7fc28354c01b3f0878fbbe Mon Sep 17 00:00:00 2001 From: ToineSiebelink Date: Mon, 18 Dec 2023 12:25:41 +0000 Subject: Remove the dependency-cycle between beans - Splitting admin service into AnchorService and DataspaceService (this resolves the cyclic dependency) - Improved Delete dataspace integration error tests (were depending on execution order, now independent) Issue-ID: CPS-871 Change-Id: I47efedb6eb4bd2900f72d689616b7b7b62df2938 Signed-off-by: halil.cakal Signed-off-by: ToineSiebelink --- .../cps/api/impl/CpsAdminServiceImplSpec.groovy | 188 --------------------- .../cps/api/impl/CpsAnchorServiceImplSpec.groovy | 152 +++++++++++++++++ .../cps/api/impl/CpsDataServiceImplSpec.groovy | 16 +- .../api/impl/CpsDataspaceServiceImplSpec.groovy | 67 ++++++++ .../cps/api/impl/CpsModuleServiceImplSpec.groovy | 21 +-- .../onap/cps/api/impl/E2ENetworkSliceSpec.groovy | 12 +- .../org/onap/cps/utils/PrefixResolverSpec.groovy | 8 +- 7 files changed, 247 insertions(+), 217 deletions(-) delete mode 100755 cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy create mode 100644 cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAnchorServiceImplSpec.groovy create mode 100644 cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataspaceServiceImplSpec.groovy (limited to 'cps-service/src/test/groovy') diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy deleted file mode 100755 index 12564fb6d..000000000 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy +++ /dev/null @@ -1,188 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020-2023 Nordix Foundation - * Modifications Copyright (C) 2020-2022 Bell Canada. - * Modifications Copyright (C) 2021 Pantheon.tech - * Modifications Copyright (C) 2022 TechMahindra Ltd. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.cps.api.impl - -import org.onap.cps.api.CpsDataService -import org.onap.cps.spi.CpsAdminPersistenceService -import org.onap.cps.spi.exceptions.ModuleNamesNotFoundException -import org.onap.cps.spi.model.Anchor -import org.onap.cps.spi.model.Dataspace -import org.onap.cps.spi.utils.CpsValidator -import spock.lang.Specification -import java.time.OffsetDateTime - -class CpsAdminServiceImplSpec extends Specification { - def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService) - def mockCpsDataService = Mock(CpsDataService) - def mockCpsValidator = Mock(CpsValidator) - def objectUnderTest = new CpsAdminServiceImpl(mockCpsAdminPersistenceService, mockCpsDataService,mockCpsValidator) - - def 'Create dataspace method invokes persistence service.'() { - when: 'create dataspace method is invoked' - objectUnderTest.createDataspace('someDataspace') - then: 'the persistence service method is invoked with same parameters' - 1 * mockCpsAdminPersistenceService.createDataspace('someDataspace') - and: 'the CpsValidator is called on the dataspaceName' - 1 * mockCpsValidator.validateNameCharacters('someDataspace') - } - - def 'Create anchor method invokes persistence service.'() { - when: 'create anchor method is invoked' - objectUnderTest.createAnchor('someDataspace', 'someSchemaSet', 'someAnchorName') - then: 'the persistence service method is invoked with same parameters' - 1 * mockCpsAdminPersistenceService.createAnchor('someDataspace', 'someSchemaSet', 'someAnchorName') - and: 'the CpsValidator is called on the dataspaceName, schemaSetName and anchorName' - 1 * mockCpsValidator.validateNameCharacters('someDataspace', 'someSchemaSet', 'someAnchorName') - } - - def 'Retrieve all anchors for dataspace.'() { - given: 'that an anchor is associated with the dataspace' - def anchors = [new Anchor()] - mockCpsAdminPersistenceService.getAnchors('someDataspace') >> anchors - when: 'get Anchors is called for a dataspace name' - def result = objectUnderTest.getAnchors('someDataspace') - then: 'the collection provided by persistence service is returned as result' - result == anchors - and: 'the CpsValidator is called on the dataspaceName' - 1 * mockCpsValidator.validateNameCharacters('someDataspace') - } - - def 'Retrieve all anchors for schema-set.'() { - given: 'that anchor is associated with the dataspace and schemaset' - def anchors = [new Anchor()] - mockCpsAdminPersistenceService.getAnchors('someDataspace', 'someSchemaSet') >> anchors - when: 'get anchors is called for a dataspace name and schema set name' - def result = objectUnderTest.getAnchors('someDataspace', 'someSchemaSet') - then: 'the collection provided by persistence service is returned as result' - result == anchors - and: 'the CpsValidator is called on the dataspaceName, schemaSetName' - 1 * mockCpsValidator.validateNameCharacters('someDataspace', 'someSchemaSet') - } - - def 'Retrieve all anchors for multiple schema-sets.'() { - given: 'that anchor is associated with the dataspace and schemasets' - def anchors = [new Anchor(), new Anchor()] - mockCpsAdminPersistenceService.getAnchors('someDataspace', _ as Collection) >> anchors - when: 'get anchors is called for a dataspace name and schema set names' - def result = objectUnderTest.getAnchors('someDataspace', ['schemaSet1', 'schemaSet2']) - then: 'the collection provided by persistence service is returned as result' - result == anchors - and: 'the CpsValidator is called on the dataspace name and schema-set names' - 1 * mockCpsValidator.validateNameCharacters('someDataspace') - 1 * mockCpsValidator.validateNameCharacters(_) - } - - def 'Retrieve anchor for dataspace and provided anchor name.'() { - given: 'that anchor name is associated with the dataspace' - Anchor anchor = new Anchor() - mockCpsAdminPersistenceService.getAnchor('someDataspace','someAnchor') >> anchor - when: 'get anchor is called for a dataspace name and anchor name' - def result = objectUnderTest.getAnchor('someDataspace','someAnchor') - then: 'the anchor provided by persistence service is returned as result' - result == anchor - and: 'the CpsValidator is called on the dataspaceName, anchorName' - 1 * mockCpsValidator.validateNameCharacters('someDataspace', 'someAnchor') - } - - def 'Retrieve dataspace.'() { - given: 'a dataspace is already created' - def dataspace = new Dataspace(name: "someDataspace") - mockCpsAdminPersistenceService.getDataspace('someDataspace') >> dataspace - expect: 'the dataspace provided by persistence service is returned as result' - assert objectUnderTest.getDataspace('someDataspace') == dataspace - } - - def 'Retrieve all dataspaces.'() { - given: 'that all given dataspaces are already created' - def dataspaces = [new Dataspace(name: "test-dataspace1"), new Dataspace(name: "test-dataspace2")] - mockCpsAdminPersistenceService.getAllDataspaces() >> dataspaces - expect: 'the dataspace provided by persistence service is returned as result' - assert objectUnderTest.getAllDataspaces() == dataspaces - } - - def 'Delete anchor.'() { - when: 'delete anchor is invoked' - objectUnderTest.deleteAnchor('someDataspace','someAnchor') - then: 'delete data nodes is invoked on the data service with expected parameters' - 1 * mockCpsDataService.deleteDataNodes('someDataspace','someAnchor', _ as OffsetDateTime ) - and: 'the persistence service method is invoked with same parameters to delete anchor' - 1 * mockCpsAdminPersistenceService.deleteAnchor('someDataspace','someAnchor') - and: 'the CpsValidator is called on the dataspaceName, anchorName' - 1 * mockCpsValidator.validateNameCharacters('someDataspace', 'someAnchor') - } - - def 'Delete multiple anchors.'() { - when: 'delete anchors is invoked' - objectUnderTest.deleteAnchors('someDataspace', ['anchor1', 'anchor2']) - then: 'delete data nodes is invoked on the data service with expected parameters' - 1 * mockCpsDataService.deleteDataNodes('someDataspace', _ as Collection, _ as OffsetDateTime) - and: 'the persistence service method is invoked with same parameters to delete anchor' - 1 * mockCpsAdminPersistenceService.deleteAnchors('someDataspace',_ as Collection) - and: 'the CpsValidator is called on the dataspace name and anchor names' - 1 * mockCpsValidator.validateNameCharacters('someDataspace') - 1 * mockCpsValidator.validateNameCharacters(_) - } - - def 'Query all anchor identifiers for a dataspace and module names.'() { - given: 'the persistence service is invoked with the expected parameters and returns a list of anchors' - mockCpsAdminPersistenceService.queryAnchors('some-dataspace-name', ['some-module-name']) >> [new Anchor(name:'some-anchor-identifier')] - when: 'query anchor names is called using a dataspace name and module name' - def result = objectUnderTest.queryAnchorNames('some-dataspace-name', ['some-module-name']) - then: 'get anchor identifiers returns the same anchor identifier returned by the persistence layer' - result == ['some-anchor-identifier'] - and: 'the CpsValidator is called on the dataspaceName' - 1 * mockCpsValidator.validateNameCharacters('some-dataspace-name') - } - - def 'Query all anchors with Module Names Not Found Exception in persistence layer.'() { - given: 'the persistence layer throws a Module Names Not Found Exception' - def originalException = new ModuleNamesNotFoundException('exception-ds', [ 'm1', 'm2']) - mockCpsAdminPersistenceService.queryAnchors(*_) >> { throw originalException} - when: 'attempt query anchors' - objectUnderTest.queryAnchorNames('some-dataspace-name', []) - then: 'the same exception is thrown (up)' - def thrownUp = thrown(ModuleNamesNotFoundException) - assert thrownUp == originalException - and: 'the exception details contains the relevant data' - assert thrownUp.details.contains('exception-ds') - assert thrownUp.details.contains('m1') - assert thrownUp.details.contains('m2') - } - - def 'Delete dataspace.'() { - when: 'delete dataspace is invoked' - objectUnderTest.deleteDataspace('someDataspace') - then: 'associated persistence service method is invoked with correct parameter' - 1 * mockCpsAdminPersistenceService.deleteDataspace('someDataspace') - and: 'the CpsValidator is called on the dataspaceName' - 1 * mockCpsValidator.validateNameCharacters('someDataspace') - } - - def 'Update anchor schema set.'() { - when: 'update anchor is invoked' - objectUnderTest.updateAnchorSchemaSet('someDataspace', 'someAnchor', 'someSchemaSetName') - then: 'associated persistence service method is invoked with correct parameter' - 1 * mockCpsAdminPersistenceService.updateAnchorSchemaSet('someDataspace', 'someAnchor', 'someSchemaSetName') - } -} diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAnchorServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAnchorServiceImplSpec.groovy new file mode 100644 index 000000000..3546b8167 --- /dev/null +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAnchorServiceImplSpec.groovy @@ -0,0 +1,152 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.api.impl + +import org.onap.cps.spi.CpsAdminPersistenceService +import org.onap.cps.spi.CpsDataPersistenceService +import org.onap.cps.spi.exceptions.ModuleNamesNotFoundException +import org.onap.cps.spi.model.Anchor +import org.onap.cps.spi.utils.CpsValidator +import spock.lang.Specification + +class CpsAnchorServiceImplSpec extends Specification { + + def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService) + def mockCpsDataPersistenceService = Mock(CpsDataPersistenceService) + def mockCpsValidator = Mock(CpsValidator) + + def objectUnderTest = new CpsAnchorServiceImpl(mockCpsAdminPersistenceService, mockCpsDataPersistenceService, mockCpsValidator) + + def 'Create anchor method invokes persistence service.'() { + when: 'create anchor method is invoked' + objectUnderTest.createAnchor('someDataspace', 'someSchemaSet', 'someAnchorName') + then: 'the persistence service method is invoked with same parameters' + 1 * mockCpsAdminPersistenceService.createAnchor('someDataspace', 'someSchemaSet', 'someAnchorName') + and: 'the CpsValidator is called on the dataspaceName, schemaSetName and anchorName' + 1 * mockCpsValidator.validateNameCharacters('someDataspace', 'someSchemaSet', 'someAnchorName') + } + + def 'Retrieve all anchors for dataspace.'() { + given: 'that an anchor is associated with the dataspace' + def anchors = [new Anchor()] + mockCpsAdminPersistenceService.getAnchors('someDataspace') >> anchors + when: 'get Anchors is called for a dataspace name' + def result = objectUnderTest.getAnchors('someDataspace') + then: 'the collection provided by persistence service is returned as result' + result == anchors + and: 'the CpsValidator is called on the dataspaceName' + 1 * mockCpsValidator.validateNameCharacters('someDataspace') + } + + def 'Retrieve all anchors for schema-set.'() { + given: 'that anchor is associated with the dataspace and schemaset' + def anchors = [new Anchor()] + mockCpsAdminPersistenceService.getAnchors('someDataspace', 'someSchemaSet') >> anchors + when: 'get anchors is called for a dataspace name and schema set name' + def result = objectUnderTest.getAnchors('someDataspace', 'someSchemaSet') + then: 'the collection provided by persistence service is returned as result' + result == anchors + and: 'the CpsValidator is called on the dataspaceName, schemaSetName' + 1 * mockCpsValidator.validateNameCharacters('someDataspace', 'someSchemaSet') + } + + def 'Retrieve all anchors for multiple schema-sets.'() { + given: 'that anchor is associated with the dataspace and schemasets' + def anchors = [new Anchor(), new Anchor()] + mockCpsAdminPersistenceService.getAnchors('someDataspace', _ as Collection) >> anchors + when: 'get anchors is called for a dataspace name and schema set names' + def result = objectUnderTest.getAnchors('someDataspace', ['schemaSet1', 'schemaSet2']) + then: 'the collection provided by persistence service is returned as result' + result == anchors + and: 'the CpsValidator is called on the dataspace name and schema-set names' + 1 * mockCpsValidator.validateNameCharacters('someDataspace') + 1 * mockCpsValidator.validateNameCharacters(_) + } + + def 'Retrieve anchor for dataspace and provided anchor name.'() { + given: 'that anchor name is associated with the dataspace' + Anchor anchor = new Anchor() + mockCpsAdminPersistenceService.getAnchor('someDataspace','someAnchor') >> anchor + when: 'get anchor is called for a dataspace name and anchor name' + def result = objectUnderTest.getAnchor('someDataspace','someAnchor') + then: 'the anchor provided by persistence service is returned as result' + result == anchor + and: 'the CpsValidator is called on the dataspaceName, anchorName' + 1 * mockCpsValidator.validateNameCharacters('someDataspace', 'someAnchor') + } + + def 'Delete anchor.'() { + when: 'delete anchor is invoked' + objectUnderTest.deleteAnchor('someDataspace','someAnchor') + then: 'delete data nodes is invoked on the data service with expected parameters' + 1 * mockCpsDataPersistenceService.deleteDataNodes('someDataspace','someAnchor') + and: 'the persistence service method is invoked with same parameters to delete anchor' + 1 * mockCpsAdminPersistenceService.deleteAnchor('someDataspace','someAnchor') + and: 'the CpsValidator is called on the dataspaceName, anchorName' + 1 * mockCpsValidator.validateNameCharacters('someDataspace', 'someAnchor') + } + + def 'Delete multiple anchors.'() { + when: 'delete anchors is invoked' + objectUnderTest.deleteAnchors('someDataspace', ['anchor1', 'anchor2']) + then: 'delete data nodes is invoked on the data service with expected parameters' + 1 * mockCpsDataPersistenceService.deleteDataNodes('someDataspace', _ as Collection) + and: 'the persistence service method is invoked with same parameters to delete anchor' + 1 * mockCpsAdminPersistenceService.deleteAnchors('someDataspace',_ as Collection) + and: 'the CpsValidator is called on the dataspace name and anchor names' + 1 * mockCpsValidator.validateNameCharacters('someDataspace') + 1 * mockCpsValidator.validateNameCharacters(_) + } + + def 'Query all anchor identifiers for a dataspace and module names.'() { + given: 'the persistence service is invoked with the expected parameters and returns a list of anchors' + mockCpsAdminPersistenceService.queryAnchors('some-dataspace-name', ['some-module-name']) >> [new Anchor(name:'some-anchor-identifier')] + when: 'query anchor names is called using a dataspace name and module name' + def result = objectUnderTest.queryAnchorNames('some-dataspace-name', ['some-module-name']) + then: 'get anchor identifiers returns the same anchor identifier returned by the persistence layer' + result == ['some-anchor-identifier'] + and: 'the CpsValidator is called on the dataspaceName' + 1 * mockCpsValidator.validateNameCharacters('some-dataspace-name') + } + + def 'Query all anchors with Module Names Not Found Exception in persistence layer.'() { + given: 'the persistence layer throws a Module Names Not Found Exception' + def originalException = new ModuleNamesNotFoundException('exception-ds', ['m1', 'm2']) + mockCpsAdminPersistenceService.queryAnchors(*_) >> { throw originalException} + when: 'attempt query anchors' + objectUnderTest.queryAnchorNames('some-dataspace-name', []) + then: 'the same exception is thrown (up)' + def thrownUp = thrown(ModuleNamesNotFoundException) + assert thrownUp == originalException + and: 'the exception details contains the relevant data' + assert thrownUp.details.contains('exception-ds') + assert thrownUp.details.contains('m1') + assert thrownUp.details.contains('m2') + } + + def 'Update anchor schema set.'() { + when: 'update anchor is invoked' + objectUnderTest.updateAnchorSchemaSet('someDataspace', 'someAnchor', 'someSchemaSetName') + then: 'associated persistence service method is invoked with correct parameter' + 1 * mockCpsAdminPersistenceService.updateAnchorSchemaSet('someDataspace', 'someAnchor', 'someSchemaSetName') + } + +} diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy index 6ff708a6e..77e15c320 100644 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy @@ -24,7 +24,7 @@ package org.onap.cps.api.impl import org.onap.cps.TestUtils -import org.onap.cps.api.CpsAdminService +import org.onap.cps.api.CpsAnchorService import org.onap.cps.api.CpsDeltaService import org.onap.cps.spi.CpsDataPersistenceService import org.onap.cps.spi.FetchDescendantsOption @@ -43,26 +43,24 @@ import org.onap.cps.yang.YangTextSchemaSourceSet import org.onap.cps.yang.YangTextSchemaSourceSetBuilder import spock.lang.Shared import spock.lang.Specification - import java.time.OffsetDateTime import java.util.stream.Collectors class CpsDataServiceImplSpec extends Specification { def mockCpsDataPersistenceService = Mock(CpsDataPersistenceService) - def mockCpsAdminService = Mock(CpsAdminService) + def mockCpsAnchorService = Mock(CpsAnchorService) def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache) def mockCpsValidator = Mock(CpsValidator) def timedYangParser = new TimedYangParser() def mockCpsDeltaService = Mock(CpsDeltaService); - def objectUnderTest = new CpsDataServiceImpl(mockCpsDataPersistenceService, mockCpsAdminService, + def objectUnderTest = new CpsDataServiceImpl(mockCpsDataPersistenceService, mockCpsAnchorService, mockYangTextSchemaSourceSetCache, mockCpsValidator, timedYangParser, mockCpsDeltaService) def setup() { - - mockCpsAdminService.getAnchor(dataspaceName, anchorName) >> anchor - mockCpsAdminService.getAnchor(dataspaceName, ANCHOR_NAME_1) >> anchor1 - mockCpsAdminService.getAnchor(dataspaceName, ANCHOR_NAME_2) >> anchor2 + mockCpsAnchorService.getAnchor(dataspaceName, anchorName) >> anchor + mockCpsAnchorService.getAnchor(dataspaceName, ANCHOR_NAME_1) >> anchor1 + mockCpsAnchorService.getAnchor(dataspaceName, ANCHOR_NAME_2) >> anchor2 } @Shared @@ -426,7 +424,7 @@ class CpsDataServiceImplSpec extends Specification { def 'Delete all data nodes for given dataspace and multiple anchors.'() { given: 'schema set for given anchors and dataspace references test tree model' setupSchemaSetMocks('test-tree.yang') - mockCpsAdminService.getAnchors(dataspaceName, ['anchor1', 'anchor2']) >> + mockCpsAnchorService.getAnchors(dataspaceName, ['anchor1', 'anchor2']) >> [new Anchor(name: 'anchor1', dataspaceName: dataspaceName), new Anchor(name: 'anchor2', dataspaceName: dataspaceName)] when: 'delete data node method is invoked with correct parameters' diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataspaceServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataspaceServiceImplSpec.groovy new file mode 100644 index 000000000..8e17594bd --- /dev/null +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataspaceServiceImplSpec.groovy @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.api.impl + +import org.onap.cps.spi.CpsAdminPersistenceService +import org.onap.cps.spi.model.Dataspace +import org.onap.cps.spi.utils.CpsValidator +import spock.lang.Specification + +class CpsDataspaceServiceImplSpec extends Specification { + def mockCpsAdminPersistenceService = Mock(CpsAdminPersistenceService) + def mockCpsValidator = Mock(CpsValidator) + def objectUnderTest = new CpsDataspaceServiceImpl(mockCpsAdminPersistenceService,mockCpsValidator) + + def 'Create dataspace method invokes persistence service.'() { + when: 'create dataspace method is invoked' + objectUnderTest.createDataspace('someDataspace') + then: 'the persistence service method is invoked with same parameters' + 1 * mockCpsAdminPersistenceService.createDataspace('someDataspace') + and: 'the CpsValidator is called on the dataspaceName' + 1 * mockCpsValidator.validateNameCharacters('someDataspace') + } + + def 'Retrieve dataspace.'() { + given: 'a dataspace is already created' + def dataspace = new Dataspace(name: "someDataspace") + mockCpsAdminPersistenceService.getDataspace('someDataspace') >> dataspace + expect: 'the dataspace provided by persistence service is returned as result' + assert objectUnderTest.getDataspace('someDataspace') == dataspace + } + + def 'Retrieve all dataspaces.'() { + given: 'that all given dataspaces are already created' + def dataspaces = [new Dataspace(name: "test-dataspace1"), new Dataspace(name: "test-dataspace2")] + mockCpsAdminPersistenceService.getAllDataspaces() >> dataspaces + expect: 'the dataspace provided by persistence service is returned as result' + assert objectUnderTest.getAllDataspaces() == dataspaces + } + + def 'Delete dataspace.'() { + when: 'delete dataspace is invoked' + objectUnderTest.deleteDataspace('someDataspace') + then: 'associated persistence service method is invoked with correct parameter' + 1 * mockCpsAdminPersistenceService.deleteDataspace('someDataspace') + and: 'the CpsValidator is called on the dataspaceName' + 1 * mockCpsValidator.validateNameCharacters('someDataspace') + } + +} diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy index d8edb02ab..d909e27ab 100644 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy @@ -23,11 +23,12 @@ package org.onap.cps.api.impl +import org.onap.cps.api.CpsAnchorService + import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_ALLOWED import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED import org.onap.cps.TestUtils -import org.onap.cps.api.CpsAdminService import org.onap.cps.spi.CpsModulePersistenceService import org.onap.cps.spi.exceptions.DuplicatedYangResourceException import org.onap.cps.spi.exceptions.ModelValidationException @@ -45,12 +46,12 @@ import spock.lang.Specification class CpsModuleServiceImplSpec extends Specification { def mockCpsModulePersistenceService = Mock(CpsModulePersistenceService) - def mockCpsAdminService = Mock(CpsAdminService) def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache) + def mockCpsAnchorService = Mock(CpsAnchorService) def mockCpsValidator = Mock(CpsValidator) def timedYangTextSchemaSourceSetBuilder = new TimedYangTextSchemaSourceSetBuilder() - def objectUnderTest = new CpsModuleServiceImpl(mockCpsModulePersistenceService, mockYangTextSchemaSourceSetCache, mockCpsAdminService, mockCpsValidator,timedYangTextSchemaSourceSetBuilder) + def objectUnderTest = new CpsModuleServiceImpl(mockCpsModulePersistenceService, mockYangTextSchemaSourceSetCache, mockCpsAnchorService, mockCpsValidator,timedYangTextSchemaSourceSetBuilder) def 'Create schema set.'() { when: 'Create schema set method is invoked' @@ -133,11 +134,11 @@ class CpsModuleServiceImplSpec extends Specification { def 'Delete schema-set when cascade is allowed.'() { given: '#numberOfAnchors anchors are associated with schemaset' def associatedAnchors = createAnchors(numberOfAnchors) - mockCpsAdminService.getAnchors('my-dataspace', 'my-schemaset') >> associatedAnchors + mockCpsAnchorService.getAnchors('my-dataspace', 'my-schemaset') >> associatedAnchors when: 'schema set deletion is requested with cascade allowed' objectUnderTest.deleteSchemaSet('my-dataspace', 'my-schemaset', CASCADE_DELETE_ALLOWED) then: 'anchor deletion is called #numberOfAnchors times' - numberOfAnchors * mockCpsAdminService.deleteAnchor('my-dataspace', _) + numberOfAnchors * mockCpsAnchorService.deleteAnchor('my-dataspace', _) and: 'persistence service method is invoked with same parameters' 1 * mockCpsModulePersistenceService.deleteSchemaSet('my-dataspace', 'my-schemaset') and: 'schema set will be removed from the cache' @@ -152,11 +153,11 @@ class CpsModuleServiceImplSpec extends Specification { def 'Delete schema-set when cascade is prohibited.'() { given: 'no anchors are associated with schemaset' - mockCpsAdminService.getAnchors('my-dataspace', 'my-schemaset') >> Collections.emptyList() + mockCpsAnchorService.getAnchors('my-dataspace', 'my-schemaset') >> Collections.emptyList() when: 'schema set deletion is requested with cascade allowed' objectUnderTest.deleteSchemaSet('my-dataspace', 'my-schemaset', CASCADE_DELETE_PROHIBITED) then: 'no anchors are deleted' - 0 * mockCpsAdminService.deleteAnchor(_, _) + 0 * mockCpsAnchorService.deleteAnchor(_, _) and: 'persistence service method is invoked with same parameters' 1 * mockCpsModulePersistenceService.deleteSchemaSet('my-dataspace', 'my-schemaset') and: 'schema set will be removed from the cache' @@ -169,7 +170,7 @@ class CpsModuleServiceImplSpec extends Specification { def 'Delete schema-set when cascade is prohibited and schema-set has anchors.'() { given: '2 anchors are associated with schemaset' - mockCpsAdminService.getAnchors('my-dataspace', 'my-schemaset') >> createAnchors(2) + mockCpsAnchorService.getAnchors('my-dataspace', 'my-schemaset') >> createAnchors(2) when: 'schema set deletion is requested with cascade allowed' objectUnderTest.deleteSchemaSet('my-dataspace', 'my-schemaset', CASCADE_DELETE_PROHIBITED) then: 'Schema-Set in Use exception is thrown' @@ -178,11 +179,11 @@ class CpsModuleServiceImplSpec extends Specification { def 'Delete multiple schema-sets when cascade is allowed.'() { given: '#numberOfAnchors anchors are associated with each schemaset' - mockCpsAdminService.getAnchors('my-dataspace', ['my-schemaset1', 'my-schemaset2']) >> createAnchors(numberOfAnchors * 2) + mockCpsAnchorService.getAnchors('my-dataspace', ['my-schemaset1', 'my-schemaset2']) >> createAnchors(numberOfAnchors * 2) when: 'schema set deletion is requested with cascade allowed' objectUnderTest.deleteSchemaSetsWithCascade('my-dataspace', ['my-schemaset1', 'my-schemaset2']) then: 'anchor deletion is called #numberOfAnchors times' - mockCpsAdminService.deleteAnchors('my-dataspace', _) + mockCpsAnchorService.deleteAnchors('my-dataspace', _) and: 'persistence service method is invoked with same parameters' mockCpsModulePersistenceService.deleteSchemaSets('my-dataspace', _) and: 'schema sets will be removed from the cache' diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy index 118ee1cd0..4782468f1 100755 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/E2ENetworkSliceSpec.groovy @@ -24,7 +24,7 @@ package org.onap.cps.api.impl import org.onap.cps.TestUtils -import org.onap.cps.api.CpsAdminService +import org.onap.cps.api.CpsAnchorService import org.onap.cps.api.CpsDeltaService import org.onap.cps.spi.CpsDataPersistenceService import org.onap.cps.spi.CpsDataPersistenceService @@ -40,7 +40,7 @@ import spock.lang.Specification class E2ENetworkSliceSpec extends Specification { def mockModuleStoreService = Mock(CpsModulePersistenceService) def mockDataStoreService = Mock(CpsDataPersistenceService) - def mockCpsAdminService = Mock(CpsAdminService) + def mockCpsAnchorService = Mock(CpsAnchorService) def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache) def mockCpsValidator = Mock(CpsValidator) def timedYangTextSchemaSourceSetBuilder = new TimedYangTextSchemaSourceSetBuilder() @@ -48,9 +48,9 @@ class E2ENetworkSliceSpec extends Specification { def mockCpsDeltaService = Mock(CpsDeltaService) def cpsModuleServiceImpl = new CpsModuleServiceImpl(mockModuleStoreService, - mockYangTextSchemaSourceSetCache, mockCpsAdminService, mockCpsValidator,timedYangTextSchemaSourceSetBuilder) + mockYangTextSchemaSourceSetCache, mockCpsAnchorService, mockCpsValidator,timedYangTextSchemaSourceSetBuilder) - def cpsDataServiceImpl = new CpsDataServiceImpl(mockDataStoreService, mockCpsAdminService, + def cpsDataServiceImpl = new CpsDataServiceImpl(mockDataStoreService, mockCpsAnchorService, mockYangTextSchemaSourceSetCache, mockCpsValidator, timedYangParser, mockCpsDeltaService) def dataspaceName = 'someDataspace' @@ -90,7 +90,7 @@ class E2ENetworkSliceSpec extends Specification { and : 'a valid json is provided for the model' def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-Cavsta-Data.txt') and : 'all the further dependencies are mocked ' - mockCpsAdminService.getAnchor(dataspaceName, anchorName) >> + mockCpsAnchorService.getAnchor(dataspaceName, anchorName) >> new Anchor().builder().name(anchorName).schemaSetName(schemaSetName).dataspaceName(dataspaceName).build() mockYangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName) >> YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap) @@ -123,7 +123,7 @@ class E2ENetworkSliceSpec extends Specification { and : 'a valid json is provided for the model' def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-ran-inventory-data.json') and : 'all the further dependencies are mocked ' - mockCpsAdminService.getAnchor('someDataspace', 'someAnchor') >> + mockCpsAnchorService.getAnchor('someDataspace', 'someAnchor') >> new Anchor().builder().name('someAnchor').schemaSetName('someSchemaSet').dataspaceName(dataspaceName).build() mockYangTextSchemaSourceSetCache.get('someDataspace', 'someSchemaSet') >> YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap) mockModuleStoreService.getYangSchemaResources('someDataspace', 'someSchemaSet') >> schemaContext diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/PrefixResolverSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/PrefixResolverSpec.groovy index ff6ab346f..b975de655 100644 --- a/cps-service/src/test/groovy/org/onap/cps/utils/PrefixResolverSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/utils/PrefixResolverSpec.groovy @@ -24,7 +24,7 @@ package org.onap.cps.utils import com.hazelcast.map.IMap import org.onap.cps.TestUtils -import org.onap.cps.api.CpsAdminService +import org.onap.cps.api.CpsAnchorService import org.onap.cps.api.impl.YangTextSchemaSourceSetCache import org.onap.cps.cache.AnchorDataCacheEntry import org.onap.cps.spi.model.Anchor @@ -34,13 +34,13 @@ import spock.lang.Specification class PrefixResolverSpec extends Specification { - def mockCpsAdminService = Mock(CpsAdminService) + def mockCpsAnchorService = Mock(CpsAnchorService) def mockYangTextSchemaSourceSetCache = Mock(YangTextSchemaSourceSetCache) def mockAnchorDataCache = Mock(IMap) - def objectUnderTest = new PrefixResolver(mockCpsAdminService, mockYangTextSchemaSourceSetCache, mockAnchorDataCache) + def objectUnderTest = new PrefixResolver(mockCpsAnchorService, mockYangTextSchemaSourceSetCache, mockAnchorDataCache) def mockYangTextSchemaSourceSet = Mock(YangTextSchemaSourceSet) @@ -52,7 +52,7 @@ class PrefixResolverSpec extends Specification { given: 'an anchor for the test-tree model' def anchor = new Anchor(dataspaceName: 'testDataspace', name: 'testAnchor') and: 'the system can get this anchor' - mockCpsAdminService.getAnchor('testDataspace', 'testAnchor') >> anchor + mockCpsAnchorService.getAnchor('testDataspace', 'testAnchor') >> anchor and: 'the schema source cache contains the schema context for the test-tree module' mockYangTextSchemaSourceSet.getSchemaContext() >> schemaContext } -- cgit 1.2.3-korg