- def 'Alternate ID removed from cache when persisting fails.'() {
- given: 'an existing data node and an update request with an alternate id'
- def ncmpServiceCmHandle = new NcmpServiceCmHandle(cmHandleId: cmHandleId, alternateId: 'alt-1')
- DataNode existingCmHandleDataNode = new DataNode(xpath: cmHandleXpath, leaves: ['id': cmHandleId, 'alternate-id': null])
- and: 'an applicable alternate id for the cm handle'
- mockAlternateIdChecker.canApplyAlternateId(cmHandleId, '','alt-1') >> true
- and: 'but an exception occurs while saving'
- def originalException = new NullPointerException('some exception')
- mockCpsDataService.updateNodeLeaves(*_) >> { throw originalException }
- when: 'updating of alternate id called'
- objectUnderTest.updateAlternateId(existingCmHandleDataNode, ncmpServiceCmHandle)
- then: 'the original exception is thrown up'
- def thrownException = thrown(NullPointerException)
- assert thrownException == originalException
+ def 'Update with rejected alternate id.'() {
+ given: 'cm handles request'
+ def updatedNcmpServiceCmHandles = [new NcmpServiceCmHandle(cmHandleId: cmHandleId, alternateId: 'alt-1')]
+ and: 'a data node found'
+ def dataNode = new DataNode(xpath: cmHandleXpath, leaves: ['id': cmHandleId, 'alternate-id': 'alt-1'])
+ mockInventoryPersistence.getCmHandleDataNodeByCmHandleId(cmHandleId) >> [dataNode]
+ when: 'attempt to update the cm handle'
+ def response = objectUnderTest.updateCmHandleProperties(updatedNcmpServiceCmHandles)
+ then: 'the update is NOT delegated to cps data service'
+ 0 * mockCpsDataService.updateNodeLeaves(*_)
+ and: 'the alternate id checker rejects the given cm handle (override default setup behavior)'
+ mockAlternateIdChecker.getIdsOfCmHandlesWithRejectedAlternateId(*_) >> [cmHandleId]
+ and: 'the response shows a failure for the given cm handle id'
+ assert response[0].status == Status.FAILURE
+ assert response[0].cmHandle == cmHandleId