* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.impl.event.avc;
+package org.onap.cps.ncmp.api.impl.config.embeddedcache;
import com.hazelcast.config.MapConfig;
import com.hazelcast.map.IMap;
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.impl.event.avc;
+package org.onap.cps.ncmp.api.impl.events.avcsubscription;
import com.hazelcast.map.IMap;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.ncmp.api.impl.events.avcsubscription.SubscriptionEventResponseOutcome;
@Slf4j
@RequiredArgsConstructor
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.common.header.Headers;
-import org.onap.cps.ncmp.api.impl.event.avc.ForwardedSubscriptionEventCacheConfig;
-import org.onap.cps.ncmp.api.impl.event.avc.ResponseTimeoutTask;
+import org.onap.cps.ncmp.api.impl.config.embeddedcache.ForwardedSubscriptionEventCacheConfig;
import org.onap.cps.ncmp.api.impl.events.EventsPublisher;
import org.onap.cps.ncmp.api.impl.utils.DmiServiceNameOrganizer;
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.impl.event.avc;
+package org.onap.cps.ncmp.api.impl.events.avcsubscription;
import com.hazelcast.map.IMap;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
-import org.onap.cps.ncmp.api.impl.events.avcsubscription.SubscriptionEventResponseMapper;
-import org.onap.cps.ncmp.api.impl.events.avcsubscription.SubscriptionEventResponseOutcome;
+import org.onap.cps.ncmp.api.impl.config.embeddedcache.ForwardedSubscriptionEventCacheConfig;
import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionPersistence;
import org.onap.cps.ncmp.api.impl.yangmodels.YangModelSubscriptionEvent;
import org.onap.cps.ncmp.api.models.SubscriptionEventResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.common.header.Headers;
import org.apache.kafka.common.header.internals.RecordHeaders;
-import org.onap.cps.ncmp.api.impl.event.avc.SubscriptionOutcomeMapper;
import org.onap.cps.ncmp.api.impl.events.EventsPublisher;
import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionPersistence;
import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionStatus;
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.impl.event.avc;
+package org.onap.cps.ncmp.api.impl.events.avcsubscription;
import java.util.List;
import java.util.Map;
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.impl.event.avc
+package org.onap.cps.ncmp.api.impl.config.embeddedcache
import com.hazelcast.config.Config
import com.hazelcast.core.Hazelcast
0 * mockForwardedSubscriptionEventCache.put("SCO-9989752cm-subscription-001", ["DMIName1", "DMIName2"] as Set)
and: 'the event is forwarded twice with the CMHandle private properties and provides a valid listenable future'
0 * mockSubscriptionEventPublisher.publishEvent("ncmp-dmi-cm-avc-subscription-DMIName1", "SCO-9989752-cm-subscription-001-DMIName1",
- subscriptionEvent -> {
+ consumerRecord.headers(),subscriptionEvent -> {
Map targets = subscriptionEvent.getEvent().getPredicates().getTargets().get(0)
targets["CMHandle1"] == ["shape":"circle"]
targets["CMHandle2"] == ["shape":"square"]
}
)
0 * mockSubscriptionEventPublisher.publishEvent("ncmp-dmi-cm-avc-subscription-DMIName2", "SCO-9989752-cm-subscription-001-DMIName2",
- subscriptionEvent -> {
+ consumerRecord.headers(),subscriptionEvent -> {
Map targets = subscriptionEvent.getEvent().getPredicates().getTargets().get(0)
targets["CMHandle3"] == ["shape":"triangle"]
}
0 * mockForwardedSubscriptionEventCache.get(_)
and: 'the subscription id is removed from the event cache map returning the asynchronous blocking variable'
0 * mockForwardedSubscriptionEventCache.remove("SCO-9989752cm-subscription-001") >> {block.set(_)}
+ and: 'subscription outcome has been sent'
+ 1 * mockSubscriptionEventResponseOutcome.sendResponse('SCO-9989752', 'cm-subscription-001', true)
}
static def createYangModelCmHandleWithDmiProperty(id, dmiId,propertyName, propertyValue) {
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.impl.event.avc
+package org.onap.cps.ncmp.api.impl.events.avcsubscription
import com.fasterxml.jackson.databind.ObjectMapper
import com.hazelcast.map.IMap
import org.apache.kafka.clients.consumer.ConsumerRecord
-import org.onap.cps.ncmp.api.impl.events.avcsubscription.SubscriptionEventResponseMapper
-import org.onap.cps.ncmp.api.impl.events.avcsubscription.SubscriptionEventResponseOutcome
import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionPersistenceImpl
import org.onap.cps.ncmp.api.kafka.MessagingBaseSpec
import org.onap.cps.ncmp.api.models.SubscriptionEventResponse
def 'Consume Subscription Event Response where all DMIs have responded'() {
given: 'a subscription event response and notifications are enabled'
- objectUnderTest.notificationFeatureEnabled = true
+ objectUnderTest.notificationFeatureEnabled = isNotificationFeatureEnabled
and: 'subscription model loader is enabled'
objectUnderTest.subscriptionModelLoaderEnabled = true
when: 'the valid event is consumed'
and: 'the subscription event is removed from the map'
1 * mockForwardedSubscriptionEventCache.remove('some-client-idsome-subscription-name')
and: 'a response outcome has been created'
- 1 * mockSubscriptionEventResponseOutcome.sendResponse('some-client-id', 'some-subscription-name', true)
+ numberOfExpectedCallToSendResponse * mockSubscriptionEventResponseOutcome.sendResponse('some-client-id', 'some-subscription-name', isFullOutcomeResponse)
+ where: 'the following values are used'
+ scenario | isNotificationFeatureEnabled | isFullOutcomeResponse || numberOfExpectedCallToSendResponse
+ 'Response sent' | true | true || 1
+ 'Response not sent' | true | false || 0
+ 'Response not sent' | false | true || 0
+ 'Response not sent' | false | false || 0
}
def 'Consume Subscription Event Response where another DMI has not yet responded'() {
and: 'a response outcome has not been created'
0 * mockSubscriptionEventResponseOutcome.sendResponse(*_)
}
+
+ def 'Update subscription event when the model loader flag is enabled'() {
+ given: 'subscription model loader is enabled as per #scenario'
+ objectUnderTest.subscriptionModelLoaderEnabled = isSubscriptionModelLoaderEnabled
+ when: 'the valid event is consumed'
+ objectUnderTest.consumeSubscriptionEventResponse(consumerRecord)
+ then: 'the forwarded subscription event cache does not return dmiName for the subscription create event'
+ 1 * mockForwardedSubscriptionEventCache.containsKey('some-client-idsome-subscription-name') >> false
+ and: 'the mapper returns yang model subscription event with #numberOfExpectedCall'
+ numberOfExpectedCall * mockSubscriptionEventResponseMapper.toYangModelSubscriptionEvent(_)
+ and: 'subscription event has been updated into DB with #numberOfExpectedCall'
+ numberOfExpectedCall * mockSubscriptionPersistence.saveSubscriptionEvent(_)
+ where: 'the following values are used'
+ scenario | isSubscriptionModelLoaderEnabled || numberOfExpectedCall
+ 'The event is updated' | true || 1
+ 'The event is not updated' | false || 0
+ }
}
import com.fasterxml.jackson.databind.ObjectMapper
import org.mapstruct.factory.Mappers
-import org.onap.cps.ncmp.api.impl.event.avc.SubscriptionOutcomeMapper
import org.onap.cps.ncmp.api.impl.events.EventsPublisher
import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionPersistence
import org.onap.cps.ncmp.api.impl.utils.DataNodeBaseSpec
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
-import org.testcontainers.shaded.org.bouncycastle.crypto.engines.EthereumIESEngine
@SpringBootTest(classes = [ObjectMapper, JsonObjectMapper, SubscriptionOutcomeMapper, SubscriptionEventResponseOutcome])
class SubscriptionEventResponseOutcomeSpec extends DataNodeBaseSpec {
when: 'a response is generated'
def result = objectUnderTest.generateResponse('some-client-id', 'some-subscription-name', isFullOutcomeResponse)
then: 'the result will have the same values as same as in dataNode4'
- result.eventType == eventType
+ result.eventType == expectedEventType
result.getEvent().getSubscription().getClientID() == 'some-client-id'
result.getEvent().getSubscription().getName() == 'some-subscription-name'
result.getEvent().getPredicates().getPendingTargets() == ['CMHandle3']
result.getEvent().getPredicates().getRejectedTargets() == ['CMHandle1']
result.getEvent().getPredicates().getAcceptedTargets() == ['CMHandle2']
where: 'the following values are used'
- scenario | isFullOutcomeResponse || eventType
+ scenario | isFullOutcomeResponse || expectedEventType
'is full outcome' | true || SubscriptionEventOutcome.EventType.COMPLETE_OUTCOME
'is partial outcome' | false || SubscriptionEventOutcome.EventType.PARTIAL_OUTCOME
}
and: 'an outcome event'
def jsonData = TestUtils.getResourceFileContent('avcSubscriptionOutcomeEvent.json')
def eventOutcome = jsonObjectMapper.convertJsonString(jsonData, SubscriptionEventOutcome.class)
- eventOutcome.setEventType(eventType)
+ eventOutcome.setEventType(expectedEventType)
when: 'a subscription outcome message formed'
def result = objectUnderTest.formSubscriptionOutcomeMessage(cmHandleIdToStatus, 'SCO-9989752',
'cm-subscription-001', isFullOutcomeResponse)
then: 'the result will be equal to event outcome'
result == eventOutcome
where: 'the following values are used'
- scenario | isFullOutcomeResponse | eventType
- 'is full outcome' | true | SubscriptionEventOutcome.EventType.COMPLETE_OUTCOME
- 'is partial outcome' | false | SubscriptionEventOutcome.EventType.PARTIAL_OUTCOME
+ scenario | isFullOutcomeResponse || expectedEventType
+ 'is full outcome' | true || SubscriptionEventOutcome.EventType.COMPLETE_OUTCOME
+ 'is partial outcome' | false || SubscriptionEventOutcome.EventType.PARTIAL_OUTCOME
}
}
* ============LICENSE_END=========================================================
*/
-package org.onap.cps.ncmp.api.impl.event.avc
+package org.onap.cps.ncmp.api.impl.events.avcsubscription
import com.fasterxml.jackson.databind.ObjectMapper
import org.mapstruct.factory.Mappers
def 'Map subscription event response to subscription event outcome'() {
given: 'a Subscription Response Event'
- def jsonData = TestUtils.getResourceFileContent('avcSubscriptionEventResponse.json')
- def testEventToMap = jsonObjectMapper.convertJsonString(jsonData, SubscriptionEventResponse.class)
+ def subscriptionResponseJsonData = TestUtils.getResourceFileContent('avcSubscriptionEventResponse.json')
+ def subscriptionResponseEvent = jsonObjectMapper.convertJsonString(subscriptionResponseJsonData, SubscriptionEventResponse.class)
and: 'a Subscription Outcome Event'
def jsonDataOutcome = TestUtils.getResourceFileContent('avcSubscriptionOutcomeEvent.json')
- def testEventTarget = jsonObjectMapper.convertJsonString(jsonDataOutcome, SubscriptionEventOutcome.class)
+ def expectedEventOutcome = jsonObjectMapper.convertJsonString(jsonDataOutcome, SubscriptionEventOutcome.class)
+ expectedEventOutcome.setEventType(expectedEventType)
when: 'the subscription response event is mapped to a subscription event outcome'
- def result = objectUnderTest.toSubscriptionEventOutcome(testEventToMap)
- result.setEventType(SubscriptionEventOutcome.EventType.PARTIAL_OUTCOME)
+ def result = objectUnderTest.toSubscriptionEventOutcome(subscriptionResponseEvent)
+ result.setEventType(expectedEventType)
then: 'the resulting subscription event outcome contains the correct clientId'
- assert result == testEventTarget
+ assert result == expectedEventOutcome
+ where: 'the following values are used'
+ scenario || expectedEventType
+ 'is full outcome' || SubscriptionEventOutcome.EventType.COMPLETE_OUTCOME
+ 'is partial outcome' || SubscriptionEventOutcome.EventType.PARTIAL_OUTCOME
}
}
\ No newline at end of file