From b24a4f2f4edf845c10ef42545496256b0bdbb8a8 Mon Sep 17 00:00:00 2001 From: "andre.schmid" Date: Tue, 11 Oct 2022 14:20:40 +0100 Subject: Fix response of fetch data type endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The catalog endpoint /v1/catalog/data-types/ is returning an Optional instead of the Data Type itself. Improves unit test to verify the response payload. Change-Id: I781917fb66225abf911a043370917e7b7a183bb1 Issue-ID: SDC-4211 Signed-off-by: André Schmid --- .../java/org/openecomp/sdc/be/servlets/DataTypeServlet.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'catalog-be/src/main/java') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java index 4456b8346e..d9846a7fb1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java @@ -84,9 +84,9 @@ public class DataTypeServlet extends BeGenericServlet { @PathParam("dataTypeUid") String dataTypeUid) { final String url = request.getMethod() + " " + request.getRequestURI(); log.debug("Start handle request of {} - modifier id is {}", url, userId); - final Optional dataTypeByUid; + final Optional dataTypeFoundOptional; try { - dataTypeByUid = dataTypeOperation.getDataTypeByUid(dataTypeUid); + dataTypeFoundOptional = dataTypeOperation.getDataTypeByUid(dataTypeUid); } catch (final BusinessException e) { throw e; } catch (final Exception ex) { @@ -95,10 +95,8 @@ public class DataTypeServlet extends BeGenericServlet { log.error(EcompLoggerErrorCode.UNKNOWN_ERROR, this.getClass().getName(), errorMsg, ex); return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR)); } - if (dataTypeByUid.isEmpty()) { - throw new OperationException(ActionStatus.DATA_TYPE_NOT_FOUND, dataTypeUid); - } - return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataTypeByUid); + var dataType = dataTypeFoundOptional.orElseThrow(() -> new OperationException(ActionStatus.DATA_TYPE_NOT_FOUND, dataTypeUid)); + return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), dataType); } } -- cgit 1.2.3-korg