diff options
author | leventecsanyi <levente.csanyi@est.tech> | 2024-05-23 16:40:13 +0200 |
---|---|---|
committer | leventecsanyi <levente.csanyi@est.tech> | 2024-05-28 14:07:05 +0200 |
commit | 76fb17f57bec04a96fc53f8c730755da4cbe2856 (patch) | |
tree | 3da6b3d399478f5042a5ad1ca90a44414b61e8ee /cps-ncmp-service/src/test | |
parent | e80121ef3cc4a0a44ba9ddea935e2270e1da775a (diff) |
Restructure(package) DataJobs feature in NCMP Service
- restructured already existing classes
- added testware for AlternateIdMatcher
Issue-ID: CPS 2240
Change-Id: I5691ed99627353903689cd2929163f77ed8c4eca
Signed-off-by: leventecsanyi <levente.csanyi@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test')
3 files changed, 72 insertions, 41 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/DataJobServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/DataJobServiceImplSpec.groovy index 43787640a3..bef0adc9cb 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/DataJobServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/DataJobServiceImplSpec.groovy @@ -24,12 +24,13 @@ import ch.qos.logback.classic.Level import ch.qos.logback.classic.Logger import ch.qos.logback.classic.spi.ILoggingEvent import ch.qos.logback.core.read.ListAppender +import org.onap.cps.ncmp.impl.datajobs.DataJobServiceImpl import org.slf4j.LoggerFactory -import org.onap.cps.ncmp.api.models.datajob.DataJobReadRequest -import org.onap.cps.ncmp.api.models.datajob.DataJobWriteRequest -import org.onap.cps.ncmp.api.models.datajob.DataJobMetadata -import org.onap.cps.ncmp.api.models.datajob.ReadOperation -import org.onap.cps.ncmp.api.models.datajob.WriteOperation +import org.onap.cps.ncmp.api.datajobs.models.DataJobReadRequest +import org.onap.cps.ncmp.api.datajobs.models.DataJobWriteRequest +import org.onap.cps.ncmp.api.datajobs.models.DataJobMetadata +import org.onap.cps.ncmp.api.datajobs.models.ReadOperation +import org.onap.cps.ncmp.api.datajobs.models.WriteOperation import spock.lang.Specification class DataJobServiceImplSpec extends Specification{ diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImplSpec.groovy index 9907e9ab21..66fd7d88ef 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/inventory/InventoryPersistenceImplSpec.groovy @@ -37,7 +37,6 @@ import org.onap.cps.api.CpsModuleService import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle import org.onap.cps.spi.CascadeDeleteAllowed import org.onap.cps.spi.FetchDescendantsOption -import org.onap.cps.ncmp.api.impl.exception.NoAlternateIdParentFoundException import org.onap.cps.spi.exceptions.DataNodeNotFoundException import org.onap.cps.spi.model.DataNode import org.onap.cps.spi.model.ModuleDefinition @@ -303,41 +302,6 @@ class InventoryPersistenceImplSpec extends Specification { assert objectUnderTest.getCmHandleDataNodeByAlternateId('alternate id') == new DataNode() } - def 'Find cm handle parent data node using alternate ids'() { - given: 'cm handle in the registry with alternateId /a/b' - def matchingCpsPath = "/dmi-registry/cm-handles[@alternate-id='/a/b']" - mockCmHandleQueries.queryNcmpRegistryByCpsPath(matchingCpsPath, OMIT_DESCENDANTS) >> [new DataNode()] - and: 'no other cm handle' - mockCmHandleQueries.queryNcmpRegistryByCpsPath(*_) >> [] - expect: 'querying for alternate id a matching result found' - assert objectUnderTest.getCmHandleDataNodeByLongestMatchAlternateId(alternateId, '/') != null - where: 'the following parameters are used' - scenario | alternateId - 'exact match' | '/a/b' - 'exact match with trailing separator' | '/a/b/' - 'child match' | '/a/b/c' - } - - def 'Find cm handle parent data node using alternate ids mismatches'() { - given: 'cm handle in the registry with alternateId' - def matchingCpsPath = "/dmi-registry/cm-handles[@alternate-id='${cpsPath}]" - mockCmHandleQueries.queryNcmpRegistryByCpsPath(matchingCpsPath, OMIT_DESCENDANTS) >> [new DataNode()] - and: 'no other cm handle' - mockCmHandleQueries.queryNcmpRegistryByCpsPath(*_) >> [] - when: 'attempt to find alternateId' - objectUnderTest.getCmHandleDataNodeByLongestMatchAlternateId(alternateId, '/') - then: 'no alternate id found exception thrown' - def thrown = thrown(NoAlternateIdParentFoundException) - and: 'the exception has the relevant details from the error response' - assert thrown.message == 'No matching (parent) cm handle found using alternate ids' - assert thrown.details == 'cannot find a datanode with alternate id ' + alternateId - where: 'the following parameters are used' - scenario | alternateId | cpsPath - 'no match for parent only' | '/a' | '/a/b' - 'no match at all' | '/x/y/z' | '/a/b' - 'no match with trailing separator' | '/c/d/' | '/c/d' - } - def 'Attempt to get non existing cm handle data node by alternate id'() { given: 'query service is invoked and returns empty collection of data nodes' mockCmHandleQueries.queryNcmpRegistryByCpsPath(*_) >> [] diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/utils/AlternateIdMatcherSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/utils/AlternateIdMatcherSpec.groovy new file mode 100644 index 0000000000..720a7e7e9f --- /dev/null +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/utils/AlternateIdMatcherSpec.groovy @@ -0,0 +1,66 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2024 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.ncmp.utils + +import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence +import org.onap.cps.ncmp.exceptions.NoAlternateIdMatchFoundException +import org.onap.cps.spi.exceptions.DataNodeNotFoundException +import org.onap.cps.spi.model.DataNode +import spock.lang.Specification + +class AlternateIdMatcherSpec extends Specification { + + def mockInventoryPersistence = Mock(InventoryPersistence) + def objectUnderTest = new AlternateIdMatcher(mockInventoryPersistence) + + def setup() { + given: 'cm handle in the registry with alternate id /a/b' + mockInventoryPersistence.getCmHandleDataNodeByAlternateId('/a/b') >> new DataNode() + and: 'no other cm handle' + mockInventoryPersistence.getCmHandleDataNodeByAlternateId(_) >> { throw new DataNodeNotFoundException('', '') } + } + + def 'Finding longest alternate id matches.'() { + expect: 'querying for alternate id a matching result found' + assert objectUnderTest.getCmHandleDataNodeByLongestMatchAlternateId(targetAlternateId, '/') != null + where: 'the following parameters are used' + scenario | targetAlternateId + 'exact match' | '/a/b' + 'parent match' | '/a/b/c' + 'grand parent match' | '/a/b/c/d' + 'trailing separator match' | '/a/b/' + } + + def 'Attempt to find longest alternate id match without any matches.'() { + when: 'attempt to find alternateId' + objectUnderTest.getCmHandleDataNodeByLongestMatchAlternateId(targetAlternateId, '/') + then: 'no alternate id match found exception thrown' + def thrown = thrown(NoAlternateIdMatchFoundException) + and: 'the exception has the relevant details from the error response' + assert thrown.message == 'No matching cm handle found using alternate ids' + assert thrown.details == 'cannot find a datanode with alternate id ' + targetAlternateId + where: 'the following parameters are used' + scenario | targetAlternateId + 'no match for parent only' | '/a' + 'no match for other child' | '/a/c' + 'no match at all' | '/x/y' + } +}
\ No newline at end of file |