diff options
Diffstat (limited to 'cps-service')
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/events/CpsDataUpdateEventsService.java | 8 | ||||
-rw-r--r-- | cps-service/src/test/groovy/org/onap/cps/events/CpsDataUpdateEventsServiceSpec.groovy | 24 |
2 files changed, 24 insertions, 8 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/events/CpsDataUpdateEventsService.java b/cps-service/src/main/java/org/onap/cps/events/CpsDataUpdateEventsService.java index d38432dfa9..1097834880 100644 --- a/cps-service/src/main/java/org/onap/cps/events/CpsDataUpdateEventsService.java +++ b/cps-service/src/main/java/org/onap/cps/events/CpsDataUpdateEventsService.java @@ -46,6 +46,9 @@ public class CpsDataUpdateEventsService { @Value("${app.cps.data-updated.topic:cps-data-updated-events}") private String topicName; + @Value("${app.cps.data-updated.change-event-notifications-enabled:true}") + private boolean cpsChangeEventNotificationsEnabled; + @Value("${notification.enabled:false}") private boolean notificationsEnabled; @@ -60,7 +63,7 @@ public class CpsDataUpdateEventsService { @Timed(value = "cps.dataupdate.events.publish", description = "Time taken to publish Data Update event") public void publishCpsDataUpdateEvent(final Anchor anchor, final String xpath, final Operation operation, final OffsetDateTime observedTimestamp) { - if (notificationsEnabled) { + if (notificationsEnabled && cpsChangeEventNotificationsEnabled) { final CpsDataUpdatedEvent cpsDataUpdatedEvent = createCpsDataUpdatedEvent(anchor, observedTimestamp, xpath, operation); final String updateEventId = anchor.getDataspaceName() + ":" + anchor.getName(); @@ -70,7 +73,8 @@ public class CpsDataUpdateEventsService { .extensions(extensions).build().asCloudEvent(); eventsPublisher.publishCloudEvent(topicName, updateEventId, cpsDataUpdatedEventAsCloudEvent); } else { - log.debug("Notifications disabled."); + log.debug("State of Overall Notifications : {} and Cps Change Event Notifications : {}", + notificationsEnabled, cpsChangeEventNotificationsEnabled); } } 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) |