diff options
3 files changed, 63 insertions, 6 deletions
diff --git a/appc-adapters/appc-rest-adapter/appc-rest-adapter-bundle/src/main/java/org/onap/appc/adapter/rest/impl/RestAdapterImpl.java b/appc-adapters/appc-rest-adapter/appc-rest-adapter-bundle/src/main/java/org/onap/appc/adapter/rest/impl/RestAdapterImpl.java index 7f9f84345..39fdb1b6c 100644 --- a/appc-adapters/appc-rest-adapter/appc-rest-adapter-bundle/src/main/java/org/onap/appc/adapter/rest/impl/RestAdapterImpl.java +++ b/appc-adapters/appc-rest-adapter/appc-rest-adapter-bundle/src/main/java/org/onap/appc/adapter/rest/impl/RestAdapterImpl.java @@ -6,6 +6,8 @@ * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= + * Modifications Copyright (C) 2018 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -156,8 +158,8 @@ public class RestAdapterImpl implements RestAdapter { svcLogic.setStatus(OUTCOME_FAILURE); svcLogic.setAttribute(Constants.ATTRIBUTE_ERROR_CODE, status); svcLogic.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, msg); - svcLogic.setAttribute("org.openecomp.rest.result.code", status); - svcLogic.setAttribute("org.openecomp.rest.result.message", msg); + svcLogic.setAttribute(Constants.CONTEXT_ERROR_CODE, status); + svcLogic.setAttribute(Constants.CONTEXT_ERROR_MESSAGE, msg); } @@ -170,9 +172,9 @@ public class RestAdapterImpl implements RestAdapter { svcLogic.setStatus(OUTCOME_SUCCESS); svcLogic.setAttribute(Constants.ATTRIBUTE_ERROR_CODE, Integer.toString(HttpStatus.OK_200.getStatusCode())); svcLogic.setAttribute(Constants.ATTRIBUTE_ERROR_MESSAGE, message); - svcLogic.setAttribute("org.openecomp.rest.agent.result.code", Integer.toString(code)); - svcLogic.setAttribute("org.openecomp.rest.agent.result.message", message); - svcLogic.setAttribute("org.openecomp.rest.result.code", Integer.toString(HttpStatus.OK_200.getStatusCode())); + svcLogic.setAttribute(Constants.CONTEXT_AGENT_ERROR_CODE, Integer.toString(code)); + svcLogic.setAttribute(Constants.CONTEXT_AGENT_ERROR_MESSAGE, message); + svcLogic.setAttribute(Constants.CONTEXT_ERROR_CODE, Integer.toString(HttpStatus.OK_200.getStatusCode())); } private void executeHttpRequest(HttpRequestBase httpRequest, RequestContext rc) { diff --git a/appc-adapters/appc-rest-adapter/appc-rest-adapter-bundle/src/test/java/org/onap/appc/adapter/rest/impl/TestRestAdapterImpl.java b/appc-adapters/appc-rest-adapter/appc-rest-adapter-bundle/src/test/java/org/onap/appc/adapter/rest/impl/TestRestAdapterImpl.java index ca5a89874..e0fdd7924 100644 --- a/appc-adapters/appc-rest-adapter/appc-rest-adapter-bundle/src/test/java/org/onap/appc/adapter/rest/impl/TestRestAdapterImpl.java +++ b/appc-adapters/appc-rest-adapter/appc-rest-adapter-bundle/src/test/java/org/onap/appc/adapter/rest/impl/TestRestAdapterImpl.java @@ -8,6 +8,8 @@ * ============================================================================= * Copyright (C) 2017 Intel Corp. * ============================================================================= + * Modifications Copyright (C) 2018 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -111,7 +113,40 @@ public class TestRestAdapterImpl { assertEquals("http://example.com:8081/puttest", httpPut.getURI().toURL().toString()); assertEquals("{\"name\":\"MyNode2\", \"width\":300, \"height\":300}", EntityUtils.toString(httpPut.getEntity())); } - + + @Test + public void testCreateRequestNoParamPut() throws IOException, IllegalStateException, IllegalArgumentException, + ZoneException, APPCException { + + SvcLogicContext ctx = new SvcLogicContext(); + Map<String, String> params = new HashMap<>(); + + adapter.commonPut(params, ctx); + + assertEquals("failure", ctx.getStatus()); + assertEquals("500", ctx.getAttribute("org.openecomp.rest.result.code")); + assertEquals("java.lang.IllegalArgumentException: HTTP request may not be null", + ctx.getAttribute("org.openecomp.rest.result.message")); + } + + @Test + public void testCreateRequestInvalidParamPut() throws IOException, IllegalStateException, IllegalArgumentException, + ZoneException, APPCException { + + SvcLogicContext ctx = new SvcLogicContext(); + Map<String, String> params = new HashMap<>(); + params.put("org.onap.appc.instance.URI", "boo"); + params.put("org.onap.appc.instance.haveHeader","false"); + params.put("org.onap.appc.instance.requestBody", "{\"name\":\"MyNode2\", \"width\":300, \"height\":300}"); + + adapter.commonPut(params, ctx); + + assertEquals("failure", ctx.getStatus()); + assertEquals("500", ctx.getAttribute("org.openecomp.rest.result.code")); + assertEquals("org.apache.http.client.ClientProtocolException", + ctx.getAttribute("org.openecomp.rest.result.message")); + } + @Test public void testCreateHttpRequestDelete() throws IOException, IllegalStateException, IllegalArgumentException, ZoneException, APPCException { diff --git a/appc-core/appc-common-bundle/src/main/java/org/onap/appc/Constants.java b/appc-core/appc-common-bundle/src/main/java/org/onap/appc/Constants.java index c1a306a8c..5fab6bb31 100644 --- a/appc-core/appc-common-bundle/src/main/java/org/onap/appc/Constants.java +++ b/appc-core/appc-common-bundle/src/main/java/org/onap/appc/Constants.java @@ -6,6 +6,8 @@ * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= + * Modifications Copyright (C) 2018 Samsung + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -52,6 +54,24 @@ public final class Constants { @SuppressWarnings("nls") public static final String ATTRIBUTE_ERROR_MESSAGE = "error-message"; + /** + * The name for the error message to be set in the context + */ + @SuppressWarnings("nls") + public static final String CONTEXT_ERROR_MESSAGE = "org.openecomp.rest.result.message"; + + @SuppressWarnings("nls") + public static final String CONTEXT_AGENT_ERROR_MESSAGE = "org.openecomp.rest.agent.result.message"; + + /** + * The name for the error code to be set in the context + */ + @SuppressWarnings("nls") + public static final String CONTEXT_ERROR_CODE = "org.openecomp.rest.result.code"; + + @SuppressWarnings("nls") + public static final String CONTEXT_AGENT_ERROR_CODE = "org.openecomp.rest.agent.result.code"; + /** * The name for the success message attribute to be set in the context */ |