+ @Unroll
+ def 'Create schema set from #fileType file with IOException occurrence on processing.'() {
+ given: 'an endpoint'
+ def schemaSetEndpoint = "$basePath/v1/dataspaces/$dataspaceName/schema-sets"
+ when: 'file uploaded with schema set create request'
+ def multipartFile = createMultipartFileForIOException(fileType)
+ def response =
+ mvc.perform(
+ multipart(schemaSetEndpoint)
+ .file(multipartFile)
+ .param('schema-set-name', schemaSetName))
+ .andReturn().response
+ then: 'the error response returned indicating internal server error occurrence'
+ response.status == HttpStatus.INTERNAL_SERVER_ERROR.value()
+ where: 'following file types are used'
+ fileType << ['YANG', 'ZIP']
+ }
+
+ def 'Delete schema set.'() {
+ given: 'an endpoint'
+ def schemaSetEndpoint = "$basePath/v1/dataspaces/$dataspaceName/schema-sets/$schemaSetName"
+ when: 'delete schema set endpoint is invoked'
+ def response = mvc.perform(delete(schemaSetEndpoint)).andReturn().response
+ then: 'associated service method is invoked with expected parameters'
+ 1 * mockCpsModuleService.deleteSchemaSet(dataspaceName, schemaSetName, CASCADE_DELETE_PROHIBITED)
+ and: 'response code indicates success'
+ response.status == HttpStatus.NO_CONTENT.value()
+ }
+
+ def 'Delete schema set which is in use.'() {
+ given: 'service method throws an exception indicating the schema set is in use'
+ def thrownException = new SchemaSetInUseException(dataspaceName, schemaSetName)
+ mockCpsModuleService.deleteSchemaSet(dataspaceName, schemaSetName, CASCADE_DELETE_PROHIBITED) >>
+ { throw thrownException }
+ and: 'an endpoint'
+ def schemaSetEndpoint = "$basePath/v1/dataspaces/$dataspaceName/schema-sets/$schemaSetName"
+ when: 'delete schema set endpoint is invoked'
+ def response = mvc.perform(delete(schemaSetEndpoint)).andReturn().response
+ then: 'schema set deletion fails with conflict response code'
+ response.status == HttpStatus.CONFLICT.value()
+ }
+
+ 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) >> anchorList
+ 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)
+ }
+