import org.onap.cps.ncmp.api.NetworkCmProxyDataService
import org.onap.cps.ncmp.api.impl.exception.DmiRequestException
import org.onap.cps.ncmp.api.impl.exception.ServerNcmpException
+import org.onap.cps.ncmp.rest.controller.RestInputMapper
import org.onap.cps.spi.exceptions.CpsException
+import org.onap.cps.spi.exceptions.DataNodeNotFoundException
import org.onap.cps.spi.exceptions.DataValidationException
import org.onap.cps.utils.JsonObjectMapper
import org.spockframework.spring.SpringBean
@SpringBean
JsonObjectMapper jsonObjectMapper = Stub()
+ @SpringBean
+ RestInputMapper restInputMapper = Mock()
+
@Value('${rest.api.ncmp-base-path}')
def basePathNcmp
def errorMessage = 'some error message'
@Shared
def errorDetails = 'some error details'
+ @Shared
+ def dataNodeNotFoundErrorMessage = 'DataNode not found'
def setup() {
dataNodeBaseEndpointNcmp = "$basePathNcmp/v1"
setupTestException(exception, NCMP)
def response = performTestRequest(NCMP)
then: 'an HTTP response is returned with correct message and details'
- assertTestResponse(response, expectedErrorCode, errorMessage, expectedErrorDetails)
+ assertTestResponse(response, expectedErrorCode, expectedErrorMessage, expectedErrorDetails)
where:
- scenario | exception || expectedErrorDetails | expectedErrorCode
- 'CPS' | new CpsException(errorMessage, errorDetails) || errorDetails | INTERNAL_SERVER_ERROR
- 'NCMP-server' | new ServerNcmpException(errorMessage, errorDetails) || null | INTERNAL_SERVER_ERROR
- 'NCMP-client' | new DmiRequestException(errorMessage, errorDetails) || null | BAD_REQUEST
- 'other' | new IllegalStateException(errorMessage) || null | INTERNAL_SERVER_ERROR
+ scenario | exception || expectedErrorDetails | expectedErrorMessage | expectedErrorCode
+ 'CPS' | new CpsException(errorMessage, errorDetails) || errorDetails | errorMessage | INTERNAL_SERVER_ERROR
+ 'NCMP-server' | new ServerNcmpException(errorMessage, errorDetails) || null | errorMessage | INTERNAL_SERVER_ERROR
+ 'NCMP-client' | new DmiRequestException(errorMessage, errorDetails) || null | errorMessage | BAD_REQUEST
+ 'DataNode Validation' | new DataNodeNotFoundException(dataNodeNotFoundErrorMessage, errorDetails) || null | dataNodeNotFoundErrorMessage | BAD_REQUEST
+ 'other' | new IllegalStateException(errorMessage) || null | errorMessage | INTERNAL_SERVER_ERROR
}
def 'Post request with exception returns correct HTTP Status.'() {
}
def setupTestException(exception, apiType) {
- if (NCMP.equals(apiType)) {
+ if (NCMP == apiType) {
mockNetworkCmProxyDataService.getYangResourcesModuleReferences(*_) >> { throw exception }
}
mockNetworkCmProxyDataService.updateDmiRegistrationAndSyncModule(*_) >> { throw exception }
}
def performTestRequest(apiType) {
- if (NCMP.equals(apiType)) {
+ if (NCMP == apiType) {
return mvc.perform(get("$dataNodeBaseEndpointNcmp/ch/testCmHandle/modules")).andReturn().response
}
- def jsonData = TestUtils.getResourceFileContent('dmi-registration.json')
+ def jsonData = TestUtils.getResourceFileContent('dmi_registration_all_singing_and_dancing.json')
return mvc.perform(post("$dataNodeBaseEndpointNcmpInventory/ch").contentType(MediaType.APPLICATION_JSON).content(jsonData)).andReturn().response
}