summaryrefslogtreecommitdiffstats
path: root/cps-rest/src
diff options
context:
space:
mode:
authorToine Siebelink <toine.siebelink@est.tech>2021-02-01 15:50:32 +0000
committerGerrit Code Review <gerrit@onap.org>2021-02-01 15:50:32 +0000
commit3786f6394d8a973adba50bb5af3b459f0d296f93 (patch)
treef7ef147453029ed914f77958415da2cfa654c8c7 /cps-rest/src
parent30da8a9ea8f8f77ab5976097749caffbd16c4a93 (diff)
parent4be931a5d98df7b9adb88f70292d103f2c16080f (diff)
Merge "Retrieve an Anchor for a given dataspace by anchor name - REST layer"
Diffstat (limited to 'cps-rest/src')
-rwxr-xr-x[-rw-r--r--]cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java3
-rwxr-xr-x[-rw-r--r--]cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy26
2 files changed, 22 insertions, 7 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 1b6f56a211..0f8e041d0c 100644..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
@@ -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
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 c1c7c5dcdf..5f8147cd52 100644..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
@@ -20,6 +20,12 @@
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.CpsDataService
@@ -41,12 +47,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 {
@@ -69,6 +69,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'
@@ -243,4 +244,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')
+ }
}