X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=cps-ncmp-service%2Fsrc%2Ftest%2Fgroovy%2Forg%2Fonap%2Fcps%2Fncmp%2Fapi%2Fimpl%2Futils%2FAlternateIdCheckerSpec.groovy;h=0eabaa1d28c3f69eab7c619abf6e96b94663942e;hb=8e6218198950381dff5b028ac6760238f91755f9;hp=f41fd6cdf335e257a4a5d99d2f238d8829e6d958;hpb=3c8eaa8624c2bac85745f8d547d7aac8a9164c6e;p=cps.git diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/AlternateIdCheckerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/AlternateIdCheckerSpec.groovy index f41fd6cdf..0eabaa1d2 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/AlternateIdCheckerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/utils/AlternateIdCheckerSpec.groovy @@ -20,7 +20,6 @@ package org.onap.cps.ncmp.api.impl.utils - import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle @@ -68,25 +67,41 @@ class AlternateIdCheckerSpec extends Specification { 'other alternate id' || false } - def 'Check a batch of NEW cm handles with #scenario.'() { + def 'Check a batch of created cm handles with #scenario.'() { given: 'a batch of 2 new cm handles alternate id 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: #alreadyinDb' + and: 'the database already contains cm handle(s) with these alternate ids: #altAlreadyInDb' mockInventoryPersistenceService.getCmHandleDataNodeByAlternateId(_) >> { args -> altAlreadyInDb.contains(args[0]) ? new DataNode() : throwDataNodeNotFoundException() } when: 'the batch of new cm handles is checked' - def result = objectUnderTest.getIdsOfCmHandlesWithAcceptableAlternateId(batch) - then: 'the result only contains the ids of the acceptable cm handles' - assert result.contains('ch-1') == acceptCh1 - assert result.contains('ch-2') == acceptCh2 + def result = objectUnderTest.getIdsOfCmHandlesWithRejectedAlternateId(batch, AlternateIdChecker.Operation.CREATE) + then: 'the result contains ids of the rejected cm handles' + assert result == expectedRejectedCmHandleIds where: 'the following alternate ids are used' - 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'] } def throwDataNodeNotFoundException() {