- def 'Get request with invalid authentication is not authorized'() {
- when: 'request is sent with invalid authentication'
- def response =
- mvc.perform(
- get("$basePath/v1/dataspaces/dataspace-name/anchors")
- .header("Authorization", 'Basic invalid auth'))
- .andReturn().response
- then: 'HTTP Unauthorized status code is returned'
- assert UNAUTHORIZED.value() == response.status
+ def 'Post request with #exceptionThrown.class.simpleName returns HTTP Status Bad Request.'() {
+ given: '#exception is thrown the service indicating data is not found'
+ mockCpsDataService.saveData(_, _, _, _, _) >> { throw exceptionThrown }
+ when: 'data update request is performed'
+ def response = mvc.perform(
+ post("$basePath/v1/dataspaces/dataspace-name/anchors/anchor-name/nodes")
+ .contentType(MediaType.APPLICATION_JSON)
+ .param('xpath', 'parent node xpath')
+ .content(groovy.json.JsonOutput.toJson('{"some-key" : "some-value"}'))
+ ).andReturn().response
+ then: 'response code indicates bad input parameters'
+ response.status == BAD_REQUEST.value()
+ where: 'the following exceptions are thrown'
+ exceptionThrown << [new DataNodeNotFoundException('', ''), new NotFoundInDataspaceException('', '')]