diff options
author | Claudio David Gasparini <claudio.gasparini@pantheon.tech> | 2021-01-07 12:21:38 +0100 |
---|---|---|
committer | Claudio David Gasparini <claudio.gasparini@pantheon.tech> | 2021-01-11 10:01:27 +0100 |
commit | fa56d71bb94d88f657a9d73fb91c3036220f32ab (patch) | |
tree | 163bd68ae4a77cdc4412a5354958090e7063f257 /cps-rest | |
parent | 45b0d293c2d625c6d352d71a743f832c5e287c4e (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')
3 files changed, 68 insertions, 13 deletions
diff --git a/cps-rest/docs/api/swagger/openapi.yml b/cps-rest/docs/api/swagger/openapi.yml index d2c720e01c..2acd2b1641 100755 --- a/cps-rest/docs/api/swagger/openapi.yml +++ b/cps-rest/docs/api/swagger/openapi.yml @@ -67,6 +67,41 @@ paths: 403: description: Forbidden content: {} + /v1/dataspaces/{dataspace-name}/schema-sets/{schema-set-name}: + get: + tags: + - cps-admin + summary: Read a schema set given a schema set and a dataspace + operationId: getSchemaSet + parameters: + - name: dataspace-name + in: path + description: dataspace-name + required: true + schema: + type: string + - name: schema-set-name + in: path + description: schema-name + required: true + schema: + type: string + responses: + 200: + description: OK + content: + application/json: + schema: + type: object + 401: + description: Unauthorized + content: {} + 403: + description: Forbidden + content: {} + 404: + description: Not Found + content: {} /v1/dataspaces/{dataspace-name}/schema-sets: post: tags: 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') } } |