diff options
author | halil.cakal <halil.cakal@est.tech> | 2023-06-06 16:20:55 +0100 |
---|---|---|
committer | halil.cakal <halil.cakal@est.tech> | 2023-06-07 12:21:17 +0100 |
commit | b3b44d9aa4e71c4264df140ffff27b5ba4c44e82 (patch) | |
tree | 75d3ae4ab36146f1f88aa2e54e0a0ae151a8f646 /cps-ncmp-service/src/test/groovy | |
parent | 195d3d7bbed40ff1ed6659e6864a5695356a400b (diff) |
Agreed outstanding comments including package refactoring
- Change package of AVC Subscription relevent codes into their place
- Change package of Subscription Event Cache config inot its place
- Add more branches for subscription outcome mapper
- Add more branches for subscription event response consumer
- Change unit test method params in order not to use deprecated methods
Issue-ID: CPS-1730
Change-Id: Ieda587d5be318db8360d52d49dc38d7ce3dd85cd
Signed-off-by: halil.cakal <halil.cakal@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/test/groovy')
5 files changed, 49 insertions, 23 deletions
diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/ForwardedSubscriptionEventCacheConfigSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/ForwardedSubscriptionEventCacheConfigSpec.groovy index 03d3a1c105..879525e572 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/ForwardedSubscriptionEventCacheConfigSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/embeddedcache/ForwardedSubscriptionEventCacheConfigSpec.groovy @@ -18,7 +18,7 @@ * ============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 diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventForwarderSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventForwarderSpec.groovy index 63ddcef554..a9eaaee916 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventForwarderSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventForwarderSpec.groovy @@ -137,14 +137,14 @@ class SubscriptionEventForwarderSpec extends MessagingBaseSpec { 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"] } @@ -154,6 +154,8 @@ class SubscriptionEventForwarderSpec extends MessagingBaseSpec { 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) { diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventResponseConsumerSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseConsumerSpec.groovy index 80c9b69c0b..26bb7e78ee 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionEventResponseConsumerSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseConsumerSpec.groovy @@ -18,13 +18,11 @@ * ============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 @@ -49,7 +47,7 @@ class SubscriptionEventResponseConsumerSpec extends MessagingBaseSpec { 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' @@ -62,7 +60,13 @@ class SubscriptionEventResponseConsumerSpec extends MessagingBaseSpec { 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'() { @@ -82,4 +86,21 @@ class SubscriptionEventResponseConsumerSpec extends MessagingBaseSpec { 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 + } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseOutcomeSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseOutcomeSpec.groovy index 53c5cd2c7b..3570a9e366 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseOutcomeSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseOutcomeSpec.groovy @@ -22,7 +22,6 @@ package org.onap.cps.ncmp.api.impl.events.avcsubscription 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 @@ -32,7 +31,6 @@ import org.onap.cps.utils.JsonObjectMapper 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 { @@ -56,14 +54,14 @@ 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 } @@ -74,7 +72,7 @@ class SubscriptionEventResponseOutcomeSpec extends DataNodeBaseSpec { 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) @@ -82,8 +80,8 @@ class SubscriptionEventResponseOutcomeSpec extends DataNodeBaseSpec { 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 } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionOutcomeMapperSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionOutcomeMapperSpec.groovy index 22067745f0..b05e983c03 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/event/avc/SubscriptionOutcomeMapperSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionOutcomeMapperSpec.groovy @@ -18,7 +18,7 @@ * ============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 @@ -41,15 +41,20 @@ class SubscriptionOutcomeMapperSpec extends Specification { 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 |