aboutsummaryrefslogtreecommitdiffstats
path: root/cps-rest/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'cps-rest/src/test')
-rwxr-xr-xcps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy62
-rw-r--r--cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy6
2 files changed, 66 insertions, 2 deletions
diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy
index 0d189783fd..6d1ca40cd9 100755
--- a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy
+++ b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy
@@ -3,7 +3,7 @@
* Copyright (C) 2020-2021 Pantheon.tech
* Modifications Copyright (C) 2020-2021 Bell Canada.
* Modifications Copyright (C) 2021-2025 Nordix Foundation
- * Modifications Copyright (C) 2022 TechMahindra Ltd.
+ * Modifications Copyright (C) 2022-2025 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,15 +23,26 @@
package org.onap.cps.rest.controller
+import com.fasterxml.jackson.databind.ObjectMapper
+
+import static org.onap.cps.api.parameters.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put
+
import org.mapstruct.factory.Mappers
import org.onap.cps.api.CpsAnchorService
import org.onap.cps.api.CpsDataspaceService
import org.onap.cps.api.CpsModuleService
+import org.onap.cps.api.CpsNotificationService
import org.onap.cps.api.exceptions.AlreadyDefinedException
import org.onap.cps.api.exceptions.SchemaSetInUseException
import org.onap.cps.api.model.Anchor
import org.onap.cps.api.model.Dataspace
import org.onap.cps.api.model.SchemaSet
+import org.onap.cps.utils.JsonObjectMapper
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
@@ -63,8 +74,15 @@ class AdminRestControllerSpec extends Specification {
CpsAnchorService mockCpsAnchorService = Mock()
@SpringBean
+ CpsNotificationService mockCpsNotificationService = Mock()
+
+ @SpringBean
CpsRestInputMapper cpsRestInputMapper = Mappers.getMapper(CpsRestInputMapper)
+ @SpringBean
+ JsonObjectMapper jsonObjectMapper = new JsonObjectMapper(new ObjectMapper())
+
+
@Autowired
MockMvc mvc
@@ -393,6 +411,48 @@ class AdminRestControllerSpec extends Specification {
response.status == HttpStatus.NO_CONTENT.value()
}
+ def 'Add notification subscription'() {
+ given: 'an endpoint and its payload'
+ def notificationSubscriptionEndpoint = "$basePath/v2/notification-subscription"
+ def xpath = '/dataspaces'
+ def jsonPayload = '{"dataspace":[{"name":"ds01"}]}'
+ when: 'post request is performed'
+ def response =
+ mvc.perform(
+ post(notificationSubscriptionEndpoint)
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(jsonPayload))
+ .andReturn().response
+ then: 'notification service method is invoked with expected parameter'
+ 1 * mockCpsNotificationService.createNotificationSubscription(jsonPayload, xpath)
+ and: 'HTTP response code indicates success'
+ response.status == HttpStatus.CREATED.value()
+ }
+
+ def 'delete notification subscription'() {
+ given: 'an endpoint and xpath'
+ def notificationSubscriptionEndpoint = "$basePath/v2/notification-subscription"
+ def xpath = '/dataspaces'
+ when: 'delete request is performed'
+ def response = mvc.perform(delete(notificationSubscriptionEndpoint).param('xpath', xpath)).andReturn().response
+ then: 'notification service method is invoked with expected parameter'
+ 1 * mockCpsNotificationService.deleteNotificationSubscription(xpath)
+ and: 'HTTP response code indicates success'
+ response.status == HttpStatus.NO_CONTENT.value()
+ }
+
+ def 'Get notification subscription.'() {
+ given: 'an endpoint and xpath'
+ def notificationSubscriptionEndpoint = "$basePath/v2/notification-subscription"
+ def xpath = '/dataspaces'
+ when: 'get notification subscription is invoked'
+ def response = mvc.perform(get(notificationSubscriptionEndpoint).param('xpath', xpath)).andReturn().response
+ then: 'HTTP response code indicates success'
+ response.status == HttpStatus.OK.value()
+ and: 'notification service is called with proper parameters'
+ 1 * mockCpsNotificationService.getNotificationSubscription(xpath)
+ }
+
def createMultipartFile(filename, content) {
return new MockMultipartFile("file", filename, "text/plain", content.getBytes())
}
diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy
index f0fc4cca62..4e1d27cda2 100644
--- a/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy
+++ b/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy
@@ -3,7 +3,7 @@
* Copyright (C) 2020 Pantheon.tech
* Modifications Copyright (C) 2021-2023 Nordix Foundation
* Modifications Copyright (C) 2021 Bell Canada.
- * Modifications Copyright (C) 2022 TechMahindra Ltd.
+ * Modifications Copyright (C) 2022-2025 TechMahindra Ltd.
* Modifications Copyright (C) 2022 Deutsche Telekom AG
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,6 +30,7 @@ import org.onap.cps.api.CpsDataspaceService
import org.onap.cps.api.CpsAnchorService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
+import org.onap.cps.api.CpsNotificationService
import org.onap.cps.api.CpsQueryService
import org.onap.cps.rest.controller.CpsRestInputMapper
import org.onap.cps.api.exceptions.AlreadyDefinedException
@@ -87,6 +88,9 @@ class CpsRestExceptionHandlerSpec extends Specification {
@SpringBean
PrefixResolver prefixResolver = Mock()
+ @SpringBean
+ CpsNotificationService mockCpsNotificationService = Mock()
+
@Autowired
MockMvc mvc