aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/test/groovy/org/onap
diff options
context:
space:
mode:
authordanielhanrahan <daniel.hanrahan@est.tech>2024-08-15 14:33:39 +0100
committerdanielhanrahan <daniel.hanrahan@est.tech>2024-08-20 14:47:06 +0100
commit73f044beb1fe4bd2fd30fb71357c918ab39dda38 (patch)
tree805ffc1c6bcb17f783684993fbfe36830616c5de /cps-ncmp-service/src/test/groovy/org/onap
parentc5709a649f6dce392816a69d2c481d9b7680815a (diff)
Refactoring alternate ID checker (CPS-2366 #1)
Issue-ID: CPS-2366 Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech> Change-Id: I07228a130ebdab0e2782e54255b5e8cc34c8d77e
Diffstat (limited to 'cps-ncmp-service/src/test/groovy/org/onap')
-rw-r--r--cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/AlternateIdCheckerSpec.groovy68
1 files changed, 23 insertions, 45 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/AlternateIdCheckerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/AlternateIdCheckerSpec.groovy
index b086e58de8..6642532ac2 100644
--- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/AlternateIdCheckerSpec.groovy
+++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/AlternateIdCheckerSpec.groovy
@@ -24,50 +24,16 @@ import org.onap.cps.ncmp.api.inventory.models.NcmpServiceCmHandle
import org.onap.cps.ncmp.impl.inventory.models.YangModelCmHandle
import org.onap.cps.spi.exceptions.DataNodeNotFoundException
import org.onap.cps.spi.model.DataNode
-import org.onap.cps.spi.model.DataNodeBuilder
import spock.lang.Specification
class AlternateIdCheckerSpec extends Specification {
def mockInventoryPersistenceService = Mock(InventoryPersistence)
- def someDataNode = new DataNodeBuilder().build()
- def dataNodeFoundException = new DataNodeNotFoundException('', '')
def objectUnderTest = new AlternateIdChecker(mockInventoryPersistenceService)
- def 'Check new cm handle with new alternate id.'() {
- given: 'inventory persistence can not find cm handle id'
- mockInventoryPersistenceService.getYangModelCmHandle('ch 1') >> {throw dataNodeFoundException}
- and: 'inventory persistence can not find alternate id'
- mockInventoryPersistenceService.getCmHandleDataNodeByAlternateId('alternate id') >> {throw dataNodeFoundException}
- expect: 'mapping can be added'
- assert objectUnderTest.canApplyAlternateId('ch 1', 'alternate id')
- }
-
- def 'Check new cm handle with used alternate id.'() {
- given: 'inventory persistence can not find cm handle id'
- mockInventoryPersistenceService.getYangModelCmHandle('ch 1') >> {throw dataNodeFoundException}
- and: 'inventory persistence can find alternate id'
- mockInventoryPersistenceService.getCmHandleDataNodeByAlternateId('alternate id') >> { someDataNode }
- expect: 'mapping can not be added'
- assert objectUnderTest.canApplyAlternateId('ch 1', 'alternate id') == false
- }
-
- def 'Check for existing cm handle with #currentAlternateId.'() {
- given: 'a cm handle with the #currentAlternateId'
- def yangModelCmHandle = new YangModelCmHandle(alternateId: currentAlternateId)
- and: 'inventory service finds the cm handle'
- mockInventoryPersistenceService.getYangModelCmHandle('my cm handle') >> yangModelCmHandle
- expect: 'add mapping returns expected result'
- assert canAdd == objectUnderTest.canApplyAlternateId('my cm handle', 'same alternate id')
- where: 'following alternate ids is used'
- currentAlternateId || canAdd
- 'same alternate id' || true
- 'other alternate id' || false
- }
-
def 'Check a batch of created cm handles with #scenario.'() {
- given: 'a batch of 2 new cm handles alternate id ids #alt1 and #alt2'
+ given: 'a batch of 2 new cm handles with alternate ids #alt1 and #alt2'
def batch = [new NcmpServiceCmHandle(cmHandleId: 'ch-1', alternateId: alt1),
new NcmpServiceCmHandle(cmHandleId: 'ch-2', alternateId: alt2)]
and: 'the database already contains cm handle(s) with these alternate ids: #altAlreadyInDb'
@@ -78,16 +44,17 @@ class AlternateIdCheckerSpec extends Specification {
then: 'the result contains ids of the rejected cm handles'
assert result == expectedRejectedCmHandleIds
where: 'the following alternate ids are used'
- scenario | alt1 | alt2 | altAlreadyInDb || expectedRejectedCmHandleIds
- 'blank alternate ids' | '' | '' | ['dont matter'] || []
- 'null alternate ids' | null | null | ['dont matter'] || []
- 'new alternate ids' | 'fdn1' | 'fdn2' | ['other fdn'] || []
- 'one already used alternate id' | 'fdn1' | 'fdn2' | ['fdn1'] || ['ch-1']
- 'duplicate alternate id in batch' | 'fdn1' | 'fdn1' | ['dont matter'] || ['ch-2']
+ scenario | alt1 | alt2 | altAlreadyInDb || expectedRejectedCmHandleIds
+ 'blank alternate ids' | '' | '' | ['dont matter'] || []
+ 'null alternate ids' | null | null | ['dont matter'] || []
+ 'new alternate ids' | 'fdn1' | 'fdn2' | ['other fdn'] || []
+ 'one already used alternate id' | 'fdn1' | 'fdn2' | ['fdn1'] || ['ch-1']
+ 'two already used alternate ids' | 'fdn1' | 'fdn2' | ['fdn1', 'fdn2'] || ['ch-1', 'ch-2']
+ 'duplicate alternate id in batch' | 'fdn1' | 'fdn1' | ['dont matter'] || ['ch-2']
}
def 'Check a batch of updates to existing cm handles with #scenario.'() {
- given: 'a batch of 1 existing cm handle update alternate id to #proposedAlt'
+ given: 'a batch of 1 existing cm handle to update alternate id to #proposedAlt'
def batch = [new NcmpServiceCmHandle(cmHandleId: 'ch-1', alternateId: proposedAlt)]
and: 'the database already contains a cm handle with alternate id: #altAlreadyInDb'
mockInventoryPersistenceService.getCmHandleDataNodeByAlternateId(_) >>
@@ -104,9 +71,20 @@ class AlternateIdCheckerSpec extends Specification {
'used different alternate id' | 'otherFdn' | 'fdn1' || ['ch-1']
}
- def throwDataNodeNotFoundException() {
- // cannot 'return' an exception in conditional stub behavior, so hence a method call that will always throw this exception
- throw dataNodeFoundException
+ def 'Check update of non-existing cm handle.'() {
+ given: 'a batch of 1 non-existing cm handle to update alternate id'
+ def batch = [new NcmpServiceCmHandle(cmHandleId: 'non-existing', alternateId: 'altId')]
+ and: 'the database does not contain any cm handles'
+ mockInventoryPersistenceService.getCmHandleDataNodeByAlternateId(_) >> { throwDataNodeNotFoundException() }
+ mockInventoryPersistenceService.getYangModelCmHandle(_) >> { throwDataNodeNotFoundException() }
+ when: 'the batch of cm handle updates is checked'
+ def result = objectUnderTest.getIdsOfCmHandlesWithRejectedAlternateId(batch, AlternateIdChecker.Operation.UPDATE)
+ then: 'the result has no rejected cm handles'
+ assert result.empty
+ }
+
+ static throwDataNodeNotFoundException() {
+ throw new DataNodeNotFoundException('', '')
}
}