From ff7ba3a74265b62b116abb2fc34767f87444a655 Mon Sep 17 00:00:00 2001 From: ToineSiebelink Date: Wed, 28 Apr 2021 12:13:34 +0100 Subject: - Remove redundant and misleading tests - Some small improvemnt to tets ins same class Issue-ID: CPS-325 Change-Id: I0d888dbd9db555508b23e37957098b7b4d518912 Signed-off-by: ToineSiebelink --- .../rest/controller/DataRestControllerSpec.groovy | 40 ++++++---------------- 1 file changed, 11 insertions(+), 29 deletions(-) (limited to 'cps-rest') diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy index 299299ce2..b7337e02a 100755 --- a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy +++ b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/DataRestControllerSpec.groovy @@ -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' } } -- cgit 1.2.3-korg