aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-rest
diff options
context:
space:
mode:
authorJosephKeenan <joseph.keenan@est.tech>2022-01-28 11:22:22 +0000
committerJosephKeenan <joseph.keenan@est.tech>2022-02-02 12:06:23 +0000
commite0873dde9816543a34818c1509b1aaa1c195a875 (patch)
tree3d4628a9482f1c0ab9413841d4d035bcf96f1a97 /cps-ncmp-rest
parent63132cec2c18363a8224646039cc23b6144d8e6c (diff)
[TECHDEBT] Align CPS NCMP REST API Specification
- Updated ncmp.yml to align implementation with specification - Added new Exception classes to differentiate between server NCMP issues and client based NCMP issues - Added 500 error to specification - To be merged after https://gerrit.onap.org/r/c/cps/+/126848 - Added excpetion handlers for SerNcmpException & DmiRequestException Issue-ID: CPS-823 Signed-off-by: JosephKeenan <joseph.keenan@est.tech> Change-Id: If1c9c6c29c6ea2daa07753d7f766ef15c1ba4ca0
Diffstat (limited to 'cps-ncmp-rest')
-rw-r--r--cps-ncmp-rest/docs/openapi/components.yaml10
-rwxr-xr-xcps-ncmp-rest/docs/openapi/ncmp-inventory.yml3
-rwxr-xr-xcps-ncmp-rest/docs/openapi/ncmp.yml29
-rwxr-xr-xcps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java11
-rw-r--r--cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy21
5 files changed, 50 insertions, 24 deletions
diff --git a/cps-ncmp-rest/docs/openapi/components.yaml b/cps-ncmp-rest/docs/openapi/components.yaml
index 021a79037d..22453f367b 100644
--- a/cps-ncmp-rest/docs/openapi/components.yaml
+++ b/cps-ncmp-rest/docs/openapi/components.yaml
@@ -382,3 +382,13 @@ components:
NoContent:
description: No Content
content: {}
+ InternalServerError:
+ description: Internal Server Error
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/ErrorMessage"
+ example:
+ status: 500
+ message: Internal Server Error
+ details: Internal Server Error occurred
diff --git a/cps-ncmp-rest/docs/openapi/ncmp-inventory.yml b/cps-ncmp-rest/docs/openapi/ncmp-inventory.yml
index b0a50aa83a..f3f84fed9a 100755
--- a/cps-ncmp-rest/docs/openapi/ncmp-inventory.yml
+++ b/cps-ncmp-rest/docs/openapi/ncmp-inventory.yml
@@ -1,5 +1,6 @@
# ============LICENSE_START=======================================================
# Copyright (C) 2021 Bell Canada
+# Modifications Copyright (C) 2021-2022 Nordix Foundation
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -38,3 +39,5 @@ updateDmiRegistration:
$ref: 'components.yaml#/components/responses/Unauthorized'
403:
$ref: 'components.yaml#/components/responses/Forbidden'
+ 500:
+ $ref: 'components.yaml#/components/responses/InternalServerError'
diff --git a/cps-ncmp-rest/docs/openapi/ncmp.yml b/cps-ncmp-rest/docs/openapi/ncmp.yml
index d80ec6508e..3a71aba804 100755
--- a/cps-ncmp-rest/docs/openapi/ncmp.yml
+++ b/cps-ncmp-rest/docs/openapi/ncmp.yml
@@ -45,8 +45,8 @@ getResourceDataForPassthroughOperational:
$ref: 'components.yaml#/components/responses/Unauthorized'
403:
$ref: 'components.yaml#/components/responses/Forbidden'
- 404:
- $ref: 'components.yaml#/components/responses/NotFound'
+ 500:
+ $ref: 'components.yaml#/components/responses/InternalServerError'
resourceDataForPassthroughRunning:
get:
@@ -76,8 +76,8 @@ resourceDataForPassthroughRunning:
$ref: 'components.yaml#/components/responses/Unauthorized'
403:
$ref: 'components.yaml#/components/responses/Forbidden'
- 404:
- $ref: 'components.yaml#/components/responses/NotFound'
+ 500:
+ $ref: 'components.yaml#/components/responses/InternalServerError'
post:
tags:
- network-cm-proxy
@@ -112,8 +112,8 @@ resourceDataForPassthroughRunning:
$ref: 'components.yaml#/components/responses/Unauthorized'
403:
$ref: 'components.yaml#/components/responses/Forbidden'
- 404:
- $ref: 'components.yaml#/components/responses/NotFound'
+ 500:
+ $ref: 'components.yaml#/components/responses/InternalServerError'
put:
tags:
@@ -149,8 +149,8 @@ resourceDataForPassthroughRunning:
$ref: 'components.yaml#/components/responses/Unauthorized'
403:
$ref: 'components.yaml#/components/responses/Forbidden'
- 404:
- $ref: 'components.yaml#/components/responses/NotFound'
+ 500:
+ $ref: 'components.yaml#/components/responses/InternalServerError'
patch:
tags:
@@ -180,8 +180,8 @@ resourceDataForPassthroughRunning:
$ref: 'components.yaml#/components/responses/Unauthorized'
403:
$ref: 'components.yaml#/components/responses/Forbidden'
- 404:
- $ref: 'components.yaml#/components/responses/NotFound'
+ 500:
+ $ref: 'components.yaml#/components/responses/InternalServerError'
delete:
tags:
@@ -204,7 +204,8 @@ resourceDataForPassthroughRunning:
$ref: 'components.yaml#/components/responses/Forbidden'
404:
$ref: 'components.yaml#/components/responses/NotFound'
-
+ 500:
+ $ref: 'components.yaml#/components/responses/InternalServerError'
fetchModuleReferencesByCmHandle:
get:
@@ -230,8 +231,8 @@ fetchModuleReferencesByCmHandle:
$ref: 'components.yaml#/components/responses/Unauthorized'
403:
$ref: 'components.yaml#/components/responses/Forbidden'
- 404:
- $ref: 'components.yaml#/components/responses/NotFound'
+ 500:
+ $ref: 'components.yaml#/components/responses/InternalServerError'
executeCmHandleSearch:
post:
@@ -259,3 +260,5 @@ executeCmHandleSearch:
$ref: 'components.yaml#/components/responses/Unauthorized'
403:
$ref: 'components.yaml#/components/responses/Forbidden'
+ 500:
+ $ref: 'components.yaml#/components/responses/InternalServerError'
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java
index ce9dd5a027..8c6f9f1d70 100755
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java
@@ -21,7 +21,9 @@
package org.onap.cps.ncmp.rest.exceptions;
import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.ncmp.api.impl.exception.DmiRequestException;
import org.onap.cps.ncmp.api.impl.exception.NcmpException;
+import org.onap.cps.ncmp.api.impl.exception.ServerNcmpException;
import org.onap.cps.ncmp.rest.controller.NetworkCmProxyController;
import org.onap.cps.ncmp.rest.model.ErrorMessage;
import org.onap.cps.spi.exceptions.CpsException;
@@ -56,11 +58,16 @@ public class NetworkCmProxyRestExceptionHandler {
return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception);
}
- @ExceptionHandler({NcmpException.class})
- public static ResponseEntity<Object> handleNcmpExceptions(final NcmpException exception) {
+ @ExceptionHandler({ServerNcmpException.class})
+ public static ResponseEntity<Object> handleServerNcmpExceptions(final ServerNcmpException exception) {
return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception);
}
+ @ExceptionHandler({DmiRequestException.class})
+ public static ResponseEntity<Object> handleDmiRequestExceptions(final DmiRequestException exception) {
+ return buildErrorResponse(HttpStatus.BAD_REQUEST, exception);
+ }
+
private static ResponseEntity<Object> buildErrorResponse(final HttpStatus status, final Exception exception) {
if (exception.getCause() != null || !(exception instanceof CpsException)) {
log.error("Exception occurred", exception);
diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy
index 7b3cd89145..1b72b8c084 100644
--- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy
+++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandlerSpec.groovy
@@ -23,7 +23,8 @@ package org.onap.cps.ncmp.rest.exceptions
import groovy.json.JsonSlurper
import org.modelmapper.ModelMapper
import org.onap.cps.ncmp.api.NetworkCmProxyDataService
-import org.onap.cps.ncmp.api.impl.exception.NcmpException
+import org.onap.cps.ncmp.api.impl.exception.DmiRequestException
+import org.onap.cps.ncmp.api.impl.exception.ServerNcmpException
import org.onap.cps.spi.exceptions.CpsException
import org.onap.cps.utils.JsonObjectMapper
import org.spockframework.spring.SpringBean
@@ -34,6 +35,7 @@ import org.springframework.test.web.servlet.MockMvc
import spock.lang.Shared
import spock.lang.Specification
+import static org.springframework.http.HttpStatus.BAD_REQUEST
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
@@ -66,17 +68,18 @@ class NetworkCmProxyRestExceptionHandlerSpec extends Specification {
dataNodeBaseEndpoint = "$basePath/v1"
}
- def 'Get request with generic #scenario exception returns HTTP Status Internal Server Error.'() {
- when: 'generic CPS exception is thrown by the service'
+ def 'Get request with generic #scenario exception returns correct HTTP Status.'() {
+ when: 'an exception is thrown by the service'
setupTestException(exception)
def response = performTestRequest()
- then: 'an HTTP Internal Server Error response is returned with correct message and details'
- assertTestResponse(response, INTERNAL_SERVER_ERROR, errorMessage, expectedErrorDetails)
+ then: 'an HTTP response is returned with correct message and details'
+ assertTestResponse(response, expectedErrorCode, errorMessage, expectedErrorDetails)
where:
- scenario | exception || expectedErrorDetails
- 'CPS' | new CpsException(errorMessage, errorDetails) || errorDetails
- 'NCMP' | new NcmpException(errorMessage, errorDetails) || null
- 'other' | new IllegalStateException(errorMessage) || null
+ 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
}
def setupTestException(exception){