+ def 'Get existing schema set.'() {
+ given: 'service method returns a new schema set'
+ mockCpsModuleService.getSchemaSet(dataspaceName, schemaSetName) >>
+ new SchemaSet(name: schemaSetName, dataspaceName: dataspaceName)
+ and: 'an endpoint'
+ def schemaSetEndpoint = "$basePath/v1/dataspaces/$dataspaceName/schema-sets/$schemaSetName"
+ 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(schemaSetName)
+ }
+
+ def 'Create Anchor.'() {
+ given: 'request parameters'
+ def requestParams = new LinkedMultiValueMap<>()
+ requestParams.add('schema-set-name', schemaSetName)
+ requestParams.add('anchor-name', anchorName)
+ and: 'an endpoint'
+ def anchorEndpoint = "$basePath/v1/dataspaces/$dataspaceName/anchors"
+ when: 'post is invoked'
+ def response =
+ mvc.perform(
+ post(anchorEndpoint).contentType(MediaType.APPLICATION_JSON)
+ .params(requestParams as MultiValueMap))
+ .andReturn().response
+ then: 'anchor is created successfully'
+ 1 * mockCpsAdminService.createAnchor(dataspaceName, schemaSetName, anchorName)
+ response.status == HttpStatus.CREATED.value()
+ response.getContentAsString().contains(anchorName)
+ }
+
+ def 'Get existing anchor.'() {
+ given: 'service method returns a list of anchors'
+ mockCpsAdminService.getAnchors(dataspaceName) >> [anchor]
+ and: 'an endpoint'
+ def anchorEndpoint = "$basePath/v1/dataspaces/$dataspaceName/anchors"
+ when: 'get all anchors API is invoked'
+ def response = mvc.perform(get(anchorEndpoint)).andReturn().response
+ then: 'the correct anchor is returned'
+ response.status == HttpStatus.OK.value()
+ response.getContentAsString().contains(anchorName)
+ }
+
+ def 'Get existing anchor by dataspace and anchor name.'() {
+ given: 'service method returns an anchor'
+ mockCpsAdminService.getAnchor(dataspaceName, anchorName) >>
+ new Anchor(name: anchorName, dataspaceName: dataspaceName, schemaSetName: schemaSetName)
+ and: 'an endpoint'
+ def anchorEndpoint = "$basePath/v1/dataspaces/$dataspaceName/anchors/$anchorName"
+ when: 'get anchor API is invoked'
+ def response = mvc.perform(get(anchorEndpoint)).andReturn().response
+ def responseContent = response.getContentAsString()
+ then: 'the correct anchor is returned'
+ response.status == HttpStatus.OK.value()
+ responseContent.contains(anchorName)
+ responseContent.contains(dataspaceName)
+ 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 'Delete dataspace.'() {
+ given: 'an endpoint'
+ def dataspaceEndpoint = "$basePath/v1/dataspaces"
+ when: 'delete dataspace endpoint is invoked'
+ def response = mvc.perform(delete(dataspaceEndpoint)
+ .param('dataspace-name', dataspaceName))
+ .andReturn().response
+ then: 'associated service method is invoked with expected parameter'
+ 1 * mockCpsAdminService.deleteDataspace(dataspaceName)
+ and: 'response code indicates success'
+ response.status == HttpStatus.NO_CONTENT.value()