/*
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Pantheon.tech
- * Modifications Copyright (C) 2021-2022 Nordix Foundation
+ * Modifications Copyright (C) 2021-2023 Nordix Foundation
* Modifications Copyright (C) 2021 Bell Canada.
* Modifications Copyright (C) 2022 TechMahindra Ltd.
* Modifications Copyright (C) 2022 Deutsche Telekom AG
import com.fasterxml.jackson.databind.ObjectMapper
import groovy.json.JsonSlurper
-import org.onap.cps.api.CpsAdminService
+import org.onap.cps.api.CpsDataspaceService
+import org.onap.cps.api.CpsAnchorService
import org.onap.cps.api.CpsDataService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.api.CpsQueryService
class CpsRestExceptionHandlerSpec extends Specification {
@SpringBean
- CpsAdminService mockCpsAdminService = Stub()
+ CpsDataspaceService mockCpsAdminService = Stub()
+
+ @SpringBean
+ CpsAnchorService mockCpsAnchorService = Stub()
@SpringBean
CpsModuleService mockCpsModuleService = Stub()
"Anchor with name ${existingObjectName} already exists for ${dataspaceName}.")
}
+ def 'Request with a schema set in use exception returns HTTP Status Conflict.'() {
+ when: 'Schema set in use exception is thrown by the service'
+ setupTestException(new SchemaSetInUseException(dataspaceName, existingObjectName))
+ def response = performTestRequest()
+ then: 'a HTTP conflict response is returned with correct message an details'
+ assertTestResponse(response, CONFLICT,
+ "Schema Set is being used.",
+ "Schema Set with name ${existingObjectName} in dataspace ${dataspaceName} is having Anchor records associated.")
+ }
+
def 'Get request with a #exceptionThrown.class.simpleName returns HTTP Status Bad Request'() {
- when: 'CPS validation exception is thrown by the service'
+ when: '#exceptionThrown.class.simpleName is thrown by the service'
setupTestException(exceptionThrown)
def response = performTestRequest()
then: 'an HTTP Bad Request response is returned with correct message and details'
*/
def setupTestException(exception) {
- mockCpsAdminService.getAnchors(_) >> { throw exception }
+ mockCpsAnchorService.getAnchors(_) >> { throw exception }
}
def performTestRequest() {