aboutsummaryrefslogtreecommitdiffstats
path: root/cps-rest/src
diff options
context:
space:
mode:
authorrajesh.kumar <rk00747546@techmahindra.com>2024-12-24 13:40:06 +0530
committerrajesh.kumar <rk00747546@techmahindra.com>2025-03-05 11:19:34 +0530
commita6e58e73589e12cd52992bdf6177971dc88dd4c5 (patch)
tree1f6b732ee0ac323c4ac08cb948a37d0f88ecb783 /cps-rest/src
parent4c645ef7d6e5a76a7d26991c247533cb75e64e22 (diff)
Add APIs to control notification subscription
- Add API for notification subscription - Add API for notification unsubscription - Add API for getting notification subscription information Issue-ID: CPS-2428 Change-Id: I56c34400dc73c71b936a51260efd241224dccdba Signed-off-by: rajesh.kumar <rk00747546@techmahindra.com>
Diffstat (limited to 'cps-rest/src')
-rwxr-xr-xcps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java28
-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
3 files changed, 93 insertions, 3 deletions
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
index 4c6bd6cdc5..01a9746af0 100755
--- a/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
+++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
@@ -3,7 +3,7 @@
* Copyright (C) 2020-2025 Nordix Foundation
* Modifications Copyright (C) 2020-2021 Bell Canada.
* Modifications Copyright (C) 2021 Pantheon.tech
- * 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.
@@ -31,11 +31,13 @@ import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
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.model.Anchor;
import org.onap.cps.api.model.Dataspace;
import org.onap.cps.api.model.SchemaSet;
@@ -43,6 +45,7 @@ import org.onap.cps.rest.api.CpsAdminApi;
import org.onap.cps.rest.model.AnchorDetails;
import org.onap.cps.rest.model.DataspaceDetails;
import org.onap.cps.rest.model.SchemaSetDetails;
+import org.onap.cps.utils.JsonObjectMapper;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -58,6 +61,8 @@ public class AdminRestController implements CpsAdminApi {
private final CpsModuleService cpsModuleService;
private final CpsRestInputMapper cpsRestInputMapper;
private final CpsAnchorService cpsAnchorService;
+ private final CpsNotificationService cpsNotificationService;
+ private final JsonObjectMapper jsonObjectMapper;
/**
* Create a dataspace.
@@ -280,4 +285,25 @@ public class AdminRestController implements CpsAdminApi {
final DataspaceDetails dataspaceDetails = cpsRestInputMapper.toDataspaceDetails(dataspace);
return new ResponseEntity<>(dataspaceDetails, HttpStatus.OK);
}
+
+ @Override
+ public ResponseEntity<Void> createNotificationSubscription(final String xpath,
+ final Object notificationSubscriptionAsJson) {
+ cpsNotificationService.createNotificationSubscription(
+ jsonObjectMapper.asJsonString(notificationSubscriptionAsJson), xpath);
+ return new ResponseEntity<>(HttpStatus.CREATED);
+ }
+
+ @Override
+ public ResponseEntity<Void> deleteNotificationSubscription(final String xpath) {
+ cpsNotificationService.deleteNotificationSubscription(xpath);
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+ }
+
+ @Override
+ public ResponseEntity<Object> getNotificationSubscription(final String xpath) {
+ final List<Map<String, Object>> dataMaps = cpsNotificationService.getNotificationSubscription(xpath);
+ return new ResponseEntity<>(jsonObjectMapper.asJsonString(dataMaps), HttpStatus.OK);
+ }
+
}
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