diff options
Diffstat (limited to 'runtime-acm')
2 files changed, 32 insertions, 4 deletions
diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/web/RuntimeErrorController.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/web/RuntimeErrorController.java index a7faf049d..5761d6948 100755 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/web/RuntimeErrorController.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/web/RuntimeErrorController.java @@ -22,10 +22,11 @@ package org.onap.policy.clamp.acm.runtime.main.web; +import static org.springframework.boot.web.error.ErrorAttributeOptions.Include; + import io.swagger.v3.oas.annotations.Hidden; import jakarta.servlet.RequestDispatcher; import jakarta.servlet.http.HttpServletRequest; -import java.util.Map; import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse; import org.onap.policy.clamp.models.acm.messages.rest.TypedSimpleResponse; import org.slf4j.Logger; @@ -79,10 +80,14 @@ public class RuntimeErrorController implements ErrorController { @SuppressWarnings("squid:S3752") @RequestMapping(value = "${server.error.path}", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<TypedSimpleResponse<SimpleResponse>> handleError(HttpServletRequest request) { - Map<String, Object> map = this.errorAttributes.getErrorAttributes(new ServletWebRequest(request), - ErrorAttributeOptions.defaults()); + var map = this.errorAttributes.getErrorAttributes(new ServletWebRequest(request), + ErrorAttributeOptions.of(Include.MESSAGE, Include.EXCEPTION, Include.BINDING_ERRORS)); var sb = new StringBuilder(); + final var exception = map.get("exception"); + if (exception != null) { + sb.append(exception).append(" "); + } final var error = map.get("error"); if (error != null) { sb.append(error).append(" "); diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java index b2e151126..6c5417286 100755 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java @@ -47,6 +47,7 @@ import org.onap.policy.clamp.models.acm.messages.rest.commissioning.PrimeOrder; import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.springframework.beans.factory.annotation.Autowired; @@ -112,7 +113,29 @@ class CommissioningControllerTest extends CommonRestController { assertThat(Response.Status.BAD_REQUEST.getStatusCode()).isEqualTo(resp.getStatus()); var commissioningResponse = resp.readEntity(CommissioningResponse.class); - assertThat(commissioningResponse.getErrorDetails()).isNotNull(); + assertThat(commissioningResponse.getErrorDetails()) + .isEqualTo("org.springframework.http.converter.HttpMessageNotReadableException " + + "Bad Request Could not read JSON: java.lang.IllegalStateException: " + + "Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $"); + assertThat(commissioningResponse.getAffectedAutomationCompositionDefinitions()).isNull(); + } + + @Test + void testCreateBadVersion() { + var serviceTemplateCreate = new ToscaServiceTemplate(serviceTemplate); + var x = new ToscaNodeTemplate(serviceTemplateCreate + .getToscaTopologyTemplate().getNodeTemplates().values().iterator().next()); + x.setVersion("1.0.wrong"); + serviceTemplateCreate.getToscaTopologyTemplate().getNodeTemplates().put(x.getName(), x); + + var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT); + var resp = invocationBuilder.post(Entity.json(serviceTemplateCreate)); + + assertThat(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).isEqualTo(resp.getStatus()); + var commissioningResponse = resp.readEntity(CommissioningResponse.class); + assertThat(commissioningResponse.getErrorDetails()) + .isEqualTo("java.lang.IllegalArgumentException Internal Server Error parameter " + + "\"version\": value \"1.0.wrong\", does not match regular expression \"^(\\d+.){2}\\d+$\""); assertThat(commissioningResponse.getAffectedAutomationCompositionDefinitions()).isNull(); } |