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
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()
def response =
mvc.perform(
post(endpoint)
- .header("Authorization", getAuthorizationHeader())
.contentType(MediaType.APPLICATION_JSON).content(json))
.andReturn().response
then: 'a created response is returned'
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()
def response =
mvc.perform(
get(endpoint)
- .header("Authorization", getAuthorizationHeader())
.param('xpath', xpath)
.param('include-descendants', includeDescendantsOption))
.andReturn().response
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
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'
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'