CPS-314: Delete Dataspace
Issue-ID: CPS-314
Change-Id: I778e2b784c7b1ff3fecc1036425708dc4ec73227
Signed-off-by: niamhcore <niamh.core@est.tech>
diff --git a/cps-rest/docs/openapi/cpsAdmin.yml b/cps-rest/docs/openapi/cpsAdmin.yml
index a022ef1..869cb6e 100644
--- a/cps-rest/docs/openapi/cpsAdmin.yml
+++ b/cps-rest/docs/openapi/cpsAdmin.yml
@@ -35,6 +35,26 @@
'403':
$ref: 'components.yml#/components/responses/Forbidden'
+ delete:
+ description: Delete a dataspace
+ tags:
+ - cps-admin
+ summary: Delete a dataspace
+ operationId: deleteDataspace
+ parameters:
+ - $ref: 'components.yml#/components/parameters/dataspaceNameInQuery'
+ responses:
+ '204':
+ $ref: 'components.yml#/components/responses/NoContent'
+ '400':
+ $ref: 'components.yml#/components/responses/BadRequest'
+ '401':
+ $ref: 'components.yml#/components/responses/Unauthorized'
+ '403':
+ $ref: 'components.yml#/components/responses/Forbidden'
+ '409':
+ $ref: 'components.yml#/components/responses/Conflict'
+
schemaSet:
post:
description: Create a new schema set in the given dataspace
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 55fdbbe..52e64a9 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
@@ -71,6 +71,18 @@
}
/**
+ * Delete a dataspace.
+ *
+ * @param dataspaceName name of dataspace to be deleted
+ * @return a {@Link ResponseEntity} of {@link HttpStatus} NO_CONTENT
+ */
+ @Override
+ public ResponseEntity<Void> deleteDataspace(final String dataspaceName) {
+ cpsAdminService.deleteDataspace(dataspaceName);
+ return new ResponseEntity<>(HttpStatus.NO_CONTENT);
+ }
+
+ /**
* Create a {@link SchemaSet}.
*
* @param multipartFile multipart file
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 84da2db..e8cfcfb 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
@@ -311,6 +311,18 @@
response.status == HttpStatus.NO_CONTENT.value()
}
+ def 'Delete dataspace.'() {
+ given: 'an endpoint'
+ def dataspaceEndpoint = "$basePath/v1/dataspaces"
+ when: 'delete dataspace endpoint is invoked'
+ def response = mvc.perform(delete(dataspaceEndpoint)
+ .param('dataspace-name', dataspaceName))
+ .andReturn().response
+ then: 'associated service method is invoked with expected parameter'
+ 1 * mockCpsAdminService.deleteDataspace(dataspaceName)
+ and: 'response code indicates success'
+ response.status == HttpStatus.NO_CONTENT.value()
+ }
def createMultipartFile(filename, content) {
return new MockMultipartFile("file", filename, "text/plain", content.getBytes())
@@ -333,4 +345,5 @@
multipartFile.getInputStream() >> { throw new IOException() }
return multipartFile
}
+
}
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 079a59c..f596844 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
@@ -37,6 +37,7 @@
import org.onap.cps.spi.exceptions.ModelValidationException
import org.onap.cps.spi.exceptions.NotFoundInDataspaceException
import org.onap.cps.spi.exceptions.SchemaSetInUseException
+import org.onap.cps.spi.exceptions.DataspaceInUseException
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
@@ -145,7 +146,8 @@
assertTestResponse(response, CONFLICT, exceptionThrown.getMessage(), exceptionThrown.getDetails())
where: 'the following exceptions are thrown'
exceptionThrown << [new DataInUseException(dataspaceName, existingObjectName),
- new SchemaSetInUseException(dataspaceName, existingObjectName)]
+ new SchemaSetInUseException(dataspaceName, existingObjectName),
+ new DataspaceInUseException(dataspaceName, errorDetails)]
}
/*