Merge "CPS-314: Delete Dataspace"
[cps.git] / cps-rest / src / test / groovy / org / onap / cps / rest / controller / AdminRestControllerSpec.groovy
index 2f97a31..e8cfcfb 100755 (executable)
@@ -49,7 +49,7 @@ import org.springframework.util.LinkedMultiValueMap
 import org.springframework.util.MultiValueMap
 import spock.lang.Specification
 
-@WebMvcTest
+@WebMvcTest(AdminRestController)
 class AdminRestControllerSpec extends Specification {
 
     @SpringBean
@@ -58,12 +58,6 @@ class AdminRestControllerSpec extends Specification {
     @SpringBean
     CpsAdminService mockCpsAdminService = Mock()
 
-    @SpringBean
-    CpsDataService mockCpsDataService = Mock()
-
-    @SpringBean
-    CpsQueryService mockCpsQueryService = Mock()
-
     @SpringBean
     ModelMapper modelMapper = Spy()
 
@@ -317,6 +311,18 @@ class AdminRestControllerSpec extends Specification {
             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()
+    }
 
     def createMultipartFile(filename, content) {
         return new MockMultipartFile("file", filename, "text/plain", content.getBytes())
@@ -339,4 +345,5 @@ class AdminRestControllerSpec extends Specification {
         multipartFile.getInputStream() >> { throw new IOException() }
         return multipartFile
     }
+
 }