Retrieve an Anchor for a given dataspace by anchor name - REST layer 92/117292/2
authorRishi.Chail <rishi.chail@est.tech>
Fri, 22 Jan 2021 15:05:03 +0000 (15:05 +0000)
committerRishi.Chail <rishi.chail@est.tech>
Sat, 23 Jan 2021 06:22:29 +0000 (06:22 +0000)
Issue-ID: CPS-186

Signed-off-by: Rishi.Chail <rishi.chail@est.tech>
Change-Id: I2dceb582c6277e56400dfbc46340c70d814603ee

cps-rest/docs/api/swagger/cpsAdmin.yml [changed mode: 0644->0755]
cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java [changed mode: 0644->0755]
cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index d33c8e5..18ed1a2
@@ -146,7 +146,7 @@ anchorByDataspaceAndAnchorName:
   get:
     tags:
       - cps-admin
-    summary: Read an anchor given a anchor and a dataspace - DRAFT
+    summary: Read an anchor given a anchor and a dataspace
     operationId: getAnchor
     parameters:
       - $ref: 'components.yaml#/components/parameters/dataspaceNameInPath'
old mode 100644 (file)
new mode 100755 (executable)
index 1b6f56a..0f8e041
@@ -102,7 +102,8 @@ public class AdminRestController implements CpsAdminApi {
 
     @Override
     public ResponseEntity<Object> getAnchor(final String dataspaceName, final String anchorName) {
-        return null;
+        final Anchor anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
+        return new ResponseEntity<>(anchor, HttpStatus.OK);
     }
 
     @Override
old mode 100644 (file)
new mode 100755 (executable)
index 540d622..db0ab6d
 
 package org.onap.cps.rest.controller
 
+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
+
 import org.modelmapper.ModelMapper
 import org.onap.cps.api.CpsAdminService
 import org.onap.cps.api.CpsModuleService
@@ -40,12 +46,6 @@ import org.springframework.util.MultiValueMap
 import spock.lang.Specification
 import spock.lang.Unroll
 
-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
 class AdminRestControllerSpec extends Specification {
 
@@ -65,6 +65,7 @@ class AdminRestControllerSpec extends Specification {
     def basePath
 
     def anchorsEndpoint = '/v1/dataspaces/my_dataspace/anchors'
+    def anchorEndpoint = '/v1/dataspaces/my_dataspace/anchors/my_anchorname'
     def schemaSetsEndpoint = '/v1/dataspaces/test-dataspace/schema-sets'
     def schemaSetEndpoint = schemaSetsEndpoint + '/my_schema_set'
 
@@ -239,4 +240,17 @@ class AdminRestControllerSpec extends Specification {
             response.status == HttpStatus.OK.value()
             response.getContentAsString().contains('my_anchor')
     }
+
+    def 'Get existing anchor by dataspace and anchor name.'() {
+        given:
+            mockCpsAdminService.getAnchor('my_dataspace','my_anchorname') >> new Anchor(name: 'my_anchorname', dataspaceName: 'my_dataspace', schemaSetName: 'my_schemaSetName')
+        when: 'get anchor API is invoked'
+            def response = mvc.perform(get("$basePath$anchorEndpoint")).andReturn().response
+            def responseContent = response.getContentAsString()
+        then: 'the correct anchor is returned'
+            response.status == HttpStatus.OK.value()
+            responseContent.contains('my_anchorname')
+            responseContent.contains('my_dataspace')
+            responseContent.contains('my_schemaSetName')
+    }
 }