aboutsummaryrefslogtreecommitdiffstats
path: root/cps-rest/src
diff options
context:
space:
mode:
authorClaudio David Gasparini <claudio.gasparini@pantheon.tech>2021-01-07 12:21:38 +0100
committerClaudio David Gasparini <claudio.gasparini@pantheon.tech>2021-01-11 10:01:27 +0100
commitfa56d71bb94d88f657a9d73fb91c3036220f32ab (patch)
tree163bd68ae4a77cdc4412a5354958090e7063f257 /cps-rest/src
parent45b0d293c2d625c6d352d71a743f832c5e287c4e (diff)
Rework CpsModulePersistenceService
- remove getModuleReferences - provide service returning YangTextSchemaSourceSet Issue-ID: CPS-21 Signed-off-by: Claudio David Gasparini <claudio.gasparini@pantheon.tech> Change-Id: I61cf6450c8ed8a5154990ea19467e016dc1155b4
Diffstat (limited to 'cps-rest/src')
-rw-r--r--cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java7
-rw-r--r--cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy39
2 files changed, 33 insertions, 13 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 9549580bac..407a767389 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
@@ -28,6 +28,7 @@ import org.onap.cps.api.CpsAdminService;
import org.onap.cps.api.CpsModuleService;
import org.onap.cps.rest.api.CpsAdminApi;
import org.onap.cps.spi.model.Anchor;
+import org.onap.cps.spi.model.SchemaSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -59,6 +60,12 @@ public class AdminRestController implements CpsAdminApi {
return new ResponseEntity<>(schemaSetName, HttpStatus.CREATED);
}
+ @Override
+ public ResponseEntity<Object> getSchemaSet(final String dataspaceName, final String schemaSetName) {
+ final SchemaSet schemaSet = cpsModuleService.getSchemaSet(dataspaceName, schemaSetName);
+ return new ResponseEntity<>(schemaSet, HttpStatus.OK);
+ }
+
/**
* Create a new anchor.
*
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 9919649cb0..078253a64e 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
@@ -25,9 +25,9 @@ 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.model.SchemaSet
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
@@ -57,6 +57,8 @@ class AdminRestControllerSpec extends Specification {
MockMvc mvc
def anchorsEndpoint = '/v1/dataspaces/my_dataspace/anchors'
+ def schemaSetsEndpoint = '/v1/dataspaces/test-dataspace/schema-sets'
+ def schemaSetEndpoint = schemaSetsEndpoint + '/my_schema_set'
def anchor = new Anchor(name: 'my_anchor')
def anchorList = [anchor]
@@ -66,7 +68,7 @@ class AdminRestControllerSpec extends Specification {
def response = performCreateDataspaceRequest("new-dataspace")
then: 'Service method is invoked with expected parameters'
1 * mockCpsAdminService.createDataspace("new-dataspace")
- and:
+ and: 'Dataspace is create successfully'
response.status == HttpStatus.CREATED.value()
}
@@ -76,7 +78,7 @@ class AdminRestControllerSpec extends Specification {
mockCpsAdminService.createDataspace("existing-dataspace") >> { throw thrownException }
when:
def response = performCreateDataspaceRequest("existing-dataspace")
- then:
+ then: 'Dataspace creation fails'
response.status == HttpStatus.BAD_REQUEST.value()
}
@@ -99,7 +101,7 @@ class AdminRestControllerSpec extends Specification {
def multipartFile = createMultipartFile("filename.doc", "content")
when:
def response = performCreateSchemaSetRequest(multipartFile)
- then:
+ then: 'Create schema fails'
response.status == HttpStatus.BAD_REQUEST.value()
}
@@ -118,13 +120,24 @@ class AdminRestControllerSpec extends Specification {
def performCreateSchemaSetRequest(multipartFile) {
return mvc.perform(
MockMvcRequestBuilders
- .multipart('/v1/dataspaces/test-dataspace/schema-sets')
+ .multipart(schemaSetsEndpoint)
.file(multipartFile)
.param('schemaSetName', 'test-schema-set')
).andReturn().response
}
- def 'when createAnchor API is called, the response status is 201. '() {
+ def 'Get existing schema set'() {
+ given:
+ mockCpsModuleService.getSchemaSet('test-dataspace', 'my_schema_set') >>
+ new SchemaSet(name: 'my_schema_set', dataspaceName: 'test-dataspace')
+ when: 'get schema set API is invoked'
+ def response = mvc.perform(get(schemaSetEndpoint)).andReturn().response
+ then: 'the correct schema set is returned'
+ response.status == HttpStatus.OK.value()
+ response.getContentAsString().contains('my_schema_set')
+ }
+
+ def 'Create Anchor'() {
given:
def requestParams = new LinkedMultiValueMap<>()
requestParams.add('schema-set-name', 'my_schema-set')
@@ -132,19 +145,19 @@ class AdminRestControllerSpec extends Specification {
when: 'post is invoked'
def response = mvc.perform(post(anchorsEndpoint).contentType(MediaType.APPLICATION_JSON)
.params(requestParams as MultiValueMap)).andReturn().response
- then: 'Status is 201 and the response is the name of the created anchor -> my_anchor'
+ then: 'Anchor is created successfully'
1 * mockCpsAdminService.createAnchor('my_dataspace', 'my_schema-set', 'my_anchor')
- assert response.status == HttpStatus.CREATED.value()
- assert response.getContentAsString().contains('my_anchor')
+ response.status == HttpStatus.CREATED.value()
+ response.getContentAsString().contains('my_anchor')
}
- def 'when get all anchors for a dataspace API is called, the response status is 200 '() {
+ def 'Get existing anchor'() {
given:
mockCpsAdminService.getAnchors('my_dataspace') >> anchorList
when: 'get all anchors API is invoked'
def response = mvc.perform(get(anchorsEndpoint)).andReturn().response
- then: 'Status is 200 and the response is Collection of Anchors containing anchor name -> my_anchor'
- assert response.status == HttpStatus.OK.value()
- assert response.getContentAsString().contains('my_anchor')
+ then: 'the correct anchor is returned'
+ response.status == HttpStatus.OK.value()
+ response.getContentAsString().contains('my_anchor')
}
}