import io.cloudevents.core.builder.CloudEventBuilder
import org.apache.kafka.clients.consumer.ConsumerRecord
import org.onap.cps.ncmp.api.impl.events.cmsubscription.model.CmNotificationSubscriptionStatus
+import org.onap.cps.ncmp.api.impl.events.cmsubscription.model.DmiCmNotificationSubscriptionDetails
import org.onap.cps.ncmp.api.impl.events.cmsubscription.service.CmNotificationSubscriptionPersistenceService
import org.onap.cps.ncmp.api.impl.inventory.InventoryPersistence
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle
assert testCache.containsKey(subscriptionId)
}
+ def 'Get cache entry via subscription id'() {
+ given: 'the cache contains value for some-id'
+ testCache.put('some-id',[:])
+ when: 'the get method is called'
+ def result = objectUnderTest.get('some-id')
+ then: 'correct value is returned as expected'
+ assert result == [:]
+ }
+
+ def 'Remove accepted and rejected entries from cache via subscription id'() {
+ given: 'a map as the value for cache entry for some-id'
+ def testMap = [:]
+ testMap.put("dmi-1",
+ new DmiCmNotificationSubscriptionDetails([],CmNotificationSubscriptionStatus.ACCEPTED))
+ testMap.put("dmi-2",
+ new DmiCmNotificationSubscriptionDetails([],CmNotificationSubscriptionStatus.REJECTED))
+ testMap.put("dmi-3",
+ new DmiCmNotificationSubscriptionDetails([],CmNotificationSubscriptionStatus.PENDING))
+ testCache.put("test-id", testMap)
+ assert testCache.get("test-id").size() == 3
+ when: 'the method to remove accepted and rejected entries for test-id is called'
+ objectUnderTest.removeAcceptedAndRejectedDmiCmNotificationSubscriptionEntries("test-id")
+ then: 'all entries with status accepted/rejected are no longer present for test-id'
+ testCache.get("test-id").each { key, testResultMap ->
+ assert testResultMap.cmNotificationSubscriptionStatus != CmNotificationSubscriptionStatus.ACCEPTED
+ || testResultMap.cmNotificationSubscriptionStatus != CmNotificationSubscriptionStatus.REJECTED
+ }
+ and: 'the size of the map for cache entry test-id is as expected'
+ assert testCache.get("test-id").size() == 1
+ }
+
def 'Create map for DMI cm notification subscription per DMI service name'() {
given: 'list of predicates from the create subscription event'
def predicates = cmNotificationSubscriptionNcmpInEvent.getData().getPredicates()
assert resultMapForDmi2.dmiCmNotificationSubscriptionPredicates[1].targetCmHandleIds == ['ch4'].toSet()
and: 'the list of xpath for each is correct'
assert resultMapForDmi1.dmiCmNotificationSubscriptionPredicates[0].xpaths
- && resultMapForDmi2.dmiCmNotificationSubscriptionPredicates[0].xpaths == ['/x1/y1','x2/y2'].toSet()
+ && resultMapForDmi2.dmiCmNotificationSubscriptionPredicates[0].xpaths == ['/x1/y1','x2/y2'].toSet()
assert resultMapForDmi1.dmiCmNotificationSubscriptionPredicates[1].xpaths
- && resultMapForDmi2.dmiCmNotificationSubscriptionPredicates[1].xpaths == ['/x3/y3','x4/y4'].toSet()
+ && resultMapForDmi2.dmiCmNotificationSubscriptionPredicates[1].xpaths == ['/x3/y3','x4/y4'].toSet()
}
def 'Get map for cm handle IDs by DMI service name'() {
}
def 'Persist Cache into database per dmi'() {
- given: 'populate cache'
+ given: 'populated cache'
def predicates = cmNotificationSubscriptionNcmpInEvent.getData().getPredicates()
def subscriptionId = cmNotificationSubscriptionNcmpInEvent.getData().getSubscriptionId()
objectUnderTest.add(subscriptionId, predicates)
4 * mockCmNotificationSubscriptionPersistenceService.addCmNotificationSubscription(_,_,_,subscriptionId)
}
+ def 'Remove subscription from database per dmi'() {
+ given: 'populated cache'
+ def predicates = cmNotificationSubscriptionNcmpInEvent.getData().getPredicates()
+ def subscriptionId = cmNotificationSubscriptionNcmpInEvent.getData().getSubscriptionId()
+ objectUnderTest.add(subscriptionId, predicates)
+ when: 'subscription is persisted in database'
+ objectUnderTest.removeFromDatabasePerDmi(subscriptionId,'dmi-1')
+ then: 'persistence service is called the correct number of times per dmi'
+ 4 * mockCmNotificationSubscriptionPersistenceService.removeCmNotificationSubscription(_,_,_,subscriptionId)
+ }
+
def setUpTestEvent(){
def jsonData = TestUtils.getResourceFileContent('cmSubscription/cmNotificationSubscriptionNcmpInEvent.json')
def testEventSent = jsonObjectMapper.convertJsonString(jsonData, CmNotificationSubscriptionNcmpInEvent.class)
def testCloudEventSent = CloudEventBuilder.v1()
- .withData(objectMapper.writeValueAsBytes(testEventSent))
- .withId('subscriptionCreated')
- .withType('subscriptionCreated')
- .withSource(URI.create('some-resource'))
- .withExtension('correlationid', 'test-cmhandle1').build()
+ .withData(objectMapper.writeValueAsBytes(testEventSent))
+ .withId('subscriptionCreated')
+ .withType('subscriptionCreated')
+ .withSource(URI.create('some-resource'))
+ .withExtension('correlationid', 'test-cmhandle1').build()
def consumerRecord = new ConsumerRecord<String, CloudEvent>('topic-name', 0, 0, 'event-key', testCloudEventSent)
def cloudEvent = consumerRecord.value()
def initialiseMockInventoryPersistenceResponses(){
mockInventoryPersistence.getYangModelCmHandles(['ch1','ch2'])
- >> [yangModelCmHandle1, yangModelCmHandle2]
+ >> [yangModelCmHandle1, yangModelCmHandle2]
mockInventoryPersistence.getYangModelCmHandles(['ch3','ch4'])
- >> [yangModelCmHandle3, yangModelCmHandle4]
+ >> [yangModelCmHandle3, yangModelCmHandle4]
}
}
\ No newline at end of file