aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToineSiebelink <toine.siebelink@est.tech>2025-03-04 15:12:32 +0000
committerToineSiebelink <toine.siebelink@est.tech>2025-03-04 16:25:22 +0000
commiteb92f7de4d1742501d8d799303208fccc98a6c06 (patch)
tree2424fbd9be7198da4090ea2a4a53956cf8b1d102
parent038a8f0d31cf139350dca4fa9800e07d8e2e28d6 (diff)
Improved unit test related to cm handle reference lookup
Issue-ID: CPS-2605 Change-Id: Iac36b4838f640fa0bb4bf6bcc41f8a72e8c3bd8e Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
-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'
}
}