[OpenAPI] Implemented example as per example wiki page for getting anchors based...
[cps.git] / cps-rest / src / test / groovy / org / onap / cps / rest / controller / AdminRestControllerSpec.groovy
index ab4cf7c..9ce7f73 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2020 Pantheon.tech
+ *  Copyright (C) 2020-2021 Pantheon.tech
  *  Modifications Copyright (C) 2020, 2021 Bell Canada. All rights reserved.
  *  Copyright (C) 2021 Nordix Foundation
  *  ================================================================================
@@ -47,7 +47,6 @@ import org.springframework.test.web.servlet.MockMvc
 import org.springframework.util.LinkedMultiValueMap
 import org.springframework.util.MultiValueMap
 import spock.lang.Specification
-import spock.lang.Unroll
 
 @WebMvcTest
 class AdminRestControllerSpec extends Specification {
@@ -65,7 +64,7 @@ class AdminRestControllerSpec extends Specification {
     CpsQueryService mockCpsQueryService = Mock()
 
     @SpringBean
-    ModelMapper modelMapper = Mock()
+    ModelMapper modelMapper = Spy()
 
     @Autowired
     MockMvc mvc
@@ -171,7 +170,6 @@ class AdminRestControllerSpec extends Specification {
             response.status == HttpStatus.CREATED.value()
     }
 
-    @Unroll
     def 'Create schema set from zip archive having #caseDescriptor.'() {
         given: 'an endpoint'
             def schemaSetEndpoint = "$basePath/v1/dataspaces/$dataspaceName/schema-sets"
@@ -206,7 +204,6 @@ class AdminRestControllerSpec extends Specification {
             response.status == HttpStatus.BAD_REQUEST.value()
     }
 
-    @Unroll
     def 'Create schema set from #fileType file with IOException occurrence on processing.'() {
         given: 'an endpoint'
             def schemaSetEndpoint = "$basePath/v1/dataspaces/$dataspaceName/schema-sets"
@@ -308,6 +305,18 @@ class AdminRestControllerSpec extends Specification {
             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 createMultipartFile(filename, content) {
         return new MockMultipartFile("file", filename, "text/plain", content.getBytes())
     }