- void mockResponses() {
- def pNFDemo1 = new DataNode(xpath: '/dmi-registry/cm-handles[@id=\'PNFDemo1\']', leaves: ['id':'PNFDemo1'])
- def pNFDemo2 = new DataNode(xpath: '/dmi-registry/cm-handles[@id=\'PNFDemo2\']', leaves: ['id':'PNFDemo2'])
- def pNFDemo3 = new DataNode(xpath: '/dmi-registry/cm-handles[@id=\'PNFDemo3\']', leaves: ['id':'PNFDemo3'])
- def pNFDemo4 = new DataNode(xpath: '/dmi-registry/cm-handles[@id=\'PNFDemo4\']', leaves: ['id':'PNFDemo4'])
- def dmiRegistry = new DataNode(xpath: '/dmi-registry', childDataNodes: [pNFDemo1, pNFDemo2, pNFDemo3, pNFDemo4])
-
- inventoryPersistence.queryDataNodes('//public-properties[@name=\'Contact\' and @value=\'newemailforstore@bookstore.com\']/ancestor::cm-handles')
- >> [pNFDemo1, pNFDemo2, pNFDemo4]
- inventoryPersistence.queryDataNodes('//public-properties[@name=\'wont_match\' and @value=\'wont_match\']/ancestor::cm-handles')
- >> []
- inventoryPersistence.queryDataNodes('//public-properties[@name=\'Contact2\' and @value=\'newemailforstore2@bookstore.com\']/ancestor::cm-handles')
- >> [pNFDemo4]
- inventoryPersistence.queryDataNodes('//public-properties[@name=\'Contact2\' and @value=\'\']/ancestor::cm-handles')
- >> []
- inventoryPersistence.queryDataNodes('//public-properties/ancestor::cm-handles')
- >> [pNFDemo1, pNFDemo2, pNFDemo3, pNFDemo4]
-
- inventoryPersistence.queryDataNodes('//cm-handles[@id=\'PNFDemo\']') >> [pNFDemo1]
- inventoryPersistence.queryDataNodes('//cm-handles[@id=\'PNFDemo2\']') >> [pNFDemo2]
- inventoryPersistence.queryDataNodes('//cm-handles[@id=\'PNFDemo3\']') >> [pNFDemo3]
- inventoryPersistence.queryDataNodes('//cm-handles[@id=\'PNFDemo4\']') >> [pNFDemo4]
-
- inventoryPersistence.getDataNode('/dmi-registry') >> dmiRegistry
-
- inventoryPersistence.getDataNode('/dmi-registry/cm-handles[@id=\'PNFDemo1\']') >> pNFDemo1
- inventoryPersistence.getDataNode('/dmi-registry/cm-handles[@id=\'PNFDemo2\']') >> pNFDemo2
- inventoryPersistence.getDataNode('/dmi-registry/cm-handles[@id=\'PNFDemo3\']') >> pNFDemo3
- inventoryPersistence.getDataNode('/dmi-registry/cm-handles[@id=\'PNFDemo4\']') >> pNFDemo4
-
- inventoryPersistence.queryAnchors(['MODULE-NAME-001']) >> [new Anchor(name: 'PNFDemo1'), new Anchor(name: 'PNFDemo2'), new Anchor(name: 'PNFDemo3')]
- inventoryPersistence.queryAnchors(['MODULE-NAME-004']) >> []
- inventoryPersistence.queryAnchors(['MODULE-NAME-003', 'MODULE-NAME-002']) >> [new Anchor(name: 'PNFDemo4')]
- inventoryPersistence.queryAnchors(['MODULE-NAME-002', 'MODULE-NAME-003']) >> [new Anchor(name: 'PNFDemo4')]
- inventoryPersistence.queryAnchors(['MODULE-NAME-004', 'MODULE-NAME-002']) >> []
- inventoryPersistence.queryAnchors(['MODULE-NAME-002', 'MODULE-NAME-004']) >> []
- inventoryPersistence.queryAnchors(['MODULE-NAME-002']) >> [new Anchor(name: 'PNFDemo2'), new Anchor(name: 'PNFDemo4')]
- inventoryPersistence.getAnchors() >> [new Anchor(name: 'PNFDemo1'), new Anchor(name: 'PNFDemo2'), new Anchor(name: 'PNFDemo3'), new Anchor(name: 'PNFDemo4')]
+
+ def 'Retrieve all CMHandleIds for empty query parameters' () {
+ given: 'We query without any parameters'
+ def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
+ and: 'the inventoryPersistence returns all four CmHandleIds'
+ mockInventoryPersistence.getDataNode(*_) >> [dmiRegistry]
+ when: 'the query executed'
+ def resultSet = objectUnderTest.queryCmHandleIdsForInventory(cmHandleQueryParameters)
+ then: 'the size of the result list equals the size of all cmHandleIds.'
+ resultSet.size() == 4
+ }
+
+ def 'Retrieve CMHandleIds when #scenario.' () {
+ given: 'a query object created with #condition'
+ def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
+ def conditionProperties = createConditionProperties(conditionName, [['some-key': 'some-value']])
+ cmHandleQueryParameters.setCmHandleQueryParameters([conditionProperties])
+ and: 'the inventoryPersistence returns different CmHandleIds'
+ partiallyMockedCmHandleQueries.queryCmHandlePublicProperties(*_) >> cmHandlesWithMatchingPublicProperties
+ partiallyMockedCmHandleQueries.queryCmHandleAdditionalProperties(*_) >> cmHandlesWithMatchingPrivateProperties
+ when: 'the query executed'
+ def result = objectUnderTestSpy.queryCmHandleIdsForInventory(cmHandleQueryParameters)
+ then: 'the expected number of results are returned.'
+ assert result.size() == expectedCmHandleIdsSize
+ where: 'the following data is used'
+ scenario | conditionName | cmHandlesWithMatchingPublicProperties | cmHandlesWithMatchingPrivateProperties || expectedCmHandleIdsSize
+ 'all properties, only public matching' | 'hasAllProperties' | queryResultCmHandleMap | null || 2
+ 'all properties, no matching cm handles' | 'hasAllProperties' | [:] | [:] || 0
+ 'additional properties, some matching cm handles' | 'hasAllAdditionalProperties' | [:] | queryResultCmHandleMap || 2
+ 'additional properties, no matching cm handles' | 'hasAllAdditionalProperties' | null | [:] || 0
+ }
+
+ def 'Retrieve CMHandleIds by different DMI properties with #scenario.' () {
+ given: 'a query object created with dmi plugin as condition'
+ def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
+ def conditionProperties = createConditionProperties('cmHandleWithDmiPlugin', [['some-key': 'some-value']])
+ cmHandleQueryParameters.setCmHandleQueryParameters([conditionProperties])
+ and: 'the inventoryPersistence returns different CmHandleIds'
+ partiallyMockedCmHandleQueries.getCmHandlesByDmiPluginIdentifier(*_) >> cmHandleQueryResult
+ when: 'the query executed'
+ def result = objectUnderTestSpy.queryCmHandleIdsForInventory(cmHandleQueryParameters)
+ then: 'the expected number of results are returned.'
+ assert result.size() == expectedCmHandleIdsSize
+ where: 'the following data is used'
+ scenario | cmHandleQueryResult || expectedCmHandleIdsSize
+ 'some matches' | queryResultCmHandleMap.values() || 2
+ 'no matches' | [] || 0
+ }
+
+ static def createCmHandleMap(cmHandleIds) {
+ def cmHandleMap = [:]
+ cmHandleIds.each{ cmHandleMap[it] = new NcmpServiceCmHandle(cmHandleId : it) }
+ return cmHandleMap
+ }
+
+ def createConditionProperties(String conditionName, List<Map<String, String>> conditionParameters) {
+ return new ConditionProperties(conditionName : conditionName, conditionParameters : conditionParameters)
+ }
+
+ def static createDataNodeList(dataNodeIds) {
+ def dataNodes =[]
+ dataNodeIds.each{ dataNodes << new DataNode(xpath: "/dmi-registry/cm-handles[@id='${it}']", leaves: ['id':it]) }
+ return dataNodes