Merge "CPS-314: Delete Dataspace"
[cps.git] / cps-rest / src / test / groovy / org / onap / cps / rest / controller / AdminRestControllerSpec.groovy
index e158ebd..e8cfcfb 100755 (executable)
@@ -1,14 +1,15 @@
 /*
  *  ============LICENSE_START=======================================================
  *  Copyright (C) 2020-2021 Pantheon.tech
- *  Modifications Copyright (C) 2020, 2021 Bell Canada. All rights reserved.
- *  Copyright (C) 2021 Nordix Foundation
+ *  Modifications Copyright (C) 2020-2021 Bell Canada.
+ *  Modifications Copyright (C) 2021 Nordix Foundation
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
  *  You may obtain a copy of the License at
  *
  *        http://www.apache.org/licenses/LICENSE-2.0
+ *
  *  Unless required by applicable law or agreed to in writing, software
  *  distributed under the License is distributed on an "AS IS" BASIS,
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -48,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,13 +59,7 @@ class AdminRestControllerSpec extends Specification {
     CpsAdminService mockCpsAdminService = Mock()
 
     @SpringBean
-    CpsDataService mockCpsDataService = Mock()
-
-    @SpringBean
-    CpsQueryService mockCpsQueryService = Mock()
-
-    @SpringBean
-    ModelMapper modelMapper = Mock()
+    ModelMapper modelMapper = Spy()
 
     @Autowired
     MockMvc mvc
@@ -316,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())
@@ -338,4 +345,5 @@ class AdminRestControllerSpec extends Specification {
         multipartFile.getInputStream() >> { throw new IOException() }
         return multipartFile
     }
+
 }