Delete anchor part 2: cps rest 10/120210/4
authorRuslan Kashapov <ruslan.kashapov@pantheon.tech>
Mon, 5 Apr 2021 11:46:03 +0000 (14:46 +0300)
committerRishi Chail <rishi.chail@est.tech>
Wed, 7 Apr 2021 13:11:46 +0000 (13:11 +0000)
Issue-ID: CPS-312
Change-Id: I08f92dfff3188bd96a69ec2ae01e0d0891b81d87
Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
cps-rest/docs/api/swagger/cpsAdmin.yml
cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy

index 5040e2c..cf26299 100755 (executable)
@@ -173,7 +173,7 @@ anchorByDataspaceAndAnchorName:
         $ref: 'components.yml#/components/responses/NotFound'
 
   delete:
-    description: Delete an anchor given an anchor name and a dataspace - DRAFT
+    description: Delete an anchor given an anchor name and a dataspace
     tags:
       - cps-admin
     summary: Delete an anchor
@@ -182,8 +182,6 @@ anchorByDataspaceAndAnchorName:
       - $ref: 'components.yml#/components/parameters/dataspaceNameInPath'
       - $ref: 'components.yml#/components/parameters/anchorNameInPath'
     responses:
-      '200':
-        $ref: 'components.yml#/components/responses/Ok'
       '204':
         $ref: 'components.yml#/components/responses/NoContent'
       '400':
index d74e9b1..ead365a 100755 (executable)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2020 Nordix Foundation
  *  Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ *  Modifications Copyright (C) 2021 Pantheon.tech
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -56,6 +57,11 @@ public class AdminRestController implements CpsAdminApi {
         return new ResponseEntity<>(dataspaceName, HttpStatus.CREATED);
     }
 
+    @Override
+    public ResponseEntity<Object> deleteDataspace(final String dataspaceName) {
+        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+    }
+
     @Override
     public ResponseEntity<String> createSchemaSet(final MultipartFile multipartFile,
         final String schemaSetName, final String dataspaceName) {
@@ -91,13 +97,9 @@ public class AdminRestController implements CpsAdminApi {
     }
 
     @Override
-    public ResponseEntity<Object> deleteAnchor(final String dataspaceName, final String anchorName) {
-        return null;
-    }
-
-    @Override
-    public ResponseEntity<Object> deleteDataspace(final String dataspaceName) {
-        return null;
+    public ResponseEntity<Void> deleteAnchor(final String dataspaceName, final String anchorName) {
+        cpsAdminService.deleteAnchor(dataspaceName, anchorName);
+        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
     }
 
     @Override
index 3387fb4..370ebaa 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2020 Pantheon.tech
+ *  Copyright (C) 2020-2021 Pantheon.tech
  *  Modifications Copyright (C) 2020, 2021 Bell Canada. All rights reserved.
  *  Copyright (C) 2021 Nordix Foundation
  *  ================================================================================
@@ -290,6 +290,18 @@ class AdminRestControllerSpec extends Specification {
             responseContent.contains(schemaSetName)
     }
 
+    def 'Delete anchor.'() {
+        given: 'an endpoint'
+            def anchorEndpoint = "$basePath/v1/dataspaces/$dataspaceName/anchors/$anchorName"
+        when: 'delete method is invoked on anchor endpoint'
+            def response = mvc.perform(delete(anchorEndpoint)).andReturn().response
+        then: 'associated service method is invoked with expected parameters'
+            1 * mockCpsAdminService.deleteAnchor(dataspaceName, anchorName)
+        and: 'response code indicates success'
+            response.status == HttpStatus.NO_CONTENT.value()
+    }
+
+
     def createMultipartFile(filename, content) {
         return new MockMultipartFile("file", filename, "text/plain", content.getBytes())
     }