aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLee Anjella Macabuhay <lee.anjella.macabuhay@est.tech>2025-03-04 16:50:49 +0000
committerGerrit Code Review <gerrit@onap.org>2025-03-04 16:50:49 +0000
commitab96e052a6725ad0cc5e56ae69461c352c83551f (patch)
tree4537a4b6008a1c6fa7cda0a4ebdec57d13385cb8
parent57593cb0ba433032df49b9b185ac6fdb71c0c83d (diff)
parenteb92f7de4d1742501d8d799303208fccc98a6c06 (diff)
Merge "Improved unit test related to cm handle reference lookup"
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/utils/AlternateIdMatcherSpec.groovy32
1 files changed, 17 insertions, 15 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/utils/AlternateIdMatcherSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/utils/AlternateIdMatcherSpec.groovy
index fe7c5e3817..b59dd1a55f 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/utils/AlternateIdMatcherSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/utils/AlternateIdMatcherSpec.groovy
@@ -30,14 +30,12 @@ import org.springframework.test.context.ContextConfiguration
import spock.lang.Specification
@SpringBootTest
-@ContextConfiguration(classes = [InventoryPersistence, CpsValidatorImpl])
+@ContextConfiguration(classes = [InventoryPersistence])
class AlternateIdMatcherSpec extends Specification {
def mockInventoryPersistence = Mock(InventoryPersistence)
- def mockCpsValidator = Mock(CpsValidatorImpl)
-
- def objectUnderTest = new AlternateIdMatcher(mockInventoryPersistence, mockCpsValidator)
+ def objectUnderTest = new AlternateIdMatcher(mockInventoryPersistence, new CpsValidatorImpl())
def setup() {
given: 'cm handle in the registry with alternate id /a/b'
@@ -76,18 +74,22 @@ class AlternateIdMatcherSpec extends Specification {
'no match at all' | '/x/y'
}
- def 'Get cmHandle id from passed cmHandleReference (cmHandleId scenario)' () {
- when: 'a cmHandleCmReference is passed in'
+ def 'Get cm handle id from a cm handle reference that is a #scenario id.' () {
+ given: 'inventory persistence service confirms the reference exists as an id or not (#isExistingCmHandleId)'
+ mockInventoryPersistence.isExistingCmHandleId(cmHandleReference) >> isExistingCmHandleId
+ when: 'getting a cm handle id from the reference'
def result = objectUnderTest.getCmHandleId(cmHandleReference)
- then: 'the inventory persistence service returns a cm handle (or not)'
- mockCpsValidator.isValidName(cmHandleReference) >> existingCmHandleIdAndValidatorResponse
- mockInventoryPersistence.isExistingCmHandleId(cmHandleReference) >> existingCmHandleIdAndValidatorResponse
- mockInventoryPersistence.getYangModelCmHandleByAlternateId(cmHandleReference) >> alternateIdGetResponse
- and: 'correct result is returned'
- assert result == cmHandleReference
+ then: 'a call to find the cm handle by alternate id is only made when needed'
+ if (isExistingCmHandleId) {
+ 0 * mockInventoryPersistence.getYangModelCmHandleByAlternateId(*_)
+ } else {
+ 1 * mockInventoryPersistence.getYangModelCmHandleByAlternateId(cmHandleReference) >> new YangModelCmHandle(id: 'ch-id-2')
+ }
+ and: 'the expected cm handle id is returned'
+ assert result == expectedCmHandleId
where: 'the following parameters are used'
- cmHandleReference | existingCmHandleIdAndValidatorResponse | alternateIdGetResponse
- 'ch-1' | true | null
- 'alt=1' | false | new YangModelCmHandle(id: 'alt=1')
+ scenario | cmHandleReference | isExistingCmHandleId || expectedCmHandleId
+ 'standard' | 'ch-id-1' | true || 'ch-id-1'
+ 'alternate' | 'alt-id=1' | false || 'ch-id-2'
}
}