diff options
Diffstat (limited to 'cps-ncmp-service/src/test')
2 files changed, 22 insertions, 6 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 6642532ac2..b976ff4284 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 @@ -37,8 +37,8 @@ class AlternateIdCheckerSpec extends Specification { 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' - mockInventoryPersistenceService.getCmHandleDataNodeByAlternateId(_) >> - { args -> altAlreadyInDb.contains(args[0]) ? new DataNode() : throwDataNodeNotFoundException() } + mockInventoryPersistenceService.getCmHandleDataNodesByAlternateIds(_ as Collection<String>) >> + { args -> args[0].stream().filter(altId -> altAlreadyInDb.contains(altId)).map(altId -> new DataNode(leaves: ["alternate-id": altId])).toList() } when: 'the batch of new cm handles is checked' def result = objectUnderTest.getIdsOfCmHandlesWithRejectedAlternateId(batch, AlternateIdChecker.Operation.CREATE) then: 'the result contains ids of the rejected cm handles' @@ -57,8 +57,8 @@ class AlternateIdCheckerSpec extends Specification { 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(_) >> - { args -> altAlreadyInDb.equals(args[0]) ? new DataNode() : throwDataNodeNotFoundException() } + mockInventoryPersistenceService.getCmHandleDataNodesByAlternateIds(_ as Collection<String>) >> + { args -> args[0].stream().filter(altId -> altAlreadyInDb == altId).map(altId -> new DataNode(leaves: ["alternate-id": altId])).toList() } mockInventoryPersistenceService.getYangModelCmHandle(_) >> new YangModelCmHandle(alternateId: altAlreadyInDb) when: 'the batch of cm handle updates is checked' def result = objectUnderTest.getIdsOfCmHandlesWithRejectedAlternateId(batch, AlternateIdChecker.Operation.UPDATE) @@ -75,7 +75,7 @@ class AlternateIdCheckerSpec extends Specification { 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.getCmHandleDataNodesByAlternateIds(_) >> [] mockInventoryPersistenceService.getYangModelCmHandle(_) >> { throwDataNodeNotFoundException() } when: 'the batch of cm handle updates is checked' def result = objectUnderTest.getIdsOfCmHandlesWithRejectedAlternateId(batch, AlternateIdChecker.Operation.UPDATE) diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy index e60bacbdc5..fdf12a880d 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/impl/inventory/InventoryPersistenceImplSpec.groovy @@ -297,7 +297,7 @@ class InventoryPersistenceImplSpec extends Specification { 1 * mockCpsDataService.getDataNodes(NCMP_DATASPACE_NAME, NCMP_DMI_REGISTRY_ANCHOR, expectedXPath, INCLUDE_ALL_DESCENDANTS) } - def 'Get cm handle data node'() { + def 'Get cm handle data node by alternate id'() { given: 'expected xPath to get cmHandle data node' def expectedXPath = '/dmi-registry/cm-handles[@alternate-id=\'alternate id\']' and: 'query service is invoked with expected xpath' @@ -316,6 +316,22 @@ class InventoryPersistenceImplSpec extends Specification { assert thrownException.getMessage().contains('DataNode not found') } + def 'Get multiple cm handle data nodes by alternate ids'() { + given: 'expected xPath to get cmHandle data node' + def expectedXPath = "/dmi-registry/cm-handles[@alternate-id='A' or @alternate-id='B']" + when: 'getting the cm handle data node' + objectUnderTest.getCmHandleDataNodesByAlternateIds(['A', 'B']) + then: 'query service is invoked with expected xpath' + 1 * mockCmHandleQueries.queryNcmpRegistryByCpsPath(expectedXPath, OMIT_DESCENDANTS) + } + + def 'Get multiple cm handle data nodes by alternate ids, passing empty collection'() { + when: 'getting the cm handle data node for no alternate ids' + objectUnderTest.getCmHandleDataNodesByAlternateIds([]) + then: 'query service is not invoked' + 0 * mockCmHandleQueries.queryNcmpRegistryByCpsPath(_, _) + } + def 'Get CM handles that has given module names'() { when: 'the method to get cm handles is called' objectUnderTest.getCmHandleIdsWithGivenModules(['sample-module-name']) |