summaryrefslogtreecommitdiffstats
path: root/cps-rest
diff options
context:
space:
mode:
authorRuslan Kashapov <ruslan.kashapov@pantheon.tech>2021-01-11 15:34:10 +0200
committerRuslan Kashapov <ruslan.kashapov@pantheon.tech>2021-01-19 14:08:37 +0200
commitdce4e316da66ede214977491c712b0a4ab457644 (patch)
tree992a172ed47557717468afff2628691b71f1eb5c /cps-rest
parent6f25d3a2ae84aff3f22b50d10592c5321a7c98ce (diff)
Delete schema set - REST and service layers
Issue-ID: CPS-121 Change-Id: I0fe885c79f98c994a8ac25a59b77b99eee4b3076 Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
Diffstat (limited to 'cps-rest')
-rw-r--r--cps-rest/docs/api/swagger/components.yaml6
-rw-r--r--cps-rest/docs/api/swagger/cpsAdmin.yml19
-rw-r--r--cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java7
-rw-r--r--cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java6
-rw-r--r--cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy38
-rw-r--r--cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy18
6 files changed, 87 insertions, 7 deletions
diff --git a/cps-rest/docs/api/swagger/components.yaml b/cps-rest/docs/api/swagger/components.yaml
index ab964a93a0..3b36b8b2fe 100644
--- a/cps-rest/docs/api/swagger/components.yaml
+++ b/cps-rest/docs/api/swagger/components.yaml
@@ -88,6 +88,12 @@ components:
application/json:
schema:
$ref: '#/components/schemas/ErrorMessage'
+ Conflict:
+ description: Conflict
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ErrorMessage'
Ok:
description: OK
content:
diff --git a/cps-rest/docs/api/swagger/cpsAdmin.yml b/cps-rest/docs/api/swagger/cpsAdmin.yml
index 948c43b763..d33c8e55ce 100644
--- a/cps-rest/docs/api/swagger/cpsAdmin.yml
+++ b/cps-rest/docs/api/swagger/cpsAdmin.yml
@@ -83,6 +83,25 @@ schemaSetBySchemaSetName:
$ref: 'components.yaml#/components/responses/Forbidden'
404:
$ref: 'components.yaml#/components/responses/NotFound'
+ delete:
+ tags:
+ - cps-admin
+ summary: Delete schema set given a schema set and a dataspace
+ operationId: deleteSchemaSet
+ parameters:
+ - $ref: 'components.yaml#/components/parameters/dataspaceNameInPath'
+ - $ref: 'components.yaml#/components/parameters/schemaSetNameInPath'
+ responses:
+ 204:
+ $ref: 'components.yaml#/components/responses/NoContent'
+ 400:
+ $ref: 'components.yaml#/components/responses/BadRequest'
+ 401:
+ $ref: 'components.yaml#/components/responses/Unauthorized'
+ 403:
+ $ref: 'components.yaml#/components/responses/Forbidden'
+ 409:
+ $ref: 'components.yaml#/components/responses/Conflict'
anchorsByDataspace:
get:
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 4237846ee7..08020eca2a 100644
--- 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
@@ -21,6 +21,7 @@
package org.onap.cps.rest.controller;
import static org.onap.cps.rest.utils.MultipartFileUtil.extractYangResourcesMap;
+import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED;
import java.util.Collection;
import org.modelmapper.ModelMapper;
@@ -66,6 +67,12 @@ public class AdminRestController implements CpsAdminApi {
return new ResponseEntity<>(schemaSet, HttpStatus.OK);
}
+ @Override
+ public ResponseEntity<Void> deleteSchemaSet(final String dataspaceName, final String schemaSetName) {
+ cpsModuleService.deleteSchemaSet(dataspaceName, schemaSetName, CASCADE_DELETE_PROHIBITED);
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+ }
+
/**
* Create a new anchor.
*
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java b/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java
index 2b096240bd..2f636630c4 100644
--- a/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java
+++ b/cps-rest/src/main/java/org/onap/cps/rest/exceptions/CpsRestExceptionHandler.java
@@ -26,6 +26,7 @@ import org.onap.cps.rest.controller.DataRestController;
import org.onap.cps.rest.model.ErrorMessage;
import org.onap.cps.spi.exceptions.CpsAdminException;
import org.onap.cps.spi.exceptions.CpsException;
+import org.onap.cps.spi.exceptions.DataInUseException;
import org.onap.cps.spi.exceptions.DataValidationException;
import org.onap.cps.spi.exceptions.ModelValidationException;
import org.onap.cps.spi.exceptions.NotFoundInDataspaceException;
@@ -62,6 +63,11 @@ public class CpsRestExceptionHandler {
return buildErrorResponse(HttpStatus.NOT_FOUND, exception.getMessage(), extractDetails(exception));
}
+ @ExceptionHandler({DataInUseException.class})
+ public static ResponseEntity<Object> handleDataInUseException(final CpsException exception) {
+ return buildErrorResponse(HttpStatus.CONFLICT, exception.getMessage(), extractDetails(exception));
+ }
+
@ExceptionHandler({CpsException.class})
public static ResponseEntity<Object> handleAnyOtherCpsExceptions(final CpsException exception) {
return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception.getMessage(), extractDetails(exception));
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 0a61c7dd59..a95d606a35 100644
--- 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
@@ -23,8 +23,9 @@ package org.onap.cps.rest.controller
import org.modelmapper.ModelMapper
import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsModuleService
-import org.onap.cps.spi.model.Anchor
import org.onap.cps.spi.exceptions.DataspaceAlreadyDefinedException
+import org.onap.cps.spi.exceptions.SchemaSetInUseException
+import org.onap.cps.spi.model.Anchor
import org.onap.cps.spi.model.SchemaSet
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
@@ -33,12 +34,14 @@ import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.mock.web.MockMultipartFile
import org.springframework.test.web.servlet.MockMvc
-import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
import org.springframework.util.LinkedMultiValueMap
import org.springframework.util.MultiValueMap
import spock.lang.Specification
+import static org.onap.cps.spi.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
@WebMvcTest
@@ -105,11 +108,29 @@ class AdminRestControllerSpec extends Specification {
response.status == HttpStatus.BAD_REQUEST.value()
}
+ def 'Delete schema set.'() {
+ when: 'delete schema set endpoint is invoked'
+ def response = performDeleteRequest(schemaSetEndpoint)
+ then: 'associated service method is invoked with expected parameters'
+ 1 * mockCpsModuleService.deleteSchemaSet('test-dataspace', 'my_schema_set', CASCADE_DELETE_PROHIBITED)
+ and: 'response code indicates success'
+ response.status == HttpStatus.NO_CONTENT.value()
+ }
+
+ def 'Delete schema set which is in use.'() {
+ given: 'the service method throws an exception indicating the schema set is in use'
+ def thrownException = new SchemaSetInUseException('test-dataspace', 'my_schema_set')
+ mockCpsModuleService.deleteSchemaSet('test-dataspace', 'my_schema_set', CASCADE_DELETE_PROHIBITED) >>
+ { throw thrownException }
+ when: 'delete schema set endpoint is invoked'
+ def response = performDeleteRequest(schemaSetEndpoint)
+ then: 'schema set deletion fails with conflict response code'
+ response.status == HttpStatus.CONFLICT.value()
+ }
+
def performCreateDataspaceRequest(String dataspaceName) {
return mvc.perform(
- MockMvcRequestBuilders
- .post('/v1/dataspaces')
- .param('dataspace-name', dataspaceName)
+ post('/v1/dataspaces').param('dataspace-name', dataspaceName)
).andReturn().response
}
@@ -119,13 +140,16 @@ class AdminRestControllerSpec extends Specification {
def performCreateSchemaSetRequest(multipartFile) {
return mvc.perform(
- MockMvcRequestBuilders
- .multipart(schemaSetsEndpoint)
+ multipart(schemaSetsEndpoint)
.file(multipartFile)
.param('schema-set-name', 'test-schema-set')
).andReturn().response
}
+ def performDeleteRequest(String uri) {
+ return mvc.perform(delete(uri)).andReturn().response
+ }
+
def 'Get existing schema set'() {
given:
mockCpsModuleService.getSchemaSet('test-dataspace', 'my_schema_set') >>
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 99ffbfd05a..d372d3c0b7 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
@@ -25,10 +25,12 @@ import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException
import org.onap.cps.spi.exceptions.CpsException
+import org.onap.cps.spi.exceptions.DataInUseException
import org.onap.cps.spi.exceptions.DataValidationException
import org.onap.cps.spi.exceptions.ModelValidationException
import org.onap.cps.spi.exceptions.NotFoundInDataspaceException
import org.onap.cps.spi.exceptions.SchemaSetAlreadyDefinedException
+import org.onap.cps.spi.exceptions.SchemaSetInUseException
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
@@ -38,6 +40,7 @@ import spock.lang.Specification
import spock.lang.Unroll
import static org.springframework.http.HttpStatus.BAD_REQUEST
+import static org.springframework.http.HttpStatus.CONFLICT
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR
import static org.springframework.http.HttpStatus.NOT_FOUND
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
@@ -133,6 +136,21 @@ class CpsRestExceptionHandlerSpec extends Specification {
new DataValidationException(errorMessage, errorDetails, null)]
}
+ @Unroll
+ def 'Delete request with a #exceptionThrown.class.simpleName returns HTTP Status Conflict'() {
+
+ when: 'CPS validation exception is thrown by the service'
+ setupTestException(exceptionThrown)
+ def response = performTestRequest()
+
+ then: 'an HTTP Conflict response is returned with correct message and details'
+ assertTestResponse(response, CONFLICT, exceptionThrown.getMessage(), exceptionThrown.getDetails())
+
+ where: 'the following exceptions are thrown'
+ exceptionThrown << [new DataInUseException(dataspaceName, existingObjectName),
+ new SchemaSetInUseException(dataspaceName, existingObjectName)]
+ }
+
/*
* NB. The test uses 'get JSON by id' endpoint and associated service method invocation
* to test the exception handling. The endpoint chosen is not a subject of test.