aboutsummaryrefslogtreecommitdiffstats
path: root/cps-service/src/test/groovy/org/onap/cps/notification/NotificationServiceSpec.groovy
diff options
context:
space:
mode:
authorRenu Kumari <renu.kumari@bell.ca>2021-08-19 13:11:00 -0400
committerRenu Kumari <renu.kumari@bell.ca>2021-08-23 11:52:48 -0400
commit0c5979fe48a43d5fbc680d026ea7ec866f60ed9e (patch)
treed48e4f76cecfe7524e6cc4cc649c5e062b5b92e4 /cps-service/src/test/groovy/org/onap/cps/notification/NotificationServiceSpec.groovy
parentdb89e9c72388a7eb0a2132f7c25a213a925a0478 (diff)
Process data-updated event asynchronouslymr/526/123402/5
- notification is processed asynchronously using defined threadpool - updated docker-compose and readme to add dataspace filtering variables Issue-ID: CPS-526 Signed-off-by: Renu Kumari <renu.kumari@bell.ca> Change-Id: I7f827250f45cb9e3db2f060e9b3a089a4eaee05c
Diffstat (limited to 'cps-service/src/test/groovy/org/onap/cps/notification/NotificationServiceSpec.groovy')
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/notification/NotificationServiceSpec.groovy27
1 files changed, 17 insertions, 10 deletions
diff --git a/cps-service/src/test/groovy/org/onap/cps/notification/NotificationServiceSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/notification/NotificationServiceSpec.groovy
index b60d09323..104550ae8 100644
--- a/cps-service/src/test/groovy/org/onap/cps/notification/NotificationServiceSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/notification/NotificationServiceSpec.groovy
@@ -19,30 +19,35 @@
package org.onap.cps.notification
+import org.onap.cps.config.AsyncConfig
import org.onap.cps.event.model.CpsDataUpdatedEvent
import org.spockframework.spring.SpringBean
+import org.spockframework.spring.SpringSpy
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.test.context.SpringBootTest
+import org.springframework.scheduling.annotation.EnableAsync
import org.springframework.test.context.ContextConfiguration
import spock.lang.Shared
import spock.lang.Specification
@SpringBootTest
+@EnableAsync
@EnableConfigurationProperties
-@ContextConfiguration(classes = [NotificationProperties])
+@ContextConfiguration(classes = [NotificationProperties, NotificationService, NotificationErrorHandler, AsyncConfig])
class NotificationServiceSpec extends Specification {
@SpringBean
NotificationPublisher mockNotificationPublisher = Mock()
@SpringBean
- NotificationErrorHandler spyNotificationErrorHandler = Spy(new NotificationErrorHandler())
- @SpringBean
CpsDataUpdatedEventFactory mockCpsDataUpdatedEventFactory = Mock()
+ @SpringSpy
+ NotificationErrorHandler spyNotificationErrorHandler
+ @SpringSpy
+ NotificationProperties spyNotificationProperties
@Autowired
- NotificationProperties notificationProperties
- NotificationProperties spyNotificationProperties
+ NotificationService objectUnderTest
@Shared
def myDataspacePublishedName = 'my-dataspace-published'
@@ -50,7 +55,7 @@ class NotificationServiceSpec extends Specification {
def 'Skip sending notification when disabled.'() {
given: 'notification is disabled'
- def objectUnderTest = createNotificationService(false)
+ spyNotificationProperties.isEnabled() >> false
when: 'dataUpdatedEvent is received'
objectUnderTest.processDataUpdatedEvent(myDataspacePublishedName, myAnchorName)
then: 'the notification is not sent'
@@ -59,12 +64,13 @@ class NotificationServiceSpec extends Specification {
def 'Send notification when enabled: #scenario.'() {
given: 'notification is enabled'
- def objectUnderTest = createNotificationService(true)
+ spyNotificationProperties.isEnabled() >> true
and: 'event factory can create event successfully'
def cpsDataUpdatedEvent = new CpsDataUpdatedEvent()
mockCpsDataUpdatedEventFactory.createCpsDataUpdatedEvent(dataspaceName, myAnchorName) >> cpsDataUpdatedEvent
when: 'dataUpdatedEvent is received'
- objectUnderTest.processDataUpdatedEvent(dataspaceName, myAnchorName)
+ def future = objectUnderTest.processDataUpdatedEvent(dataspaceName, myAnchorName)
+ future.get()
then: 'notification is sent'
expectedSendNotificationCount * mockNotificationPublisher.sendNotification(cpsDataUpdatedEvent)
where:
@@ -75,12 +81,13 @@ class NotificationServiceSpec extends Specification {
def 'Error handling in notification service.'() {
given: 'notification is enabled'
- def objectUnderTest = createNotificationService(true)
+ spyNotificationProperties.isEnabled() >> true
and: 'event factory can not create event successfully'
mockCpsDataUpdatedEventFactory.createCpsDataUpdatedEvent(myDataspacePublishedName, myAnchorName) >>
{ throw new Exception("Could not create event") }
when: 'event is sent for processing'
- objectUnderTest.processDataUpdatedEvent(myDataspacePublishedName, myAnchorName)
+ def future = objectUnderTest.processDataUpdatedEvent(myDataspacePublishedName, myAnchorName)
+ future.get()
then: 'error is handled and not thrown to caller'
notThrown Exception
1 * spyNotificationErrorHandler.onException(_, _, _, _)