- Remove redundant and misleading tests 66/120966/2
authorToineSiebelink <toine.siebelink@est.tech>
Wed, 28 Apr 2021 11:13:34 +0000 (12:13 +0100)
committerToineSiebelink <toine.siebelink@est.tech>
Wed, 28 Apr 2021 15:44:12 +0000 (16:44 +0100)
- Some small improvemnt to tets ins same class

Issue-ID: CPS-325

Change-Id: I0d888dbd9db555508b23e37957098b7b4d518912
Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy

index 299299c..b7337e0 100755 (executable)
@@ -174,27 +174,7 @@ class DataRestControllerSpec extends Specification {
             'no descendant explicitly'  | dataNodeWithLeavesNoChildren | 'false'                  || OMIT_DESCENDANTS             | false
             'with descendants'          | dataNodeWithChild            | 'true'                   || INCLUDE_ALL_DESCENDANTS      | true
     }
-
-    @Unroll
-    def 'Get data node error scenario: #scenario.'() {
-        given: 'the service throws an exception'
-            def endpoint = "$dataNodeBaseEndpoint/anchors/$anchorName/node"
-            mockCpsDataService.getDataNode(dataspaceName, anchorName, xpath, _) >> { throw exception }
-        when: 'get request is performed through REST API'
-            def response =
-                    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
-            'root path'       | '/'       | new DataNodeNotFoundException('', '')            || HttpStatus.NOT_FOUND
-            'already defined' | '/x-path' | new AlreadyDefinedException('', new Throwable()) || HttpStatus.CONFLICT
-    }
-
+    
     @Unroll
     def 'Update data node leaves: #scenario.'() {
         given: 'json data'
@@ -206,16 +186,17 @@ class DataRestControllerSpec extends Specification {
                             patch(endpoint)
                                     .contentType(MediaType.APPLICATION_JSON)
                                     .content(jsonData)
-                                    .param('xpath', xpath)
+                                    .param('xpath', inputXpath)
                     ).andReturn().response
         then: 'the service method is invoked with expected parameters'
             1 * mockCpsDataService.updateNodeLeaves(dataspaceName, anchorName, xpathServiceParameter, jsonData)
         and: 'response status indicates success'
             response.status == HttpStatus.OK.value()
         where:
-            scenario               | xpath    | xpathServiceParameter
-            'root node by default' | ''       | '/'
-            'node by parent xpath' | '/xpath' | '/xpath'
+            scenario               | inputXpath    || xpathServiceParameter
+            'root node by default' | ''            || '/'
+            'root node by choice'  | '/'           || '/'
+            'some xpath by parent' | '/some/xpath' || '/some/xpath'
     }
 
     @Unroll
@@ -229,15 +210,16 @@ class DataRestControllerSpec extends Specification {
                             put(endpoint)
                                     .contentType(MediaType.APPLICATION_JSON)
                                     .content(jsonData)
-                                    .param('xpath', xpath))
+                                    .param('xpath', inputXpath))
                             .andReturn().response
         then: 'the service method is invoked with expected parameters'
             1 * mockCpsDataService.replaceNodeTree(dataspaceName, anchorName, xpathServiceParameter, jsonData)
         and: 'response status indicates success'
             response.status == HttpStatus.OK.value()
         where:
-            scenario               | xpath    | xpathServiceParameter
-            'root node by default' | ''       | '/'
-            'node by parent xpath' | '/xpath' | '/xpath'
+            scenario               | inputXpath    || xpathServiceParameter
+            'root node by default' | ''            || '/'
+            'root node by choice'  | '/'           || '/'
+            'some xpath by parent' | '/some/xpath' || '/some/xpath'
     }
 }