Fix for AlreadyDefinedException test.
[cps.git] / cps-rest / src / test / groovy / org / onap / cps / rest / controller / DataRestControllerSpec.groovy
index ef834a7..ef43641 100755 (executable)
@@ -33,6 +33,7 @@ import org.onap.cps.api.CpsAdminService
 import org.onap.cps.api.CpsDataService
 import org.onap.cps.api.CpsModuleService
 import org.onap.cps.api.CpsQueryService
+import org.onap.cps.spi.exceptions.AlreadyDefinedException
 import org.onap.cps.spi.exceptions.AnchorNotFoundException
 import org.onap.cps.spi.exceptions.DataNodeNotFoundException
 import org.onap.cps.spi.exceptions.DataspaceNotFoundException
@@ -46,10 +47,11 @@ import org.springframework.http.HttpStatus
 import org.springframework.http.MediaType
 import org.springframework.test.web.servlet.MockMvc
 import spock.lang.Shared
+import spock.lang.Specification
 import spock.lang.Unroll
 
 @WebMvcTest
-class DataRestControllerSpec extends RestControllerSpecification {
+class DataRestControllerSpec extends Specification {
 
     @SpringBean
     CpsDataService mockCpsDataService = Mock()
@@ -96,7 +98,6 @@ class DataRestControllerSpec extends RestControllerSpecification {
             def response =
                     mvc.perform(
                             post(endpoint)
-                                    .header("Authorization", getAuthorizationHeader())
                                     .contentType(MediaType.APPLICATION_JSON).content(json))
                             .andReturn().response
         then: 'a created response is returned'
@@ -113,7 +114,7 @@ class DataRestControllerSpec extends RestControllerSpecification {
             mockCpsDataService.getDataNode(dataspaceName, anchorName, xpath, OMIT_DESCENDANTS) >> dataNodeWithLeavesNoChildren
         when: 'get request is performed through REST API'
             def response =
-                    mvc.perform(get(endpoint).header("Authorization", getAuthorizationHeader()).param('xpath', xpath))
+                    mvc.perform(get(endpoint).param('xpath', xpath))
                             .andReturn().response
         then: 'a success response is returned'
             response.status == HttpStatus.OK.value()
@@ -133,7 +134,6 @@ class DataRestControllerSpec extends RestControllerSpecification {
             def response =
                     mvc.perform(
                             get(endpoint)
-                                    .header("Authorization", getAuthorizationHeader())
                                     .param('xpath', xpath)
                                     .param('include-descendants', includeDescendantsOption))
                             .andReturn().response
@@ -155,16 +155,17 @@ class DataRestControllerSpec extends RestControllerSpecification {
             mockCpsDataService.getDataNode(dataspaceName, anchorName, xpath, _) >> { throw exception }
         when: 'get request is performed through REST API'
             def response =
-                    mvc.perform(get(endpoint).header("Authorization", getAuthorizationHeader()).param("xpath", xpath))
+                    mvc.perform(get(endpoint).param("xpath", xpath))
                             .andReturn().response
         then: 'a success response is returned'
             response.status == httpStatus.value()
         where:
-            scenario       | xpath     | exception                                 || httpStatus
-            'no dataspace' | '/x-path' | new DataspaceNotFoundException('')        || HttpStatus.BAD_REQUEST
-            'no anchor'    | '/x-path' | new AnchorNotFoundException('', '')       || HttpStatus.BAD_REQUEST
-            'no data'      | '/x-path' | new DataNodeNotFoundException('', '', '') || HttpStatus.NOT_FOUND
-            'empty path'   | ''        | new IllegalStateException()               || HttpStatus.NOT_IMPLEMENTED
+            scenario          | xpath     | exception                                        || httpStatus
+            'no dataspace'    | '/x-path' | new DataspaceNotFoundException('')               || HttpStatus.BAD_REQUEST
+            'no anchor'       | '/x-path' | new AnchorNotFoundException('', '')              || HttpStatus.BAD_REQUEST
+            'no data'         | '/x-path' | new DataNodeNotFoundException('', '', '')        || HttpStatus.NOT_FOUND
+            'empty path'      | ''        | new IllegalStateException()                      || HttpStatus.NOT_IMPLEMENTED
+            'already defined' | '/x-path' | new AlreadyDefinedException('', new Throwable()) || HttpStatus.CONFLICT
     }
 
     @Unroll
@@ -178,7 +179,6 @@ class DataRestControllerSpec extends RestControllerSpecification {
                             patch(endpoint)
                                     .contentType(MediaType.APPLICATION_JSON)
                                     .content(jsonData)
-                                    .header("Authorization", getAuthorizationHeader())
                                     .param('xpath', xpath)
                     ).andReturn().response
         then: 'the service method is invoked with expected parameters'
@@ -202,7 +202,6 @@ class DataRestControllerSpec extends RestControllerSpecification {
                             put(endpoint)
                                     .contentType(MediaType.APPLICATION_JSON)
                                     .content(jsonData)
-                                    .header("Authorization", getAuthorizationHeader())
                                     .param('xpath', xpath))
                             .andReturn().response
         then: 'the service method is invoked with expected parameters'