- scenario | alt1 | alt2 | altAlreadyInDb || acceptCh1 | acceptCh2
- 'no alternate ids' | '' | '' | ['dont matter'] || true | true
- 'new alternate ids' | 'fdn1' | 'fdn2' | ['other fdn'] || true | true
- 'one already used alternate id' | 'fdn1' | 'fdn2' | ['fdn1'] || false | true
- 'two already used alternate ids' | 'fdn1' | 'fdn2' | ['fdn1','fdn2'] || false | false
- 'duplicate alternate id in batch' | 'fdn1' | 'fdn1' | ['dont matter'] || true | false
+ scenario | alt1 | alt2 | altAlreadyInDb || expectedRejectedCmHandleIds
+ 'no alternate ids' | '' | '' | ['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']
+ }
+
+ 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'
+ def batch = [new NcmpServiceCmHandle(cmHandleId: 'ch-1', alternateId: proposedAlt)]
+ and: 'the database already contains a cm handle with alternate id: #altAlreadyInDb'
+ mockInventoryPersistenceService.getCmHandleDataNodeByAlternateId(_) >>
+ { args -> altAlreadyInDb.equals(args[0]) ? new DataNode() : throwDataNodeNotFoundException() }
+ mockInventoryPersistenceService.getYangModelCmHandle(_) >> new YangModelCmHandle(alternateId: altAlreadyInDb)
+ when: 'the batch of cm handle updates is checked'
+ def result = objectUnderTest.getIdsOfCmHandlesWithRejectedAlternateId(batch, AlternateIdChecker.Operation.UPDATE)
+ then: 'the result contains ids of the rejected cm handles'
+ assert result == expectedRejectedCmHandleIds
+ where: 'the following parameters are used'
+ scenario | proposedAlt | altAlreadyInDb || expectedRejectedCmHandleIds
+ 'no alternate id' | 'fdn1' | '' || []
+ 'used the same alternate id' | 'fdn1' | 'fdn1' || []
+ 'used different alternate id' | 'otherFdn' | 'fdn1' || ['ch-1']