X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-service%2Fsrc%2Ftest%2Fgroovy%2Forg%2Fonap%2Fcps%2Fevents%2FCpsDataUpdateEventsServiceSpec.groovy;fp=cps-service%2Fsrc%2Ftest%2Fgroovy%2Forg%2Fonap%2Fcps%2Fevents%2FCpsDataUpdateEventsServiceSpec.groovy;h=11842645c23eb908117df623da334b40c2a10252;hb=f7873bd1a65592539a26e49ba84cd3c90cdca252;hp=24b9ab5d71ecbba8fb8c063d0bada73da147c9cc;hpb=7b935fc1a85db39ffe216f6f53fed21de1bbb11a;p=cps.git diff --git a/cps-service/src/test/groovy/org/onap/cps/events/CpsDataUpdateEventsServiceSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/events/CpsDataUpdateEventsServiceSpec.groovy index 24b9ab5d71..11842645c2 100644 --- a/cps-service/src/test/groovy/org/onap/cps/events/CpsDataUpdateEventsServiceSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/events/CpsDataUpdateEventsServiceSpec.groovy @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2024 TechMahindra Ltd. + * Copyright (C) 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +30,6 @@ import io.cloudevents.CloudEvent import io.cloudevents.core.CloudEventUtils import io.cloudevents.jackson.PojoCloudEventDataMapper import org.onap.cps.events.model.CpsDataUpdatedEvent -import org.onap.cps.events.model.Data import org.onap.cps.spi.model.Anchor import org.onap.cps.utils.JsonObjectMapper import org.springframework.test.context.ContextConfiguration @@ -40,7 +40,6 @@ import java.time.OffsetDateTime @ContextConfiguration(classes = [ObjectMapper, JsonObjectMapper]) class CpsDataUpdateEventsServiceSpec extends Specification { def mockEventsPublisher = Mock(EventsPublisher) - def notificationsEnabled = true def objectMapper = new ObjectMapper(); def objectUnderTest = new CpsDataUpdateEventsService(mockEventsPublisher) @@ -52,6 +51,8 @@ class CpsDataUpdateEventsServiceSpec extends Specification { def observedTimestamp = OffsetDateTime.now() and: 'notificationsEnabled is #notificationsEnabled and it will be true as default' objectUnderTest.notificationsEnabled = true + and: 'cpsChangeEventNotificationsEnabled is also true' + objectUnderTest.cpsChangeEventNotificationsEnabled = true when: 'service is called to publish data update event' objectUnderTest.topicName = "cps-core-event" objectUnderTest.publishCpsDataUpdateEvent(anchor, xpath, operation, observedTimestamp) @@ -79,18 +80,27 @@ class CpsDataUpdateEventsServiceSpec extends Specification { 'non root node xpath and delete operation' | '/test/path' | DELETE || UPDATE } - def 'publish cps update event when notification service is disabled'() { + def 'publish cps update event when #scenario'() { given: 'an anchor, operation and observed timestamp' def anchor = new Anchor('anchor01', 'dataspace01', 'schema01'); def operation = CREATE def observedTimestamp = OffsetDateTime.now() - and: 'notificationsEnabled is false' - objectUnderTest.notificationsEnabled = false + and: 'notificationsEnabled is #notificationsEnabled' + objectUnderTest.notificationsEnabled = notificationsEnabled + and: 'cpsChangeEventNotificationsEnabled is #cpsChangeEventNotificationsEnabled' + objectUnderTest.cpsChangeEventNotificationsEnabled = cpsChangeEventNotificationsEnabled when: 'service is called to publish data update event' objectUnderTest.topicName = "cps-core-event" objectUnderTest.publishCpsDataUpdateEvent(anchor, '/', operation, observedTimestamp) then: 'the event contains the required attributes' - 0 * mockEventsPublisher.publishCloudEvent('cps-core-event', 'dataspace01:anchor01', _) + expectedCallToPublisher * mockEventsPublisher.publishCloudEvent('cps-core-event', 'dataspace01:anchor01', _) + where: 'below scenarios are present' + scenario | notificationsEnabled | cpsChangeEventNotificationsEnabled || expectedCallToPublisher + 'both notifications enabled' | true | true || 1 + 'both notifications disabled' | false | false || 0 + 'only CPS change event notification enabled' | false | true || 0 + 'only overall notification enabled' | true | false || 0 + } def 'publish cps update event when no timestamp provided'() { @@ -100,6 +110,8 @@ class CpsDataUpdateEventsServiceSpec extends Specification { def observedTimestamp = null and: 'notificationsEnabled is true' objectUnderTest.notificationsEnabled = true + and: 'cpsChangeEventNotificationsEnabled is true' + objectUnderTest.cpsChangeEventNotificationsEnabled = true when: 'service is called to publish data update event' objectUnderTest.topicName = "cps-core-event" objectUnderTest.publishCpsDataUpdateEvent(anchor, '/', operation, observedTimestamp)